Skip to content

zrwangems/dsh-zrwang-plugin / ars/skills/sr-screener

sr-screener

Flagged

系统综述文献筛选:把方案或 PROSPERO 协议转成资格规则,双盲筛选标题摘要与全文,第三人裁决冲突,输出 PRISMA 2020 计数、EndNote/Zotero RIS 分组与可交付给论文技能的 literature_corpus。Triggers: systematic review screening, screen papers, PRISMA counts, pilot screening, adjudicate conflicts | 文献筛选, 系统综述筛选, PRISMA 计数, 筛选冲突裁决。

FileKindSize
SKILL.mdskill md33.1 KB
_shared/ARCHITECTURE.mdmarkdown51.7 KB
_shared/MODE_REGISTRY.mdmarkdown6.7 KB
_shared/agents/compliance_agent.mdmarkdown9.4 KB
_shared/artifact_reproducibility_pattern.mdmarkdown9.8 KB
_shared/benchmark_report.schema.jsonconfig2.7 KB
_shared/benchmark_report_pattern.mdmarkdown8.8 KB
_shared/bibliographic_integrity_signals.mdmarkdown8.1 KB
_shared/collaboration_depth_rubric.mdmarkdown11.5 KB
_shared/compliance_checkpoint_protocol.mdmarkdown8.9 KB
_shared/compliance_report.schema.jsonconfig8.1 KB
_shared/contracts/README.mdmarkdown54.7 KB
_shared/contracts/activity/adjudication_activity_input.schema.jsonconfig18.5 KB
_shared/contracts/activity/adjudication_activity_store.schema.jsonconfig18.7 KB
_shared/contracts/audit/audit_jsonl.schema.jsonconfig5.4 KB
_shared/contracts/audit/audit_sidecar.schema.jsonconfig8.4 KB
_shared/contracts/audit/audit_verdict.schema.jsonconfig5.4 KB
_shared/contracts/audit/cross_document_consistency_advisory.schema.jsonconfig20.4 KB
_shared/contracts/audit/cross_document_consistency_advisory_draft.schema.jsonconfig23.4 KB
_shared/contracts/audit/cross_document_source_manifest.schema.jsonconfig6.3 KB
_shared/contracts/audit/tortured_phrase_advisory.schema.jsonconfig30.9 KB
_shared/contracts/audit/tortured_phrase_snapshot.schema.jsonconfig4.9 KB
_shared/contracts/audit/tortured_phrase_snapshot_manifest.schema.jsonconfig7.3 KB
_shared/contracts/capability/stage_capability_matrix.jsonconfig23.5 KB
_shared/contracts/claim_standing/candidate_ledger.schema.jsonconfig23.1 KB
_shared/contracts/claim_standing/query_plan.schema.jsonconfig12.7 KB
_shared/contracts/claim_standing/query_plan_v1_1.schema.jsonconfig20.3 KB
_shared/contracts/claim_standing/retrieval_input.schema.jsonconfig14.4 KB
_shared/contracts/claim_standing/stance_record.schema.jsonconfig11.7 KB
_shared/contracts/claim_standing/transmission_ledger.schema.jsonconfig7.6 KB
_shared/contracts/cross_model/codex_citation_receipt.schema.jsonconfig4.7 KB
_shared/contracts/cross_model/codex_citation_request.schema.jsonconfig986 B
_shared/contracts/cross_model/promotion_bakeoff_sealed_commitment.schema.jsonconfig1.5 KB
_shared/contracts/cross_model/promotion_bakeoff_sealed_reveal.schema.jsonconfig1.5 KB
_shared/contracts/degradation_registry.jsonconfig42.5 KB
_shared/contracts/evaluator/full.jsonconfig6.3 KB
_shared/contracts/evidence/claim_registry.schema.jsonconfig2.3 KB
_shared/contracts/evidence/claim_registry_coverage_report.schema.jsonconfig4.8 KB
_shared/contracts/evidence/evidence_row.schema.jsonconfig14.3 KB
_shared/contracts/evidence/evidence_row_v1_1.schema.jsonconfig11.4 KB
_shared/contracts/evidence/evidence_row_v1_2.schema.jsonconfig21.8 KB
_shared/contracts/evidence/evidence_row_v1_3.schema.jsonconfig10.7 KB
_shared/contracts/human_subjects/authority_profile_registry.schema.jsonconfig16.7 KB
_shared/contracts/human_subjects/committee_correspondence.schema.jsonconfig9.9 KB
_shared/contracts/human_subjects/content_coverage_advisory.schema.jsonconfig19.9 KB
_shared/contracts/human_subjects/irb_context_record.schema.jsonconfig12.1 KB
_shared/contracts/human_subjects/resolved_authority_context.schema.jsonconfig11.8 KB
_shared/contracts/human_subjects/review_pathway_rule_trace.schema.jsonconfig9.5 KB
_shared/contracts/human_subjects/review_pathway_trace_request.schema.jsonconfig4.8 KB
_shared/contracts/human_subjects/submission_packet_inventory.schema.jsonconfig8.5 KB
_shared/contracts/human_subjects/submission_packet_manifest.schema.jsonconfig32.2 KB
_shared/contracts/passport/audit_artifact_entry.schema.jsonconfig10.8 KB
_shared/contracts/passport/bibliographic_integrity_signal.schema.jsonconfig48.9 KB
_shared/contracts/passport/citation_provenance.schema.jsonconfig4.8 KB
_shared/contracts/passport/citation_verification_summary.schema.jsonconfig8.2 KB
_shared/contracts/passport/claim_audit_result.schema.jsonconfig7.8 KB
_shared/contracts/passport/claim_drift.schema.jsonconfig3.8 KB
_shared/contracts/passport/claim_intent_manifest.schema.jsonconfig6.6 KB
_shared/contracts/passport/constraint_violation.schema.jsonconfig3.6 KB
_shared/contracts/passport/excluded_source_entry.schema.jsonconfig1.7 KB
_shared/contracts/passport/experiment_alignment_result.schema.jsonconfig4.8 KB
_shared/contracts/passport/experiment_provenance_entry.schema.jsonconfig10.0 KB
_shared/contracts/passport/human_read_log.schema.jsonconfig3.8 KB
_shared/contracts/passport/inquiry_ledger_ref.schema.jsonconfig881 B
_shared/contracts/passport/literature_corpus_entry.schema.jsonconfig30.3 KB
_shared/contracts/passport/preregistration_artifact.schema.jsonconfig4.3 KB
_shared/contracts/passport/rejection_log.schema.jsonconfig3.3 KB
_shared/contracts/passport/reset_ledger_entry.schema.jsonconfig7.1 KB
_shared/contracts/passport/run_ledger.schema.jsonconfig8.0 KB
_shared/contracts/passport/standing_constraint_entry.schema.jsonconfig2.6 KB
_shared/contracts/passport/temporal_audit_results.schema.jsonconfig8.8 KB
_shared/contracts/passport/terminal_policies.schema.jsonconfig8.1 KB
_shared/contracts/passport/timeline.schema.jsonconfig4.7 KB
_shared/contracts/passport/uncited_assertion.schema.jsonconfig3.3 KB
_shared/contracts/passport/uncited_audit_failure.schema.jsonconfig4.4 KB
_shared/contracts/passport/user_attested_read_resolution.schema.jsonconfig3.2 KB
_shared/contracts/passport/version_records.schema.jsonconfig4.9 KB
_shared/contracts/patch/block_manifest.schema.jsonconfig2.1 KB
_shared/contracts/patch/legacy/v1_0/revision_patch.schema.jsonconfig5.3 KB
_shared/contracts/patch/revision_patch.schema.jsonconfig8.9 KB
_shared/contracts/pdf/pdf_content_classifier_diagnostic.schema.jsonconfig1.2 KB
_shared/contracts/pdf/pdf_content_classifier_worker.schema.jsonconfig2.2 KB
_shared/contracts/pdf/pdf_read_preflight.schema.jsonconfig6.8 KB
_shared/contracts/re_review/input_manifest.schema.jsonconfig7.6 KB
_shared/contracts/re_review/legacy/v1_0/input_manifest.schema.jsonconfig6.2 KB
_shared/contracts/re_review/legacy/v1_0/precommitment.schema.jsonconfig8.9 KB
_shared/contracts/re_review/legacy/v1_0/traceability.schema.jsonconfig34.2 KB
_shared/contracts/re_review/legacy/v1_0/verdict_record.schema.jsonconfig10.5 KB
_shared/contracts/re_review/precommitment.schema.jsonconfig8.6 KB
_shared/contracts/re_review/traceability.schema.jsonconfig37.7 KB
_shared/contracts/re_review/verdict_record.schema.jsonconfig10.5 KB
_shared/contracts/research_workflow/inquiry_branch_ledger.schema.jsonconfig17.0 KB
_shared/contracts/research_workflow/research_workflow_profile.schema.jsonconfig7.2 KB
_shared/contracts/research_workflow/research_workflow_profile_selection_receipt.schema.jsonconfig3.9 KB
_shared/contracts/review_target/constructive_review_findings.schema.jsonconfig7.0 KB
_shared/contracts/review_target/criteria_registry.schema.jsonconfig4.0 KB
_shared/contracts/review_target/review_criteria_binding_manifest.schema.jsonconfig7.9 KB
_shared/contracts/review_target/review_criteria_source_receipt.schema.jsonconfig5.6 KB
_shared/contracts/review_target/review_target_context.schema.jsonconfig4.5 KB
_shared/contracts/review_target/review_target_declaration.schema.jsonconfig4.6 KB
_shared/contracts/reviewer/full.jsonconfig3.7 KB
_shared/contracts/reviewer/methodology_focus.jsonconfig2.2 KB
_shared/contracts/reviewer/review_panel_provenance.schema.jsonconfig7.8 KB
_shared/contracts/reviewer/review_panel_provenance_carrier.schema.jsonconfig4.1 KB
_shared/contracts/reviewer/review_panel_provenance_input.schema.jsonconfig3.5 KB
_shared/contracts/revision/author_adjudication.schema.jsonconfig7.8 KB
_shared/contracts/revision/author_adjudication_input.schema.jsonconfig1.2 KB
_shared/contracts/revision/claim_strength_drift_disposition.schema.jsonconfig3.6 KB
_shared/contracts/revision/claim_strength_drift_disposition_input.schema.jsonconfig3.1 KB
_shared/contracts/revision/claim_strength_drift_findings.schema.jsonconfig4.2 KB
_shared/contracts/revision/claim_surface_manifest.schema.jsonconfig3.3 KB
_shared/contracts/revision/integrity_correction_authorization.schema.jsonconfig4.3 KB
_shared/contracts/revision/integrity_correction_authorization_input.schema.jsonconfig1.5 KB
_shared/contracts/revision/integrity_correction_list.schema.jsonconfig1.8 KB
_shared/contracts/revision/integrity_pass_receipt.schema.jsonconfig809 B
_shared/contracts/revision/revision_evidence_bundle.schema.jsonconfig4.9 KB
_shared/contracts/revision/revision_roadmap.schema.jsonconfig11.2 KB
_shared/contracts/submission/format_profile.example.yamlconfig971 B
_shared/contracts/submission/format_profile.schema.jsonconfig4.6 KB
_shared/contracts/submission/submission_verification_report.schema.jsonconfig10.3 KB
_shared/contracts/submission/venue_profile.schema.jsonconfig4.1 KB
_shared/contracts/writer/full.jsonconfig3.6 KB
_shared/cross_model_verification.mdmarkdown83.3 KB
_shared/description-original.mdmarkdown1.1 KB
_shared/dsh-runtime.mdmarkdown1.5 KB
_shared/evals_lift_report.schema.jsonconfig5.0 KB
_shared/ground_truth_isolation_pattern.mdmarkdown16.0 KB
_shared/handoff_schemas.mdmarkdown96.9 KB
_shared/human_subjects_authority_registry.jsonconfig49.5 KB
_shared/mode_spectrum.mdmarkdown5.2 KB
_shared/model_tiering.mdmarkdown12.6 KB
_shared/output_language_pair.mdmarkdown7.7 KB
_shared/policy_data/nature_policy.mdmarkdown3.9 KB
_shared/prisma_trAIce_protocol.mdmarkdown10.2 KB
_shared/raise_framework.mdmarkdown7.5 KB
_shared/references/authority_content_coverage_advisory_protocol.mdmarkdown14.0 KB
_shared/references/claim_standing_candidate_ledger_protocol.mdmarkdown19.2 KB
_shared/references/claim_strength_ladder.mdmarkdown5.5 KB
_shared/references/cross_document_consistency_advisory_protocol.mdmarkdown13.5 KB
_shared/references/evidence_row_protocol.mdmarkdown14.4 KB
_shared/references/firm_rules.mdmarkdown11.0 KB
_shared/references/human_subjects_authority_protocol.mdmarkdown13.1 KB
_shared/references/intent_clarification_protocol.mdmarkdown11.9 KB
_shared/references/irb_terminology_glossary.mdmarkdown12.4 KB
_shared/references/per_source_method_weaknesses.mdmarkdown4.2 KB
_shared/references/protected_hedging_phrases.mdmarkdown8.9 KB
_shared/references/psychometric_terminology_glossary.mdmarkdown8.7 KB
_shared/references/review_criteria_consumer_protocol.mdmarkdown10.3 KB
_shared/references/review_form_note.mdmarkdown11.3 KB
_shared/references/review_pathway_rule_trace_protocol.mdmarkdown8.3 KB
_shared/references/routing_core.mdmarkdown5.7 KB
_shared/references/submission_packet_manifest_protocol.mdmarkdown13.6 KB
_shared/references/word_count_conventions.mdmarkdown9.0 KB
_shared/research_workflow_profiles/field_general.jsonconfig1.2 KB
_shared/review_criteria_registry.jsonconfig11.5 KB
_shared/review_criteria_sources/msr-2027-technical-papers.2026-08-24.jsonconfig2.0 KB
_shared/review_criteria_sources/sigsoft-empirical-standards.2026-08-24.jsonconfig1.4 KB
_shared/sprint_contract.schema.jsonconfig19.0 KB
_shared/style_calibration_protocol.mdmarkdown6.9 KB
_shared/templates/codex_audit_multifile_template.mdmarkdown16.7 KB
agents/protocol_architect_agent.mdmarkdown6.4 KB
agents/qc_auditor_agent.mdmarkdown5.2 KB
agents/reporter_agent.mdmarkdown3.7 KB
agents/screening_reviewer_agent.mdmarkdown5.4 KB
examples/example_config_dta.jsonconfig1.8 KB
examples/example_protocol_dta.mdmarkdown3.8 KB
examples/quick_screen_example.mdmarkdown3.0 KB
references/decision_rules.mdmarkdown6.7 KB
references/failure_paths.mdmarkdown4.1 KB
references/orchestration.mdmarkdown12.4 KB
references/protocol_template.mdmarkdown6.2 KB
references/quality_control.mdmarkdown6.0 KB
references/reporting_and_handoff.mdmarkdown5.8 KB
references/reviewer_roles.mdmarkdown4.0 KB
scripts/_claim_audit_constants.pyscript13.7 KB
scripts/_markdown_lint_util.pyscript9.0 KB
scripts/_next_verified_at_ms.pyscript6.5 KB
scripts/_skill_lint.pyscript13.6 KB
scripts/ars_cache_invalidate.pyscript1.3 KB
scripts/ars_mark_read.pyscript18.2 KB
scripts/ars_write_scope_guard.pyscript30.9 KB
scripts/audit_snapshot.pyscript23.5 KB
scripts/bibliographic_integrity_signals.pyscript32.2 KB
scripts/build_claim_standing_candidate_ledger.pyscript54.3 KB
scripts/build_claim_standing_query_plan.pyscript25.0 KB
scripts/build_content_coverage_advisory.pyscript45.1 KB
scripts/build_cross_document_consistency_advisory.pyscript77.9 KB
scripts/build_outputs.pyscript33.0 KB
scripts/build_review_pathway_rule_trace.pyscript34.2 KB
scripts/build_submission_packet_manifest.pyscript88.1 KB
scripts/build_workflow.pyscript20.0 KB
scripts/check_audit_artifact_consistency.pyscript103.9 KB
scripts/check_benchmark_report.pyscript2.4 KB
scripts/check_claim_audit_consistency.pyscript68.9 KB
scripts/check_claim_standing_freshness.pyscript9.7 KB
scripts/check_claim_standing_transmissions.pyscript17.9 KB
scripts/check_committee_correspondence.pyscript14.9 KB
scripts/check_corpus_consumer_protocol.pyscript13.7 KB
scripts/check_cross_model_handoff_contract.pyscript9.9 KB
scripts/check_data_access_level.pyscript5.2 KB

scripts/build_content_coverage_advisory.py

View on GitHub
#!/usr/bin/env python3
"""Finalize, replay-validate, and render the bounded #681 LLM advisory.

The runtime consumes evaluator judgments only as explicit input.  It performs no
model call, prose classification, retrieval, directory scan, or ambient source
lookup.  Every authority and packet pointer is re-established from the complete
#666/#667 named input set before it is copied into the advisory carrier.
"""
from __future__ import annotations

import argparse
import copy
import datetime as dt
import json
import re
import sys
import unicodedata
from collections.abc import Mapping
from pathlib import Path
from typing import Any, NoReturn

try:  # Direct execution puts scripts/ on sys.path.
    from build_submission_packet_manifest import validate_submission_packet_manifest
    from evidence_rows import (
        ADVISORY_SCHEMA_VERSION,
        ADVISORY_SURFACE,
        DOCUMENT_LOCATOR_PROVENANCE,
        EvidenceRowError,
        build_advisory,
        render_markdown as render_evidence_rows_markdown,
        strict_percent_decode,
    )
    from resolve_human_subjects_authority import ContractError, digest, load_json
except ModuleNotFoundError:  # Package-style imports used by some test runners.
    from scripts.build_submission_packet_manifest import (  # type: ignore[no-redef]
        validate_submission_packet_manifest,
    )
    from scripts.evidence_rows import (  # type: ignore[no-redef]
        ADVISORY_SCHEMA_VERSION,
        ADVISORY_SURFACE,
        DOCUMENT_LOCATOR_PROVENANCE,
        EvidenceRowError,
        build_advisory,
        render_markdown as render_evidence_rows_markdown,
        strict_percent_decode,
    )
    from scripts.resolve_human_subjects_authority import (  # type: ignore[no-redef]
        ContractError,
        digest,
        load_json,
    )


DRAFT_SCHEMA_VERSION = "content-coverage-advisory-draft/1.0"
REPORT_SCHEMA_VERSION = "content-coverage-advisory/1.0"
LAYER = "LLM-ADVISORY"
EVALUATION_STATUS = "UNMEASURED"
MAX_JUDGMENTS = 4096
MAX_SESSION_CONTENT_BYTES = 64 * 1024 * 1024
MAX_TOTAL_SESSION_CONTENT_BYTES = 256 * 1024 * 1024
MAX_ADVISORY_BYTES = 8 * 1024 * 1024
MAX_RENDER_PAGE_SIZE = 25

PERFORMED_STATUSES = frozenset({"DOCUMENTED", "NOT_LOCATED", "CONFLICTING"})
ADVISORY_STATUSES = frozenset(
    {
        "DOCUMENTED",
        "NOT_LOCATED",
        "CONFLICTING",
        "APPLICABILITY_UNRESOLVED",
        "ACCEPTANCE_UNVERIFIED",
    }
)
FAILURE_STATES = frozenset(
    {"not_checked", "source_missing", "access_failed", "retrieval_failed"}
)
LOCATOR_KINDS = frozenset({"document", "page", "section", "paragraph", "other"})
REASON_CODES = frozenset(
    {
        "ALL_EXPECTATIONS_APPEAR_COVERED",
        "EXPECTATION_NOT_LOCATED",
        "CONFLICTING_COVERAGE_OBSERVATIONS",
        "COVERAGE_CHECK_NOT_PERFORMED",
        "SESSION_CONTENT_NOT_PROVIDED",
        "SOURCE_ACCESS_FAILED",
        "SOURCE_RETRIEVAL_FAILED",
        "DETERMINISTIC_PACKET_GAP",
        "DETERMINISTIC_PACKET_CONFLICT",
        "WAIVER_OR_EXCEPTION_BOUNDARY",
        "EXTERNAL_DEPENDENCY",
        "APPLICABILITY_UNRESOLVED",
        "NO_PROFILED_STRUCTURED_EXPECTATIONS",
        "INSTITUTIONAL_ACCEPTANCE_REQUIRED",
    }
)
_RFC3339_RE = re.compile(
    r"^[0-9]{4}-[0-9]{2}-[0-9]{2}[Tt]"
    r"(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]"
    r"(?:\.[0-9]+)?(?:[Zz]|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])$"
)
FAILURE_REASON = {
    "not_checked": "COVERAGE_CHECK_NOT_PERFORMED",
    "source_missing": "SESSION_CONTENT_NOT_PROVIDED",
    "access_failed": "SOURCE_ACCESS_FAILED",
    "retrieval_failed": "SOURCE_RETRIEVAL_FAILED",
}
STATUS_REASON = {
    "DOCUMENTED": "ALL_EXPECTATIONS_APPEAR_COVERED",
    "NOT_LOCATED": "EXPECTATION_NOT_LOCATED",
    "CONFLICTING": "CONFLICTING_COVERAGE_OBSERVATIONS",
}


class ContentCoverageAdvisoryError(ValueError):
    """A #681 draft, binding, or report violates the frozen contract."""


class ContentCoverageAdvisoryInputError(ContentCoverageAdvisoryError):
    """A named CLI input could not be loaded as a supported strict value."""


def _fail(path: str, message: str) -> NoReturn:
    raise ContentCoverageAdvisoryError(f"{path}: {message}")


def _closed(value: Any, path: str, fields: set[str]) -> dict[str, Any]:
    if not isinstance(value, dict):
        _fail(path, "must be an object")
    missing = fields - set(value)
    extra = set(value) - fields
    if missing:
        _fail(path, f"missing field(s): {', '.join(sorted(missing))}")
    if extra:
        _fail(path, f"undeclared field(s): {', '.join(sorted(extra))}")
    return value


def _array(value: Any, path: str, *, maximum: int = MAX_JUDGMENTS) -> list[Any]:
    if not isinstance(value, list):
        _fail(path, "must be an array")
    if len(value) > maximum:
        _fail(path, f"exceeds {maximum} items")
    return value


def _text(value: Any, path: str, *, maximum: int = 1000, empty: bool = False) -> str:
    if not isinstance(value, str) or (not empty and not value):
        _fail(path, "must be a string" + ("" if empty else " with at least one character"))
    if len(value) > maximum:
        _fail(path, f"must not exceed {maximum} characters")
    for character in value:
        code = ord(character)
        if code == 127 or code < 32 or 0xD800 <= code <= 0xDFFF:
            _fail(path, "contains a forbidden control or surrogate character")
        if unicodedata.category(character) in {"Cf", "Zl", "Zp"}:
            _fail(path, "contains a forbidden format or line-separator character")
    return value


def _identifier(value: Any, path: str) -> str:
    text = _text(value, path, maximum=200)
    if not text[0].isalnum() or not text[0].isascii() or not all(
        character.isascii()
        and (character.islower() or character.isdigit() or character in "._-")
        for character in text
    ):
        _fail(path, "must use lowercase ASCII letters, digits, dot, underscore, or hyphen")
    return text


def _enum(value: Any, path: str, choices: frozenset[str] | set[str]) -> str:
    if not isinstance(value, str) or value not in choices:
        _fail(path, f"must be one of {sorted(choices)}")
    return value


def _timestamp(value: Any, path: str) -> str:
    text = _text(value, path, maximum=100)
    if _RFC3339_RE.fullmatch(text) is None:
        _fail(path, "must be an RFC 3339 date-time with an offset")
    candidate = text[:-1] + "+00:00" if text[-1] in {"Z", "z"} else text
    try:
        dt.datetime.fromisoformat(candidate)
    except ValueError as exc:
        _fail(path, f"must be a real RFC 3339 date-time: {exc}")
    return text


def _canonical_bytes(value: Any) -> bytes:
    try:
        return json.dumps(
            value,
            ensure_ascii=False,
            sort_keys=True,
            separators=(",", ":"),
            allow_nan=False,
        ).encode("utf-8", errors="strict")
    except (TypeError, ValueError, UnicodeError, RecursionError) as exc:
        _fail("value", f"cannot be serialized canonically: {exc}")


def _enforce_advisory_byte_limit(value: Any) -> None:
    size = len(_canonical_bytes(value))
    if size > MAX_ADVISORY_BYTES:
        _fail("advisory", f"canonical carrier exceeds {MAX_ADVISORY_BYTES} bytes")


def _pointer_get(root: dict[str, Any], pointer: str, path: str) -> Any:
    if not isinstance(pointer, str) or not pointer.startswith("/"):
        _fail(path, "must be an absolute JSON Pointer")
    current: Any = root
    for token in pointer[1:].split("/"):
        if "~" in token:
            token = token.replace("~1", "/").replace("~0", "~")
        if isinstance(current, list):
            if not token.isdigit() or (len(token) > 1 and token.startswith("0")):
                _fail(path, "contains an invalid array index")
            index = int(token)
            if index >= len(current):
                _fail(path, "does not resolve")
            current = current[index]
        elif isinstance(current, dict) and token in current:
            current = current[token]
        else:
            _fail(path, "does not resolve")
    return current


def _validate_session_contents(value: Mapping[str, str]) -> dict[str, str]:
    if not isinstance(value, Mapping):
        _fail("session_contents", "must be an artifact_id-to-text mapping")
    result: dict[str, str] = {}
    total = 0
    for count, (key, content) in enumerate(value.items(), start=1):
        if count > 512:
            _fail("session_contents", "exceeds 512 explicitly supplied artifacts")
        artifact_id = _identifier(key, "session_contents key")
        if artifact_id in result:
            _fail(
                f"session_contents.{artifact_id}",
                "duplicates an earlier explicitly supplied artifact",
            )
        if not isinstance(content, str):
            _fail(f"session_contents.{artifact_id}", "must be a string")
        try:
            size = len(content.encode("utf-8", errors="strict"))
        except UnicodeError as exc:
            _fail(f"session_contents.{artifact_id}", f"is not strict UTF-8: {exc}")
        if size > MAX_SESSION_CONTENT_BYTES:
            _fail(f"session_contents.{artifact_id}", "exceeds 64 MiB")
        total += size
        if total > MAX_TOTAL_SESSION_CONTENT_BYTES:
            _fail("session_contents", "exceeds 256 MiB total")
        result[artifact_id] = content
    return result


def _validate_draft(draft: dict[str, Any]) -> list[dict[str, Any]]:
    root = _closed(draft, "draft", {"schema_version", "layer", "judgments"})
    if root["schema_version"] != DRAFT_SCHEMA_VERSION:
        _fail("draft.schema_version", f"must equal {DRAFT_SCHEMA_VERSION}")
    if root["layer"] != LAYER:
        _fail("draft.layer", f"must equal {LAYER}")
    judgments: list[dict[str, Any]] = []
    seen: set[tuple[Any, ...]] = set()
    fields = {
        "requirement_id",
        "expectation_pointer",
        "artifact_id",
        "coverage_check_state",
        "advisory_coverage_status",
        "document_locator",
        "quoted_anchor_encoded",
        "failure_state",
        "captured_at",
    }
    for index, raw in enumerate(_array(root["judgments"], "draft.judgments")):
        path = f"draft.judgments[{index}]"
        row = _closed(raw, path, fields)
        requirement_id = _identifier(row["requirement_id"], f"{path}.requirement_id")
        expectation_pointer = _text(
            row["expectation_pointer"], f"{path}.expectation_pointer", maximum=2000
        )
        artifact_id = _identifier(row["artifact_id"], f"{path}.artifact_id")
        check_state = _enum(
            row["coverage_check_state"],
            f"{path}.coverage_check_state",
            frozenset({"performed", "not_checked"}),
        )
        locator = _closed(row["document_locator"], f"{path}.document_locator", {"kind", "value"})
        normalized_locator = {
            "kind": _enum(locator["kind"], f"{path}.document_locator.kind", LOCATOR_KINDS),
            "value": _text(locator["value"], f"{path}.document_locator.value", maximum=500),
        }
        encoded = _text(
            row["quoted_anchor_encoded"],
            f"{path}.quoted_anchor_encoded",
            maximum=12000,
            empty=True,
        )
        try:
            decoded = strict_percent_decode(encoded)
        except EvidenceRowError as exc:
            _fail(f"{path}.quoted_anchor_encoded", str(exc))
        status = row["advisory_coverage_status"]
        failure = row["failure_state"]
        captured_at = row["captured_at"]
        if check_state == "performed":
            status = _enum(status, f"{path}.advisory_coverage_status", PERFORMED_STATUSES)
            if failure is not None:
                _fail(f"{path}.failure_state", "must be null when coverage_check_state=performed")
            if status in {"DOCUMENTED", "CONFLICTING"} and not decoded:
                _fail(f"{path}.quoted_anchor_encoded", f"status={status} requires a quote")
            if status == "NOT_LOCATED" and decoded:
                _fail(f"{path}.quoted_anchor_encoded", "NOT_LOCATED requires an empty anchor")
            if status in {"DOCUMENTED", "CONFLICTING"}:
                captured_at = _timestamp(captured_at, f"{path}.captured_at")
            elif captured_at is not None:
                _fail(f"{path}.captured_at", "NOT_LOCATED requires null")
        else:
            if status is not None:
                _fail(f"{path}.advisory_coverage_status", "must be null when not_checked")
            failure = _enum(failure, f"{path}.failure_state", FAILURE_STATES)
            if decoded:
                _fail(f"{path}.quoted_anchor_encoded", "not_checked requires an empty anchor")
            if captured_at is not None:
                _fail(f"{path}.captured_at", "not_checked requires null")
        normalized = {
                "requirement_id": requirement_id,
                "expectation_pointer": expectation_pointer,
                "artifact_id": artifact_id,
                "coverage_check_state": check_state,
                "advisory_coverage_status": status,
                "document_locator": normalized_locator,
                "quoted_anchor_encoded": encoded,
                "failure_state": failure,
                "captured_at": captured_at,
            }
        identity = (
            requirement_id,
            expectation_pointer,
            artifact_id,
            check_state,
            status,
            normalized_locator["kind"],
            normalized_locator["value"],
            encoded,
            failure,
            captured_at,
        )
        if identity in seen:
            _fail(path, "duplicates an earlier exact coverage observation")
        seen.add(identity)
        judgments.append(normalized)
    return judgments


def _manifest_entry_ref(entry: dict[str, Any]) -> dict[str, Any]:
    return {
        "evidence_ref": copy.deepcopy(entry["evidence_ref"]),
        "responsibility": entry["responsibility"],
        "deterministic_status": entry["status"],
        "reason_codes": copy.deepcopy(entry["reason_codes"]),
        "matched_artifact_ids": copy.deepcopy(entry["matched_artifact_ids"]),
    }


def _authority_anchor_ref(requirement: dict[str, Any], pointer: str) -> dict[str, Any]:
    anchor = requirement["authority_anchor"]
    return {
        "authority_anchor_pointer": pointer + "/authority_anchor",
        "authority_anchor_digest": digest(anchor),
        "source_id": anchor["source_id"],
        "provision": anchor["provision"],
        "effective_date": anchor["effective_date"],
        "authority_url": anchor["authority_url"],
    }


def _artifact_indexes(
    inventory: dict[str, Any], manifest: dict[str, Any]
) -> tuple[dict[str, dict[str, Any]], dict[str, dict[str, Any]]]:
    artifacts = {row["artifact_id"]: row for row in inventory["artifacts"]}
    observations = {row["artifact_id"]: row for row in manifest["packet_observations"]}
    return artifacts, observations


def _evidence_row(
    *,
    row_number: int,
    judgment: dict[str, Any],
    requirement_ref: dict[str, Any],
    expectation: dict[str, Any],
    artifact: dict[str, Any],
    observation: dict[str, Any],
    session_contents: dict[str, str],
) -> dict[str, Any]:
    artifact_id = judgment["artifact_id"]
    failure = judgment["failure_state"]
    check_state = judgment["coverage_check_state"]
    source_text = session_contents.get(artifact_id)
    if check_state == "performed" and source_text is None:
        _fail(
            f"draft judgment {artifact_id}",
            "performed coverage requires explicit session-held content",
        )
    if failure in {"source_missing", "access_failed", "retrieval_failed"} and source_text is not None:
        _fail(
            f"draft judgment {artifact_id}.failure_state",
            "contradicts explicitly supplied session content",
        )
    expectation_pointer = judgment["expectation_pointer"]
    template = {
        "schema_version": ADVISORY_SCHEMA_VERSION,
        "surface": ADVISORY_SURFACE,
        "row_id": f"EVR-CC-{row_number:06d}",
        "coverage_subject": {
            "requirement_id": requirement_ref["requirement_id"],
            "requirement_pointer": requirement_ref["requirement_pointer"],
            "authority_anchor_pointer": requirement_ref["authority_anchor_pointer"],
            "expectation_field_id": expectation["field_id"],
            "expectation_pointer": expectation_pointer,
            "expectation_digest": digest(expectation),
            "document_locator": {
                **judgment["document_locator"],
                "provenance": DOCUMENT_LOCATOR_PROVENANCE,
            },
        },
        "source": {
            "artifact_id": artifact_id,
            "relative_path": artifact["relative_path"],
            "source_artifact_sha256": observation["observed_sha256"],
            "source_artifact_size_bytes": observation["observed_size_bytes"],
        },
        "anchor": {
            "kind": (
                "quote"
                if judgment["advisory_coverage_status"] in {"DOCUMENTED", "CONFLICTING"}
                else "none"
            ),
            "value_encoded": judgment["quoted_anchor_encoded"],
        },
        "content_handling": {
            "sharing_scope": "session_only",
            "rights_basis": "not_assessed",
        },
    }
    try:
        return build_advisory(
            template,
            source_text if check_state == "performed" else None,
            failure_state=failure,
            captured_at=judgment["captured_at"],
        )
    except EvidenceRowError as exc:
        _fail(f"evidence row {row_number}", str(exc))


def _finding_from_judgments(
    *,
    requirement_ref: dict[str, Any],
    expectation: dict[str, Any],
    expectation_pointer: str,
    judgments: list[dict[str, Any]],
    allowed_artifacts: set[str],
    artifacts: dict[str, dict[str, Any]],
    observations: dict[str, dict[str, Any]],
    session_contents: dict[str, str],
    row_counter: list[int],
) -> dict[str, Any]:
    if not judgments:
        _fail(expectation_pointer, "is missing explicit draft accounting")
    if len(judgments) > 512:
        _fail(expectation_pointer, "exceeds 512 evidence rows")
    states = {row["coverage_check_state"] for row in judgments}
    statuses = {row["advisory_coverage_status"] for row in judgments}
    if len(states) != 1 or len(statuses) != 1:
        _fail(expectation_pointer, "cannot mix check states or advisory statuses")
    check_state = next(iter(states))
    status = next(iter(statuses))
    if status == "CONFLICTING":
        if len(judgments) < 2:
            _fail(expectation_pointer, "CONFLICTING requires two distinct positive passages")
    elif status == "NOT_LOCATED":
        if {row["artifact_id"] for row in judgments} != allowed_artifacts or len(judgments) != len(allowed_artifacts):
            _fail(
                expectation_pointer,
                "NOT_LOCATED must account exactly once for every eligible artifact",
            )
    elif len(judgments) != 1:
        _fail(expectation_pointer, "DOCUMENTED and not_checked findings require one evidence row")

    evidence: list[dict[str, Any]] = []
    for judgment in sorted(
        judgments,
        key=lambda row: (
            row["artifact_id"],
            row["document_locator"]["kind"],
            row["document_locator"]["value"],
            row["quoted_anchor_encoded"],
            "" if row["captured_at"] is None else row["captured_at"],
            "" if row["failure_state"] is None else row["failure_state"],
            "" if row["advisory_coverage_status"] is None else row["advisory_coverage_status"],
        ),
    ):
        artifact_id = judgment["artifact_id"]
        if artifact_id not in allowed_artifacts:
            _fail(
                expectation_pointer,
                f"artifact {artifact_id!r} is not in a packet-owned DOCUMENTED entry",
            )
        artifact = artifacts.get(artifact_id)
        observation = observations.get(artifact_id)
        if artifact is None or observation is None or observation["state"] != "located":
            _fail(expectation_pointer, f"artifact {artifact_id!r} lacks a located observation")
        row_counter[0] += 1
        evidence.append(
            _evidence_row(
                row_number=row_counter[0],
                judgment=judgment,
                requirement_ref=requirement_ref,
                expectation=expectation,
                artifact=artifact,
                observation=observation,
                session_contents=session_contents,
            )
        )
    if status == "CONFLICTING":
        replay_row_identities = {
            (
                row["source"]["artifact_id"],
                row["excerpt"]["excerpt_sha256"],
                row["excerpt"]["source_span_utf8"]["start"],
                row["excerpt"]["source_span_utf8"]["end"],
                row["coverage_subject"]["document_locator"]["kind"],
                row["coverage_subject"]["document_locator"]["value"],
            )
            for row in evidence
        }
        replay_passage_identities = {
            identity[:4] for identity in replay_row_identities
        }
        if len(replay_row_identities) < 2 or len(replay_passage_identities) < 2:
            _fail(
                expectation_pointer,
                "CONFLICTING requires two distinct replayed passage hashes or UTF-8 spans",
            )
    reason = (
        STATUS_REASON[status]
        if check_state == "performed"
        else FAILURE_REASON[judgments[0]["failure_state"]]
    )
    return {
        "requirement_id": requirement_ref["requirement_id"],
        "authority_anchor_pointer": requirement_ref["authority_anchor_pointer"],
        "expectation_ref": {
            "field_id": expectation["field_id"],
            "expectation_pointer": expectation_pointer,
            "expectation_digest": digest(expectation),
        },
        "coverage_check_state": check_state,
        "advisory_coverage_status": status,
        "reason_codes": [reason],
        "evidence_rows": evidence,
    }


def _ineligible_result(
    requirement_ref: dict[str, Any],
    requirement: dict[str, Any],
    entries: list[dict[str, Any]],
    *,
    applicability_unresolved: bool = False,
) -> dict[str, Any] | None:
    external = [row for row in entries if row["responsibility"] == "external_dependency"]
    waiver = [
        row
        for row in entries
        if row["responsibility"] == "packet_owned"
        if row["status"] == "ACCEPTANCE_UNVERIFIED"
        and "WAIVER_OR_EXCEPTION_CLAIM_UNVERIFIED" in row["reason_codes"]
    ]
    conflicts = [
        row
        for row in entries
        if row["responsibility"] == "packet_owned" and row["status"] == "CONFLICTING"
    ]
    gaps = [
        row
        for row in entries
        if row["responsibility"] == "packet_owned" and row["status"] == "NOT_LOCATED"
    ]
    documented = [
        row
        for row in entries
        if row["responsibility"] == "packet_owned" and row["status"] == "DOCUMENTED"
    ]
    status: str | None = None
    reasons: list[str]
    if applicability_unresolved:
        status = "APPLICABILITY_UNRESOLVED"
        reasons = ["APPLICABILITY_UNRESOLVED"]
    elif conflicts:
        reasons = ["DETERMINISTIC_PACKET_CONFLICT"]
    elif gaps:
        reasons = ["DETERMINISTIC_PACKET_GAP"]
    elif waiver:
        status = "ACCEPTANCE_UNVERIFIED"
        reasons = ["WAIVER_OR_EXCEPTION_BOUNDARY", "INSTITUTIONAL_ACCEPTANCE_REQUIRED"]
    elif documented and not requirement["structured_expectations"]:
        reasons = ["NO_PROFILED_STRUCTURED_EXPECTATIONS"]
    elif documented:
        # External dependencies remain visible in deterministic_entry_refs but
        # do not suppress passage checks over packet-owned documented artifacts.
        return None
    elif external:
        status = "ACCEPTANCE_UNVERIFIED"
        reasons = ["EXTERNAL_DEPENDENCY", "INSTITUTIONAL_ACCEPTANCE_REQUIRED"]
    else:
        reasons = ["DETERMINISTIC_PACKET_GAP"]
    return {
        "requirement_ref": copy.deepcopy(requirement_ref),
        "authority_anchor_ref": _authority_anchor_ref(
            requirement, requirement_ref["requirement_pointer"]
        ),
        "deterministic_entry_refs": [_manifest_entry_ref(row) for row in entries],
        "coverage_check_state": "not_checked",
        "advisory_coverage_status": status,
        "reason_codes": reasons,
        "expectation_findings": [],
    }


def _overlay_applicability_unresolved(manifest: dict[str, Any]) -> bool:
    """Return the sole open-gate unresolved state supported by #681.

    Exact #667 replay guarantees that closed authority/capability states never
    carry requirement entries.  Missing overlay selection is different: base
    entries remain available, but their applicability is not complete enough
    for passage evaluation.
    """

    reasons = manifest["unresolved_reasons"]
    if not reasons:
        return False
    if all(row["code"] == "OVERLAY_SELECTION_NOT_PROVIDED" for row in reasons):
        return True
    _fail(
        "manifest.unresolved_reasons",
        "an open #681 gate permits only unresolved overlay-selection accounting",
    )


def _preflight(
    manifest: dict[str, Any],
    inventory: dict[str, Any],
    packet_root: Path | str,
    context: dict[str, Any],
    registry: dict[str, Any],
    resolved: dict[str, Any],
) -> dict[str, Any]:
    """Replay the deterministic layer and fail before advisory inputs are read."""

    try:
        validate_submission_packet_manifest(
            manifest,
            inventory,
            packet_root,
            context=context,
            registry=registry,
            resolved=resolved,
        )
    except (ContractError, OSError, ValueError, RecursionError, UnicodeError) as exc:
        _fail("manifest replay", str(exc))
    binding = manifest["authority_binding"]
    if (
        binding["state"] != "replay_validated"
        or binding["resolution_state"] != "resolved"
        or not binding["downstream_gate"]["profile_dependent_result_allowed"]
    ):
        _fail(
            "manifest.authority_binding",
            "#681 requires a replay-validated resolved authority context with an open downstream gate",
        )
    if manifest["capability_envelope"]["state"] != "within_v1":
        _fail(
            "manifest.capability_envelope",
            "#681 requires the replay-validated packet to be within the #667 V1 envelope",
        )
    return binding


def finalize_advisory(
    draft: dict[str, Any],
    inventory: dict[str, Any],
    packet_root: Path | str,
    context: dict[str, Any],
    registry: dict[str, Any],
    resolved: dict[str, Any],
    manifest: dict[str, Any],
    session_sources: Mapping[str, str],
) -> dict[str, Any]:
    """Finalize explicit evaluator judgments after exact #667 replay."""

    binding = _preflight(
        manifest, inventory, packet_root, context, registry, resolved
    )
    judgments = _validate_draft(draft)
    applicability_unresolved = _overlay_applicability_unresolved(manifest)
    # Do not inspect supplied content when authority applicability is unresolved.
    # Draft observations are still parsed so any attempt to target such a
    # requirement fails as an explicit ineligible judgment below.
    contents = (
        {}
        if applicability_unresolved
        else _validate_session_contents(session_sources)
    )
    artifacts, observations = _artifact_indexes(inventory, manifest)
    unknown_sources = set(contents) - set(artifacts)
    if unknown_sources:
        _fail("session_contents", f"unknown artifact id(s): {', '.join(sorted(unknown_sources))}")

    entries_by_requirement: dict[str, list[dict[str, Any]]] = {}
    requirement_refs: dict[str, dict[str, Any]] = {}
    for entry in manifest["entries"]:
        requirement_id = entry["requirement_ref"]["requirement_id"]
        previous = requirement_refs.setdefault(requirement_id, entry["requirement_ref"])
        if previous != entry["requirement_ref"]:
            _fail("manifest.entries", f"inconsistent requirement_ref for {requirement_id}")
        entries_by_requirement.setdefault(requirement_id, []).append(entry)

    judgments_by_expectation: dict[tuple[str, str], list[dict[str, Any]]] = {}
    for judgment in judgments:
        judgments_by_expectation.setdefault(
            (judgment["requirement_id"], judgment["expectation_pointer"]), []
        ).append(judgment)

    results: list[dict[str, Any]] = []
    consumed_judgments: set[tuple[str, str]] = set()
    row_counter = [0]
    for requirement_id, entries in entries_by_requirement.items():
        requirement_ref = requirement_refs[requirement_id]
        requirement = _pointer_get(
            registry,
            requirement_ref["requirement_pointer"],
            f"manifest requirement {requirement_id}",
        )
        if not isinstance(requirement, dict) or requirement.get("requirement_id") != requirement_id:
            _fail("manifest.entries", f"requirement pointer mismatch for {requirement_id}")
        if digest(requirement) != requirement_ref["requirement_digest"]:
            _fail("manifest.entries", f"requirement digest mismatch for {requirement_id}")
        ineligible = _ineligible_result(
            requirement_ref,
            requirement,
            entries,
            applicability_unresolved=applicability_unresolved,
        )
        if ineligible is not None:
            results.append(ineligible)
            continue

        allowed_artifacts = {
            artifact_id
            for entry in entries
            if entry["responsibility"] == "packet_owned" and entry["status"] == "DOCUMENTED"
            for artifact_id in entry["matched_artifact_ids"]
        }
        findings: list[dict[str, Any]] = []
        for index, expectation in enumerate(requirement["structured_expectations"]):
            pointer = requirement_ref["requirement_pointer"] + f"/structured_expectations/{index}"
            key = (requirement_id, pointer)
            finding = _finding_from_judgments(
                requirement_ref=requirement_ref,
                expectation=expectation,
                expectation_pointer=pointer,
                judgments=judgments_by_expectation.get(key, []),
                allowed_artifacts=allowed_artifacts,
                artifacts=artifacts,
                observations=observations,
                session_contents=contents,
                row_counter=row_counter,
            )
            consumed_judgments.add(key)
            findings.append(finding)

        if any(row["coverage_check_state"] == "not_checked" for row in findings):
            check_state = "not_checked"
            status = None
            reasons = sorted(
                {
                    reason
                    for row in findings
                    if row["coverage_check_state"] == "not_checked"
                    for reason in row["reason_codes"]
                }
            )
        else:
            check_state = "performed"
            finding_statuses = [row["advisory_coverage_status"] for row in findings]
            if "CONFLICTING" in finding_statuses:
                status = "CONFLICTING"
            elif "NOT_LOCATED" in finding_statuses:
                status = "NOT_LOCATED"
            else:
                status = "DOCUMENTED"
            reasons = [STATUS_REASON[status]]
        results.append(
            {
                "requirement_ref": copy.deepcopy(requirement_ref),
                "authority_anchor_ref": _authority_anchor_ref(
                    requirement, requirement_ref["requirement_pointer"]
                ),
                "deterministic_entry_refs": [_manifest_entry_ref(row) for row in entries],
                "coverage_check_state": check_state,
                "advisory_coverage_status": status,
                "reason_codes": reasons,
                "expectation_findings": findings,
            }
        )

    extra = set(judgments_by_expectation) - consumed_judgments
    if extra:
        formatted = ", ".join(f"{req}:{pointer}" for req, pointer in sorted(extra))
        _fail("draft.judgments", f"targets ineligible or unknown expectations: {formatted}")

    context_pointer = binding["context_pointer"]
    registry_pointer = binding["registry_pointer"]
    report: dict[str, Any] = {
        "schema_version": REPORT_SCHEMA_VERSION,
        "layer": LAYER,
        "evaluation_status": EVALUATION_STATUS,
        "input_binding": {
            "manifest_schema_version": manifest["schema_version"],
            "manifest_digest": manifest["manifest_digest"],
            "inventory_id": manifest["inventory_pointer"]["inventory_id"],
            "inventory_digest": manifest["inventory_pointer"]["inventory_digest"],
            "observation_digest": manifest["packet_pointer"]["observation_digest"],
            "context_record_id": context_pointer["context_record_id"],
            "context_digest": context_pointer["context_digest"],
            "registry_id": registry_pointer["registry_id"],
            "registry_version": registry_pointer["registry_version"],
            "registry_as_of": registry_pointer["as_of"],
            "registry_digest": registry_pointer["registry_digest"],
            "resolved_digest": binding["resolved_digest"],
        },
        "deterministic_status": {
            "review_pathway": manifest["administrative_status"]["review_pathway"],
            "submission_readiness": manifest["administrative_status"]["submission_readiness"],
            "authorization_status": copy.deepcopy(
                manifest["administrative_status"]["authorization_status"]
            ),
            "review_timeline": manifest["administrative_status"]["review_timeline"],
            "acceptance_status": manifest["acceptance_boundary"]["status"],
        },
        "requirement_results": results,
        "excluded_requirements": copy.deepcopy(manifest["excluded_requirements"]),
        "boundary": {
            "deterministic_status_unchanged": True,
            "submission_readiness_unchanged": True,
            "authorization_status_unchanged": True,
            "institutional_acceptance_unchanged": True,
            "adequacy_not_assessed": True,
        },
    }
    report["report_digest"] = digest(report)
    _enforce_advisory_byte_limit(report)
    return report


def validate_advisory(
    advisory: dict[str, Any],
    draft: dict[str, Any],
    inventory: dict[str, Any],
    packet_root: Path | str,
    context: dict[str, Any],
    registry: dict[str, Any],
    resolved: dict[str, Any],
    manifest: dict[str, Any],
    session_sources: Mapping[str, str],
) -> None:
    """Require canonical exact replay from every named input."""

    _preflight(manifest, inventory, packet_root, context, registry, resolved)
    _enforce_advisory_byte_limit(advisory)
    expected = finalize_advisory(
        draft,
        inventory,
        packet_root,
        context,
        registry,
        resolved,
        manifest,
        session_sources,
    )
    if _canonical_bytes(advisory) != _canonical_bytes(expected):
        _fail("report", "does not exactly match deterministic replay from named inputs")


def _md(value: Any) -> str:
    if value is None:
        return "not checked"
    return "".join(
        f"&#{ord(character)};"
        if (
            character.isascii()
            and not character.isalnum()
            and not character.isspace()
        )
        or unicodedata.category(character) in {"Cc", "Cf", "Zl", "Zp"}
        else character
        for character in str(value)
    )


def render_advisory(
    advisory: dict[str, Any],
    draft: dict[str, Any],
    inventory: dict[str, Any],
    packet_root: Path | str,
    context: dict[str, Any],
    registry: dict[str, Any],
    resolved: dict[str, Any],
    manifest: dict[str, Any],
    session_sources: Mapping[str, str],
    *,
    page: int = 1,
    page_size: int = 25,
) -> str:
    """Replay and render the final advisory plus replay-bound evidence pages."""

    validate_advisory(
        advisory,
        draft,
        inventory,
        packet_root,
        context,
        registry,
        resolved,
        manifest,
        session_sources,
    )
    if isinstance(page, bool) or not isinstance(page, int) or page < 1:
        _fail("page", "must be a positive integer")
    if (
        isinstance(page_size, bool)
        or not isinstance(page_size, int)
        or page_size < 1
        or page_size > MAX_RENDER_PAGE_SIZE
    ):
        _fail("page_size", f"must be an integer from 1 through {MAX_RENDER_PAGE_SIZE}")
    deterministic = advisory["deterministic_status"]
    authorization = deterministic["authorization_status"]
    lines = [
        "# LLM-ADVISORY Content-Coverage Advisory",
        "",
        "Evaluation status: UNMEASURED",
        "",
        "This advisory records bounded passage observations only. It does not assess adequacy or alter deterministic packet status, submission readiness, authorization, or institutional acceptance.",
        "",
        "## Deterministic Status — Copied Unchanged",
        "",
        f"Review pathway: {deterministic['review_pathway']}",
        f"Submission readiness: {deterministic['submission_readiness']}",
        f"Authorization status: {authorization['value']}",
        f"Review timeline: {deterministic['review_timeline']}",
        f"Authorization source reference: {_md(authorization['source_reference'])}",
        f"Authorization provenance: {_md(authorization['provenance'])}",
        f"Institutional acceptance: {deterministic['acceptance_status']}",
        "",
        "## Requirement Results",
        "",
        "| Requirement | Authority source | Provision | Effective date | Anchor pointer | Anchor digest | Authority URL | Check state | LLM-ADVISORY coverage status | Reasons | Expectations |",
        "|---|---|---|---|---|---|---|---|---|---|---|",
    ]
    if advisory["requirement_results"]:
        for result in advisory["requirement_results"]:
            lines.append(
                "| "
                + " | ".join(
                    _md(value)
                    for value in (
                        result["requirement_ref"]["requirement_id"],
                        result["authority_anchor_ref"]["source_id"],
                        result["authority_anchor_ref"]["provision"],
                        result["authority_anchor_ref"]["effective_date"],
                        result["authority_anchor_ref"]["authority_anchor_pointer"],
                        result["authority_anchor_ref"]["authority_anchor_digest"],
                        result["authority_anchor_ref"]["authority_url"],
                        result["coverage_check_state"],
                        result["advisory_coverage_status"],
                        ", ".join(result["reason_codes"]),
                        len(result["expectation_findings"]),
                    )
                )
                + " |"
            )
    else:
        lines.append(
            "| none | none | none | none | none | none | none | none | none | "
            "no applicable advisory requirement results | 0 |"
        )

    lines.extend(
        [
            "",
            "## Excluded Requirements",
            "",
            "| Requirement | Requirement pointer | Applicability | Exclusion basis |",
            "|---|---|---|---|",
        ]
    )
    if advisory["excluded_requirements"]:
        for excluded in advisory["excluded_requirements"]:
            lines.append(
                "| "
                + " | ".join(
                    _md(value)
                    for value in (
                        excluded["requirement_ref"]["requirement_id"],
                        excluded["requirement_ref"]["requirement_pointer"],
                        excluded["requirement_ref"]["applicability"],
                        excluded["exclusion_basis"],
                    )
                )
                + " |"
            )
    else:
        lines.append("| none | none | none | none |")

    all_rows = [
        row
        for result in advisory["requirement_results"]
        for finding in result["expectation_findings"]
        for row in finding["evidence_rows"]
    ]
    if all_rows:
        lines.extend(["", "## Bounded Evidence Rows", ""])
        lines.append(
            render_evidence_rows_markdown(
                all_rows,
                page=page,
                page_size=page_size,
                session_sources=session_sources,
            ).rstrip("\n")
        )
        lines.append("")
    elif page != 1:
        _fail("page", "cannot exceed page 1 when no evidence rows exist")
    lines.extend(
        [
            "> **Human-subjects boundary:** This output does not authorize recruitment, consent, access to identifiable data, intervention, or data collection.",
            "",
        ]
    )
    return "\n".join(lines)


def _session_map(path: Path) -> dict[str, str]:
    try:
        value = load_json(path)
    except (ContractError, OSError, ValueError, RecursionError, UnicodeError) as exc:
        raise ContentCoverageAdvisoryInputError(str(exc)) from exc
    try:
        return _validate_session_contents(value)
    except ContentCoverageAdvisoryError as exc:
        raise ContentCoverageAdvisoryInputError(str(exc)) from exc


def _emit(text: str, output: Path | None) -> None:
    if output is None:
        sys.stdout.write(text)
    else:
        output.write_text(text, encoding="utf-8")


def _parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(description=__doc__, allow_abbrev=False)
    subparsers = parser.add_subparsers(dest="command", required=True)
    for name in ("build", "validate", "render"):
        command = subparsers.add_parser(name, allow_abbrev=False)
        command.add_argument("--draft", type=Path, required=True)
        command.add_argument("--manifest", type=Path, required=True)
        command.add_argument("--inventory", type=Path, required=True)
        command.add_argument("--packet-root", type=Path, required=True)
        command.add_argument("--context", type=Path, required=True)
        command.add_argument("--registry", type=Path, required=True)
        command.add_argument("--resolved", type=Path, required=True)
        command.add_argument("--source-map", type=Path, required=True)
        if name in {"validate", "render"}:
            command.add_argument("--advisory", type=Path, required=True)
        if name in {"build", "render"}:
            command.add_argument("--output", type=Path)
        if name == "render":
            command.add_argument("--page", type=int, default=1)
            command.add_argument("--page-size", type=int, default=25)
    return parser


def main(argv: list[str] | None = None) -> int:
    args = _parser().parse_args(argv)
    try:
        manifest = load_json(args.manifest)
        inventory = load_json(args.inventory)
        context = load_json(args.context)
        registry = load_json(args.registry)
        resolved = load_json(args.resolved)
        # The deterministic replay/gates precede even opening advisory draft or
        # session-content paths.  A closed gate cannot be turned into an input
        # read oracle by naming an unavailable --source-map.
        _preflight(
            manifest,
            inventory,
            args.packet_root,
            context,
            registry,
            resolved,
        )
        draft = load_json(args.draft)
        # Overlay selection may remain explicitly unprovided while the base
        # authority gate is open.  In that state #681 reports applicability as
        # unresolved and must not even open the named content map.
        session_sources = (
            {}
            if _overlay_applicability_unresolved(manifest)
            else _session_map(args.source_map)
        )
        if args.command == "build":
            advisory = finalize_advisory(
                draft,
                inventory,
                args.packet_root,
                context,
                registry,
                resolved,
                manifest,
                session_sources,
            )
            # Do not append a transport newline: an exactly 8 MiB canonical
            # carrier must remain loadable through the shared 8 MiB JSON cap.
            _emit(_canonical_bytes(advisory).decode("utf-8"), args.output)
            return 0
        advisory = load_json(args.advisory)
        validate_advisory(
            advisory,
            draft,
            inventory,
            args.packet_root,
            context,
            registry,
            resolved,
            manifest,
            session_sources,
        )
        if args.command == "validate":
            print("Content-coverage advisory validation passed (#681).")
            return 0
        _emit(
            render_advisory(
                advisory,
                draft,
                inventory,
                args.packet_root,
                context,
                registry,
                resolved,
                manifest,
                session_sources,
                page=args.page,
                page_size=args.page_size,
            ),
            args.output,
        )
        return 0
    except ContentCoverageAdvisoryInputError as exc:
        print(f"ERROR: {exc}", file=sys.stderr)
        return 2
    except (
        ContentCoverageAdvisoryError,
        ContractError,
        EvidenceRowError,
        OSError,
        ValueError,
        RecursionError,
        UnicodeError,
    ) as exc:
        print(f"ERROR: {exc}", file=sys.stderr)
        return 2


__all__ = [
    "ContentCoverageAdvisoryError",
    "ContentCoverageAdvisoryInputError",
    "DRAFT_SCHEMA_VERSION",
    "EVALUATION_STATUS",
    "LAYER",
    "REPORT_SCHEMA_VERSION",
    "finalize_advisory",
    "main",
    "render_advisory",
    "validate_advisory",
]


if __name__ == "__main__":
    raise SystemExit(main())
add-product-e2e-evalpaperclipai/paperclipAdd or extend a Paperclip full-stack runner E2E workflow, fixture, matcher, or report evidence path for local or Daytona execution.Stars: 115kUpdated Claude CodeCodexVerifiedInstall
add-runner-evalpaperclipai/paperclipAdd or extend a Paperclip Runner protocol evaluation definition, roster, assertion, or report fixture with provenance and narrow validation.Stars: 115kUpdated Claude CodeCodexVerifiedInstall
diagnose-why-work-stoppedpaperclipai/paperclipCompatibility entry point for failed, stalled, looping, or over-recovered Paperclip work. Use fix-failed-paperclip-run for the full diagnosis, regression, repair, real verification, and green-PR workflow; honor an explicitly requested diagnosis-only scope.Stars: 115kUpdated Claude CodeCodexVerifiedInstall
fix-failed-paperclip-runpaperclipai/paperclipDiagnose and fix failed, stuck, slow, or incorrectly blocked Paperclip tasks and runs. Use with a task/run URL or failure report to trace the root cause, prove a regression red then green, check second-order effects, verify the real workflow, and deliver a PR with passing checks.Stars: 115kUpdated Claude CodeCodexVerifiedInstall