Use explicit fresh hosted capability snapshots for plan checks

Assistant: codex
Assistant-Model: gpt-6-astra
Assistant-Session: 01a07ff8-19d0-7820-b4d0-1353833cb7fc
This commit is contained in:
tegwick 2026-09-08 12:10:17 +02:00
parent 5501b8bb56
commit 2621cf2752
6 changed files with 353 additions and 11 deletions

View file

@ -16,6 +16,7 @@ from reuse_surface import hub_client
from reuse_surface.federation import FEDERATED_INDEX_PATH
from reuse_surface.llm_bridge import execute_prompt, extract_json_object
from reuse_surface.overlaps import TOKEN_RE
from reuse_surface.plan_snapshot import load_hosted_snapshot
from reuse_surface.registry import ROOT, load_index
from reuse_surface.statehub_bridge import file_capability_request
@ -260,8 +261,16 @@ def run_plan_check(
top_n: int = 5,
use_llm: bool = True,
llm_url: str | None = None,
hub_url: str | None = None,
max_index_age_hours: float = 24,
) -> dict[str, Any]:
capabilities, updated = load_federated_capabilities()
if hub_url is not None:
capabilities, updated, provenance = load_hosted_snapshot(
hub_url, max_age_hours=max_index_age_hours
)
else:
capabilities, updated = load_federated_capabilities()
provenance = {"kind": "local", "capability_count": len(capabilities)}
matches = match_query(query, capabilities, tie_window=tie_window)
top_score = matches[0].score if matches else 0.0
verdict = verdict_for_score(
@ -302,6 +311,7 @@ def run_plan_check(
],
"federated_index_updated": updated,
"federated_index_stale_warning": _staleness_warning(updated),
"index_source": provenance,
}
if notes:
result["notes"] = notes
@ -334,7 +344,13 @@ def format_plan_check_markdown(result: dict[str, Any]) -> str:
elif verdict == "extend":
lines.append("**Verdict: EXTEND** — scope overlaps closely enough that extending the top match is likely cheaper than a new capability.")
else:
lines.append("**Verdict: NEW** — no close match in the federated index; proceed.")
lines.append("**Verdict: NEW** — no close lexical match in this index; review candidates and owner contracts before building.")
source = result.get("index_source", {})
if source.get("kind") == "hosted":
lines.extend(["", f"Source: {source['url']} ({source['capability_count']} capabilities)",
f"Composed: {source['composed_at']}; fetched: {source['fetched_at']}",
f"Snapshot SHA-256: `{source['sha256']}`"])
warning = result.get("federated_index_stale_warning")
if warning: