"""Full-document table extraction with ONLY the side-by-side bullet added to the locator prompt. Scratch harness; production untouched."""
import json, sys, time
from pathlib import Path
from quber.agents import grid_locator as gl
S=Path('/tmp/claude-1000/-home-mande-repo-quber/bc2f817a-5c6c-4515-9621-2302b82f7f68/scratchpad')
BASE=gl.build_prompt(gl.DEFAULT_ROWS, gl.DEFAULT_COLS)
A="- Two tables stacked vertically are separate ONLY when each has its own\n  title/caption and its own column-header block. Report them separately."
assert A in BASE
V1=BASE.replace(A, A+"""
- Two tables printed SIDE BY SIDE are separate tables: each has its own
  column-header block and its own row-label column, and a vertical band of
  empty grid columns separates them. Report each with its own column span;
  never report one region spanning both.""")
gl.build_prompt=lambda r,c: V1
from quber.core.extractors.set_of_mark import SetOfMarkExtractor
from quber.agents.llm_client import get_llm_client
ext=SetOfMarkExtractor(dpi=200, llm=get_llm_client("api"))
t0=time.time()
tables=ext.extract_tables_sync(Path('data/playground/998c8ed06c0be22d.pdf'))
out=[t.model_dump(mode='json') for t in tables]
json.dump(out, open(S/'v1-full.tables.json','w'))
print(f"done: {len(tables)} tables in {time.time()-t0:.0f}s")
