This commit is contained in:
eddiesoehnel committed 2026-08-24 12:22:24 -06:00
1 parent aca6452f20
commit 6524457c7c
65 files changed
+2381 -192

No files matched your search

@@ -102,6 +102,17 @@ def normalize_list(value: Any) -> list[str]:
return result
def dedupe_preserving_order(value: Any) -> Any:
"""Remove repeated list items without coercing invalid values."""
if not isinstance(value, list):
return value
result: list[Any] = []
for item in value:
if item not in result:
result.append(item)
return result
def normalize_capture_type(source: dict[str, Any], warnings: list[str]) -> str:
if "CaptureType" not in source:
return "legacy"
@@ -116,7 +127,9 @@ def normalize_capture_type(source: dict[str, Any], warnings: list[str]) -> str:
def has_publication_restrictions(value: Any) -> bool:
return bool(normalize_list(value))
# The master template uses "public" as an affirmative publishing state.
# Blank values are legacy publishable records; all other values fail closed.
return any(item.casefold() != "public" for item in normalize_list(value))
def parse_record_date(value: Any) -> str | None:
@@ -1244,14 +1257,21 @@ def command_sync(args: argparse.Namespace) -> int:
if source_path.stem.lower().startswith("hub_template"):
ignored_templates += 1
continue
target = output_hrecords / source_path.name
source = load_json(source_path)
if not source:
skipped += 1
if target.exists():
expected_records.add(target.name)
previous = load_json(target) or {}
for media in previous.get("media", []):
public_path = media.get("public_path")
if public_path:
expected_files.add(Path(public_path).name)
continue
if required_tag not in normalize_list(source.get("HubTags")):
continue
matched += 1
target = output_hrecords / source_path.name
if has_publication_restrictions(source.get("PublicationRestrictions")):
quarantined += 1
previous = load_json(target) if target.exists() else None
@@ -1546,6 +1566,13 @@ def command_apply_reasoning(args: argparse.Namespace) -> int:
patch = json.loads(patch_path.read_text(encoding="utf-8"))
if patch.get("record_id") != args.record_id:
raise RuntimeError("Patch record_id does not match --record-id")
consulted_documents = patch.get("corpus_documents_consulted")
normalized_documents = dedupe_preserving_order(consulted_documents)
if isinstance(consulted_documents, list) and len(normalized_documents) != len(consulted_documents):
patch = dict(patch)
patch["corpus_documents_consulted"] = normalized_documents
removed = len(consulted_documents) - len(normalized_documents)
print(f"Normalized corpus_documents_consulted: removed {removed} duplicate entr{'y' if removed == 1 else 'ies'}.")
issues = validate_reasoning_patch(patch)
if issues:
for issue in issues: