|
5 | 5 | import asyncio |
6 | 6 | import os |
7 | 7 | import sys |
| 8 | +import time |
8 | 9 | from pathlib import Path |
9 | 10 | from typing import Any, Literal |
10 | 11 |
|
11 | 12 | import mcp_v2 |
12 | 13 | from index_common import SBERT_MODEL |
| 14 | +from java_codebase_rag.cli_progress import ( |
| 15 | + accumulate_and_relay_subprocess_streams, |
| 16 | + emit_lance_cocoindex_finish, |
| 17 | + emit_lance_cocoindex_start, |
| 18 | +) |
13 | 19 | from java_codebase_rag.config import emit_legacy_env_hints_if_present, resolved_sbert_model_for_process_env |
14 | 20 | from kuzu_queries import KuzuGraph, resolve_kuzu_path |
15 | 21 | from mcp.server.fastmcp import FastMCP |
@@ -213,25 +219,55 @@ async def run_refresh_pipeline(*, quiet: bool = False) -> RefreshIndexOutput: |
213 | 219 | message=f"java_index_flow_lancedb.py not found under {root} nor {bundle_dir}", |
214 | 220 | phases_run=[], |
215 | 221 | ) |
216 | | - try: |
217 | | - proc = await asyncio.create_subprocess_exec( |
218 | | - str(cocoindex_bin), |
219 | | - "update", |
220 | | - _COCOINDEX_TARGET, |
221 | | - "--full-reprocess", |
222 | | - "-f", |
223 | | - cwd=str(flow_path.parent), |
224 | | - env=_cocoindex_subprocess_env(root), |
225 | | - stdout=asyncio.subprocess.PIPE, |
226 | | - stderr=asyncio.subprocess.PIPE, |
227 | | - ) |
228 | | - out_b, err_b = await proc.communicate() |
229 | | - except Exception as exc: |
230 | | - return RefreshIndexOutput( |
231 | | - success=False, |
232 | | - message=f"spawn failed: {exc!s}", |
233 | | - phases_run=[], |
234 | | - ) |
| 222 | + proc: asyncio.subprocess.Process | None = None |
| 223 | + out_b, err_b = b"", b"" |
| 224 | + if quiet: |
| 225 | + try: |
| 226 | + proc = await asyncio.create_subprocess_exec( |
| 227 | + str(cocoindex_bin), |
| 228 | + "update", |
| 229 | + _COCOINDEX_TARGET, |
| 230 | + "--full-reprocess", |
| 231 | + "-f", |
| 232 | + cwd=str(flow_path.parent), |
| 233 | + env=_cocoindex_subprocess_env(root), |
| 234 | + stdout=asyncio.subprocess.PIPE, |
| 235 | + stderr=asyncio.subprocess.PIPE, |
| 236 | + ) |
| 237 | + out_b, err_b = await proc.communicate() |
| 238 | + except Exception as exc: |
| 239 | + return RefreshIndexOutput( |
| 240 | + success=False, |
| 241 | + message=f"spawn failed: {exc!s}", |
| 242 | + phases_run=[], |
| 243 | + ) |
| 244 | + else: |
| 245 | + emit_lance_cocoindex_start(root) |
| 246 | + t0 = time.perf_counter() |
| 247 | + code_c = -1 |
| 248 | + try: |
| 249 | + proc = await asyncio.create_subprocess_exec( |
| 250 | + str(cocoindex_bin), |
| 251 | + "update", |
| 252 | + _COCOINDEX_TARGET, |
| 253 | + "--full-reprocess", |
| 254 | + "-f", |
| 255 | + cwd=str(flow_path.parent), |
| 256 | + env=_cocoindex_subprocess_env(root), |
| 257 | + stdout=asyncio.subprocess.PIPE, |
| 258 | + stderr=asyncio.subprocess.PIPE, |
| 259 | + ) |
| 260 | + out_b, err_b = await accumulate_and_relay_subprocess_streams(proc, relay=True) |
| 261 | + code_c = proc.returncode if proc.returncode is not None else -1 |
| 262 | + except Exception as exc: |
| 263 | + return RefreshIndexOutput( |
| 264 | + success=False, |
| 265 | + message=f"spawn failed: {exc!s}", |
| 266 | + phases_run=[], |
| 267 | + ) |
| 268 | + finally: |
| 269 | + emit_lance_cocoindex_finish(elapsed_s=time.perf_counter() - t0, exit_code=code_c) |
| 270 | + assert proc is not None |
235 | 271 | out = out_b.decode(errors="replace") |
236 | 272 | err = err_b.decode(errors="replace") |
237 | 273 | ok = proc.returncode == 0 |
@@ -261,7 +297,10 @@ async def run_refresh_pipeline(*, quiet: bool = False) -> RefreshIndexOutput: |
261 | 297 | stderr=asyncio.subprocess.PIPE, |
262 | 298 | ) |
263 | 299 | phases_run = ["vectors", "graph"] |
264 | | - gout_b, gerr_b = await gproc.communicate() |
| 300 | + if quiet: |
| 301 | + gout_b, gerr_b = await gproc.communicate() |
| 302 | + else: |
| 303 | + gout_b, gerr_b = await accumulate_and_relay_subprocess_streams(gproc, relay=True) |
265 | 304 | graph_code = gproc.returncode |
266 | 305 | graph_out = gout_b.decode(errors="replace") |
267 | 306 | graph_err = gerr_b.decode(errors="replace") |
|
0 commit comments