Share library/extracted for schematic and PCB review.

PCB AI skips a second PDF exam (pintable cache, pdf_path=None) and the report
gains a PCB exam section plus power-trace, thermal, via, Kelvin, and GND-stitch
checks grounded in board geometry and extracted specs.
This commit is contained in:
2026-09-20 08:32:23 +02:00
parent f3f96ea4d1
commit 8f4ebc645c
15 changed files with 1014 additions and 107 deletions
+26 -27
View File
@@ -288,7 +288,7 @@ async def review_ic_async(
graph: DesignGraph,
constraints_map: ConstraintsMap,
ic_ref: str,
pdf_path: str,
pdf_path: str | None,
on_progress: ProgressCallback | None = None,
api_logger: ApiLogger | None = None,
trace_git_commit: str = "unknown",
@@ -301,21 +301,21 @@ async def review_ic_async(
) -> tuple[ReviewResult, dict]:
"""Review one IC against its datasheet. Async, multi-turn.
Returns ``(ReviewResult, trace)`` — ``trace`` is a transcript dict of the
full agentic loop (turns, tool calls + outputs, final submission) for
offline inspection. Trace assembly is best-effort and never affects the
review result.
``pdf_path`` may be ``None`` when the caller already has library
extraction (PCB layout-only exam) — no PDF is attached and citations
are not re-verified against a PDF.
"""
comp = graph.components[ic_ref]
mpn = comp.mpn or comp.value
# Datasheet identity for the trace — hash the original PDF, not the
# trimmed copy, so the reference is stable across trim-heuristic changes.
try:
ds_md5 = hashlib.md5(Path(pdf_path).read_bytes()).hexdigest()
except Exception:
log.exception("trace: datasheet md5 failed for %s", ic_ref)
ds_md5 = None
ds_md5 = None
if pdf_path:
try:
ds_md5 = hashlib.md5(Path(pdf_path).read_bytes()).hexdigest()
except Exception:
log.exception("trace: datasheet md5 failed for %s", ic_ref)
# Pre-compute which designators the excerpt tool will accept for this
# review (neighbors via signal nets only — power/GND fan-out filtered).
@@ -338,7 +338,7 @@ async def review_ic_async(
current_ic=ic_ref,
connected_designators=connected_designators,
graph=graph,
pdf_dir=pdf_dir or Path(pdf_path).parent,
pdf_dir=pdf_dir or (Path(pdf_path).parent if pdf_path else Path(".")),
storage=storage,
cache=excerpt_cache if excerpt_cache is not None else {},
fetch_budget=_PER_REVIEW_FETCH_BUDGET,
@@ -347,7 +347,7 @@ async def review_ic_async(
)
# Trim PDF up-front — both primary and fallback attempts share it.
trimmed_pdf = _select_review_pages(pdf_path)
trimmed_pdf = _select_review_pages(pdf_path) if pdf_path else None
try:
async def _run(provider, model) -> tuple[ReviewResult, dict]:
t0 = time.monotonic()
@@ -377,15 +377,13 @@ async def review_ic_async(
if extra_context.strip():
user_text += "\n\n" + extra_context.strip()
user_blocks: list = []
if trimmed_pdf:
user_blocks.append(PdfBlock(path=Path(trimmed_pdf), cacheable=True))
user_blocks.append(TextBlock(text=user_text, cacheable=True))
initial_msg = Message(
role="user",
content=[
PdfBlock(path=Path(trimmed_pdf), cacheable=True),
TextBlock(
text=user_text,
cacheable=True,
),
],
content=user_blocks,
)
messages: list[Message] = [initial_msg]
@@ -465,13 +463,14 @@ async def review_ic_async(
mpn_by_designator=mpn_by_designator,
connected=connected_designators,
)
verify_finding_citations(
result.findings,
default_pdf=Path(pdf_path),
default_mpn=mpn,
pdf_dir=excerpt_state.pdf_dir,
mpn_by_designator=mpn_by_designator,
)
if pdf_path:
verify_finding_citations(
result.findings,
default_pdf=Path(pdf_path),
default_mpn=mpn,
pdf_dir=excerpt_state.pdf_dir,
mpn_by_designator=mpn_by_designator,
)
turn_record["tool_calls"].append({
"name": "submit_review",
"input": tc.input,
@@ -610,7 +609,7 @@ async def review_ic_async(
return await call_with_fallback("validation", _run)
finally:
if trimmed_pdf != pdf_path:
if trimmed_pdf and pdf_path and trimmed_pdf != pdf_path:
Path(trimmed_pdf).unlink(missing_ok=True)