MCPcopy
hub / github.com/MinishLab/semble / _run_find_related

Function _run_find_related

src/semble/cli.py:117–134  ·  view source on GitHub ↗

Handle the `find-related` subcommand.

(
    path: str, file_path: str, line: int, top_k: int, content: list[ContentType], max_snippet_lines: int | None
)

Source from the content-addressed store, hash-verified

115
116
117def _run_find_related(
118 path: str, file_path: str, line: int, top_k: int, content: list[ContentType], max_snippet_lines: int | None
119) -> None:
120 """Handle the `find-related` subcommand."""
121 index = _load_index(path, content)
122 chunk = resolve_chunk(index.chunks, file_path, line)
123 if chunk is None:
124 print(f"No chunk found at {file_path}:{line}.", file=sys.stderr)
125 sys.exit(1)
126 results = index.find_related(chunk, top_k=top_k, max_snippet_lines=max_snippet_lines)
127 label = f"Chunks related to {file_path}:{line}"
128 out = (
129 format_results(label, results, max_snippet_lines)
130 if results
131 else {"error": f"No related chunks found for {file_path}:{line}."}
132 )
133 print(json.dumps(out))
134 _maybe_save_index(index, path)
135
136
137def _run_clear(clear_type: _CLEAR_CHOICE) -> None:

Callers 1

_cli_mainFunction · 0.85

Calls 5

resolve_chunkFunction · 0.90
format_resultsFunction · 0.90
_load_indexFunction · 0.85
_maybe_save_indexFunction · 0.85
find_relatedMethod · 0.80

Tested by

no test coverage detected