Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

Show parse IDs for async parse tracking

jinzhenjd65cfa7578cb
diff --git a/mineru/cli/commands/parse.py b/mineru/cli/commands/parse.py
index 1b51e1f1..903256dc 100644
--- a/mineru/cli/commands/parse.py
+++ b/mineru/cli/commands/parse.py
@@ -199,7 +199,7 @@ def _parse(
if json_mode:
_emit_parse_json_response(result, None)
else:
- emit_result(CliContext(json_mode=False), _prepare_parse_summary_output(result))
+ emit_result(CliContext(json_mode=False), _prepare_parse_summary_output(result, exit_code=0))
return
# poll until done or timeout
@@ -271,10 +271,14 @@ def _parse(
parse_overrides={"status": latest_wait_status, "tip": "Re-run the same command to continue waiting."},
)
else:
- _emit_notice(
- f"Parse still in progress (tier={req_tier}). Check status with: mineru show file {file_path}", json_mode=json_mode
+ emit_result(
+ CliContext(json_mode=False),
+ _prepare_parse_summary_output(
+ result.model_copy(update={"status": latest_wait_status}),
+ waited_seconds=wait,
+ exit_code=1,
+ ),
)
- emit_result(CliContext(json_mode=False), cli_ok(exit_code=1))
def _record_parse_wait(client: DoclibClient, parse_ids: list[int], status: str, started_at: float) -> None:
@@ -424,14 +428,40 @@ def _parse_json_payload(
return payload
-def _prepare_parse_summary_output(parse_result: ParseResponse) -> CliResult[ParseSummaryOutput] | CliResult[None]:
+def _prepare_parse_summary_output(
+ parse_result: ParseResponse,
+ *,
+ waited_seconds: int | None = None,
+ exit_code: int = 0,
+) -> CliResult[ParseSummaryOutput] | CliResult[None]:
status = parse_result.status
tip = parse_result.tip or ""
- if status == "pending":
- return cli_ok(ParseSummaryOutput(f"Parse {status}... {tip}"), render=_render_parse_summary)
+ if status in ("pending", "parsing"):
+ return cli_ok(
+ ParseSummaryOutput(_format_parse_in_progress(parse_result, waited_seconds=waited_seconds, tip=tip)),
+ render=_render_parse_summary,
+ exit_code=exit_code,
+ )
return cli_ok(ParseSummaryOutput(f"Parse complete (tier={parse_result.tier}) {tip}"), render=_render_parse_summary)
+def _format_parse_in_progress(parse_result: ParseResponse, *, waited_seconds: int | None, tip: str = "") -> str:
+ elapsed = f" after {waited_seconds}s" if waited_seconds is not None else ""
+ lines = [f"Parse still in progress{elapsed} (tier={parse_result.tier})."]
+ parse_ids = parse_result.wait_parse_ids
+ if parse_ids:
+ label = "Parse ID" if len(parse_ids) == 1 else "Parse IDs"
+ lines.append(f"{label}: {', '.join(str(parse_id) for parse_id in parse_ids)}")
+ if len(parse_ids) == 1:
+ lines.append(f"Check status: mineru show parse {parse_ids[0]}")
+ else:
+ lines.append("Check status:")
+ lines.extend(f" mineru show parse {parse_id}" for parse_id in parse_ids)
+ if tip:
+ lines.append(tip)
+ return "\n".join(lines)
+
+
def _render_parse_summary(data: ParseSummaryOutput) -> str:
return data.text
diff --git a/tests/unittest/test_cli_next_command_design.py b/tests/unittest/test_cli_next_command_design.py
index 32c5842e..8061afd1 100644
--- a/tests/unittest/test_cli_next_command_design.py
+++ b/tests/unittest/test_cli_next_command_design.py
@@ -1159,6 +1159,69 @@ def test_parse_json_no_wait_wraps_parse_and_null_content(monkeypatch: Any, tmp_p
assert payload["content"] is None
+def test_parse_no_wait_text_prints_parse_id_tracking_hint(monkeypatch: Any, tmp_path: Path) -> None:
+ source = tmp_path / "demo.pdf"
+ source.write_bytes(b"%PDF-1.7\n")
+
+ class _Client:
+ def __init__(self, *, timeout: int) -> None:
+ assert timeout == 90
+
+ def ensure_parse(self, request: Any) -> ParseResponse:
+ return ParseResponse(
+ sha256="a" * 64,
+ tier="high",
+ page_range="1~1",
+ status="pending",
+ wait_parse_ids=[4686],
+ created_parse_ids=[4686],
+ )
+
+ monkeypatch.setattr(parse, "DoclibClient", _Client)
+
+ result = runner.invoke(app, ["parse", str(source), "--tier", "high", "--remote", "--no-wait"])
+
+ assert result.exit_code == 0
+ assert result.output == (
+ "Parse still in progress (tier=high).\n"
+ "Parse ID: 4686\n"
+ "Check status: mineru show parse 4686\n"
+ )
+
+
+def test_parse_no_wait_text_prints_multiple_parse_id_tracking_hints(monkeypatch: Any, tmp_path: Path) -> None:
+ source = tmp_path / "demo.pdf"
+ source.write_bytes(b"%PDF-1.7\n")
+
+ class _Client:
+ def __init__(self, *, timeout: int) -> None:
+ assert timeout == 90
+
+ def ensure_parse(self, request: Any) -> ParseResponse:
+ return ParseResponse(
+ sha256="a" * 64,
+ tier="high",
+ page_range="1~2",
+ status="pending",
+ wait_parse_ids=[4686, 4687],
+ created_parse_ids=[4687],
+ reused_parse_ids=[4686],
+ )
+
+ monkeypatch.setattr(parse, "DoclibClient", _Client)
+
+ result = runner.invoke(app, ["parse", str(source), "--tier", "high", "--remote", "--no-wait"])
+
+ assert result.exit_code == 0
+ assert result.output == (
+ "Parse still in progress (tier=high).\n"
+ "Parse IDs: 4686, 4687\n"
+ "Check status:\n"
+ " mineru show parse 4686\n"
+ " mineru show parse 4687\n"
+ )
+
+
def test_parse_expands_user_home_in_input_path(monkeypatch: Any, tmp_path: Path) -> None:
home = tmp_path / "home"
source = home / "mineru-e2e-test" / "sample.pdf"
@@ -1400,7 +1463,11 @@ def test_parse_wait_timeout_text_returns_nonzero_exit(monkeypatch: Any, tmp_path
result = runner.invoke(app, ["parse", str(source), "--tier", "flash", "--wait", "1"])
assert result.exit_code == 1
- assert "Parse still in progress" in result.output
+ assert result.output == (
+ "Parse still in progress after 1s (tier=flash).\n"
+ "Parse ID: 3\n"
+ "Check status: mineru show parse 3\n"
+ )
def test_parse_wait_timeout_json_uses_latest_parsing_status(monkeypatch: Any, tmp_path: Path) -> None: