Skip to content

zrwangems/dsh-zrwang-plugin / ars/skills/academic-paper-reviewer

academic-paper-reviewer

Flagged

模拟同行评审:期刊匹配审稿人 + 3 位动态领域审稿人 + 魔鬼代言人,输出编辑决定(接收/小修/大修/拒稿)与返修路线图,可做方法论专项评审与再审核验。Triggers: review paper, peer review, manuscript review, check methodology, re-review | 审稿, 同行评审, 评审论文, 检查方法, 复审。只做评审,不改写稿件。

FileKindSize
SKILL.mdskill md48.9 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.0 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/devils_advocate_reviewer_agent.mdmarkdown42.6 KB
agents/domain_reviewer_agent.mdmarkdown34.0 KB
agents/editorial_synthesizer_agent.mdmarkdown42.4 KB
agents/eic_agent.mdmarkdown28.8 KB
agents/field_analyst_agent.mdmarkdown11.9 KB
agents/methodology_reviewer_agent.mdmarkdown44.6 KB
agents/perspective_reviewer_agent.mdmarkdown34.3 KB
examples/hei_paper_review_example.mdmarkdown33.8 KB
examples/interdisciplinary_review_example.mdmarkdown27.6 KB
examples/subclaim_decomposition_example.mdmarkdown8.3 KB
references/calibration_mode_protocol.mdmarkdown16.1 KB
references/changelog.mdmarkdown2.0 KB
references/editorial_decision_standards.mdmarkdown13.5 KB
references/guided_mode_protocol.mdmarkdown2.6 KB
references/integration_guide.mdmarkdown1.3 KB
references/quality_rubrics.mdmarkdown6.9 KB
references/re_review_mode_protocol.mdmarkdown52.6 KB
references/review_criteria_framework.mdmarkdown6.8 KB
references/review_panel_provenance_protocol.mdmarkdown10.1 KB
references/review_quality_thinking.mdmarkdown3.9 KB
references/reviewer_sprint_prompt_source.mdmarkdown48.5 KB
references/sprint_contract_protocol.mdmarkdown32.7 KB
references/statistical_reporting_standards.mdmarkdown30.4 KB
references/top_journals_by_field.mdmarkdown13.2 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/_text_similarity.pyscript16.0 KB
scripts/ars_cache_invalidate.pyscript1.3 KB
scripts/ars_mark_read.pyscript18.2 KB
scripts/ars_write_scope_guard.pyscript30.9 KB
scripts/arxiv_client.pyscript9.4 KB
scripts/audit_panel_claims.pyscript17.3 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/_text_similarity.py

View on GitHub
#!/usr/bin/env python3
"""Shared title-similarity + retry-budget helpers for the v3.9.0 cross-index
triangulation clients.

Previously triple-implemented byte-equivalently in
`semantic_scholar_client.py`, `openalex_client.py`, and `crossref_client.py`.
Extracted in #128 (v3.9.1 housekeeping) to prevent sibling drift — any
threshold tuning or normalization rule change now happens in one place.

`_normalize_title` / `_similarity` stay byte-equivalent with the v3.7.3 /
v3.9.0 client implementations for every NON-dotted-acronym title; #431 §0.1
adds a dotted-acronym pre-pass that can only *raise* `_similarity` (taken via
`max`), plus the `exact_normalized_title` / `generic_title` identity helpers the
exact-title-or-bust gate (§0.12) reads. See `test_text_similarity.py` for the
similarity contract and `test_431_exact_or_bust.py` for the gate behavior.
"""
from __future__ import annotations

import re
import string
from difflib import SequenceMatcher


_PUNCT_TRANSLATION = str.maketrans({c: " " for c in string.punctuation})

# #431 §0.1: collapse a run of two-or-more `<letter>.` units at a word boundary
# (`R.A.G.` → `RAG`) BEFORE punctuation→whitespace, so a dotted acronym and its
# undotted spelling normalize byte-equal. `/`, `&`, and spaced initials
# (`D. H.`) are NOT dotted runs and stay untouched (`A/B`, `R&D`, `Q&A`).
_DOTTED_ACRONYM = re.compile(r"\b(?:[A-Za-z]\.){2,}")


# Per protocol: shared retry budget for the index clients. S2 / Crossref
# sleep a fixed _BACKOFF_SECONDS per 429; OpenAlex uses it as the base of
# an exponential backoff (2s → 4s → 8s, #495); arXiv does not use it — its
# 429 backoff is the 3s ToU pacing floor (_ARXIV_MIN_INTERVAL, #495).
_BACKOFF_SECONDS = 2.0
_MAX_RETRIES = 3


# Per PaperOrchestra (Song et al. 2026 Appx D.3) + protocol §"Query Patterns"
# Pattern 1: title-similarity threshold for "matched" verdict.
_TITLE_SIMILARITY_THRESHOLD = 0.70


def _normalize_title(s: str) -> str:
    """Per protocol §"Query Patterns" Pattern 1: 'case-insensitive, stripped
    of punctuation' before computing similarity. Punctuation becomes
    whitespace so token boundaries are preserved, then collapse runs of
    whitespace. The byte-equivalent base form for every non-dotted title."""
    cleaned = s.lower().translate(_PUNCT_TRANSLATION)
    return " ".join(cleaned.split())


def _normalize_title_acronym(s: str) -> str:
    """#431 §0.1: base normalization plus the dotted-acronym pre-pass. The
    dots inside a `<letter>.`-run span are stripped first (`R.A.G.` → `RAG`),
    then the base path runs. Provably additive over the dotted form only — any
    title with no dotted run normalizes identically to `_normalize_title`.

    This is the form `exact_normalized_title` compares on: under #431's
    exact-title-or-bust gate the equality (not the ratio) is load-bearing, so a
    legitimate `R.A.G.`/`RAG` acronym variant must reach byte-equality here. The
    base form alone leaves them 'r a g …' ≠ 'rag …' — a high ratio but NOT
    equal, which under the gate would wrongly fall to `unresolvable`."""
    collapsed = _DOTTED_ACRONYM.sub(lambda m: m.group(0).replace(".", ""), s)
    return _normalize_title(collapsed)


# CJK Unified Ideographs (U+4E00-U+9FFF). Extension blocks are deliberately not
# scanned: the base block is sufficient for the applicability gate, and a
# narrower gate errs toward the pre-repair behavior, which is the safe
# direction. Fullwidth Latin (U+FF01-U+FF5E) is deliberately NOT in this range
# either: a title of only fullwidth Latin is not a Chinese title and must not
# enter the CJK comparison path.
_CJK_LO = "一"
_CJK_HI = "鿿"

_CN_WRAPPERS = {
    ("《", "》"), ("「", "」"), ("『", "』"), ("【", "】"),
    ("“", "”"), ("‘", "’"),
}


def _outer_pair_encloses(text: str) -> bool:
    """#800: True iff `text` starts and ends with marks that form ONE matching
    wrapper pair AND the interior is balanced *within that pair's own family* —
    i.e. the outer pair encloses the whole title as a single unit.

    A first/last-character pair check alone is not enough: in
    `《红楼梦》与《金瓶梅》` the leading `《` and trailing `》` match as
    *character types* but belong to two different bracket pairs, and stripping
    them positionally leaves an orphaned `》` mid-string. Scanning the interior
    for an unbalanced `》` catches exactly that case, so such titles keep their
    marks. An empty interior counts as balanced, preserving the `《》` → ""
    normalization.

    The scan is deliberately scoped to the outer pair's OWN family (#804 review
    P1). A family-blind scan is unsound because two of these marks are not
    exclusively wrappers: `’` is also the English apostrophe and `”` also
    appears unpaired in mixed typesetting. Reading the lone `’` in
    `《Alzheimer’s病中ProEXC表达》` as an unbalanced quote refused to strip
    a genuine `《…》` wrap, dropping a pair that matched on main to exact=False
    and ratio 0.6818 — below the 0.70 floor, so both resolver paths failed at
    once and a correct DOI could be reported as a mismatch. That is the failure
    class #798 repaired, so the apostrophe must be invisible to a `《》` scan.

    Scoping costs nothing the check was buying: every mark that can orphan the
    OUTER pair is by definition a mark of that pair's own family. Interior marks
    of other families are content and survive the strip — `《「研究』》` →
    `「研究』` keeps the mismatched inner quotes, which is right, since they are
    what distinguishes it from `《研究》`."""
    if len(text) < 2 or (text[0], text[-1]) not in _CN_WRAPPERS:
        return False
    opener, closer = text[0], text[-1]
    depth = 0
    for ch in text[1:-1]:
        if ch == opener:
            depth += 1
        elif ch == closer:
            if depth == 0:  # closes the OUTER opener: not one unit
                return False
            depth -= 1
    return depth == 0
# The fullwidth-ASCII fold maps `.` to `.` first. `?`/`?` are kept: they can
# distinguish an interrogative title from an otherwise identical one.
_CN_TERMINAL_MARKS = "。."
_CN_HAN_ADJACENT_SPACE = re.compile(rf"(?<=[{_CJK_LO}-{_CJK_HI}]) +| +(?=[{_CJK_LO}-{_CJK_HI}])")


def has_cjk(text: str | None) -> bool:
    """True iff the string contains a CJK Unified Ideograph."""
    return any(_CJK_LO <= ch <= _CJK_HI for ch in text or "")


def normalize_cn_title(title: str | None) -> str:
    """Chinese-aware title normalization (#431 CJK repair).

    The base `_normalize_title` is ASCII-centric and, measured on real ISTIC
    metadata 2026-07-27, rejects four legitimate variants of one identical
    Chinese title:

      - fullwidth latin/digits (ProEXC vs ProEXC): `.lower()` folds case
        but never width, so U+FF30 never reaches U+0050 (measured similarity
        0.625, exact=False)
      - a trailing CJK full stop (。) and outer wrappers (《》): not members of
        `string.punctuation`, so the base form keeps them (0.970, False)
      - spaces touching Han characters: Chinese carries no word breaks, so these
        are typesetting noise; whitespace between non-CJK tokens stays
        significant (0.941, False)
      - the ideographic space U+3000, likewise absent from `string.punctuation`

    Simplified/Traditional folding is deliberately NOT done: it is lossy for
    proper nouns, and a wrong fold would manufacture a false match. The pair is
    surfaced to the human instead.

    Outer wrappers are stripped only when they enclose the whole title as one
    balanced unit (#800): `《围城》` loses its marks, but
    `《红楼梦》与《金瓶梅》` keeps them, because its first and last marks belong
    to two different bracket pairs and stripping them positionally would leave
    an orphaned `》` mid-string.

    Promoted here from `chinese_literature_client.py`, which re-imports it
    rather than keeping a second copy (#128 anti-drift). The promotion itself
    (#798/#799) was behaviorally equivalent — it only hoisted the wrapper and
    terminal-mark sets to module constants, precompiled the Han-adjacent-space
    regex, and rewrote the comments. That equivalence is now **historical**:
    #800 deliberately changed the wrapper-strip behavior described above, so
    this function no longer matches the pre-#800 implementation. What the tests
    pin today is the #800 behavior on the CJK path plus — through the pre-fix
    oracles in `test_text_similarity.py` — every non-CJK verdict and ratio.
    """
    # Fold only the fullwidth ASCII compatibility block that was observed in the
    # motivating metadata. Whole-string NFKC/casefold is too broad for an exact
    # scientific-title key: it collapses e.g. 2² with 22 and Straße with
    # Strasse. U+3000 is the fullwidth/ideographic space and is removed below.
    text = "".join(
        chr(ord(ch) - 0xFEE0) if "!" <= ch <= "~" else " " if ch == " " else ch
        for ch in (title or "")
    ).strip()

    # Only remove wrappers and terminal marks that are demonstrated typesetting
    # noise. Scientific operators and measurements remain byte-significant:
    # ER+ != ER-, CD4+ != CD4−, and 4.5% != 45%. In particular, do not return to
    # a Unicode-category-wide P*/S* deletion rule.
    while text:
        previous = text
        text = text.rstrip(_CN_TERMINAL_MARKS).strip()
        # #800: strip the outer wrapper only when it genuinely encloses the
        # whole title as one balanced unit — not merely when the first and last
        # characters happen to match as pair types.
        if _outer_pair_encloses(text):
            text = text[1:-1].strip()
        if text == previous:
            break

    # Whitespace touching a Han character is ordinary Chinese typesetting noise,
    # including spaces around an embedded Latin abbreviation. Preserve
    # whitespace *between* non-CJK tokens, where deleting it can collapse
    # scientifically distinct names (for example `PD L1` versus `PDL 1`). Case is
    # likewise retained: gene/protein symbols can be case-sensitive.
    text = re.sub(r"\s+", " ", text).strip()
    return _CN_HAN_ADJACENT_SPACE.sub("", text)


def _cjk_titles_match(a: str, b: str) -> bool:
    """Exact equality after Chinese-aware normalization, for two titles that
    BOTH carry a Han ideograph.

    The fuzzy ratio is excluded from this rule in both directions. It is not
    *sufficient*: Han characters give unrelated papers a high baseline overlap
    (two genuinely different cervical-cancer papers measured 0.510). And it is
    not safe as an extra *necessary* condition either — the fullwidth spelling
    of an identical title measured 0.625, below the 0.70 floor, so ANDing the
    ratio in would veto a match exact normalization had correctly established
    and file a real paper at P0 next to the word "fabricated".

    An empty normalized key never matches, mirroring `_cn_titles_match`'s
    non-empty guard: `《》` and `「」` both normalize to "" and are not the
    same work.
    """
    if not (has_cjk(a) and has_cjk(b)):
        return False
    left, right = normalize_cn_title(a), normalize_cn_title(b)
    return bool(left) and left == right


def _similarity(a: str, b: str) -> float:
    """`max` over the base and dotted-acronym normalizations (#431 §0.1,
    F4 non-destructive): the acronym pre-pass can only ever *raise* the score,
    so `D. H.` vs `D. H.` stays 1.000 (it would be 0.981 if the acronym form
    replaced the base form). For non-dotted titles both forms are byte-equal, so
    the second pass is skipped and the result is the pre-#431 single-form ratio."""
    a_base, b_base = _normalize_title(a), _normalize_title(b)
    base = SequenceMatcher(None, a_base, b_base).ratio()
    # CJK repair: the DOI-keyed cross-check in every resolver gates on this
    # ratio ALONE, and a legitimate fullwidth spelling of an identical Chinese
    # title measures 0.625 — under the 0.70 floor — turning a correct DOI into
    # DOI_MISMATCH. Folded in via `max` (same F4 non-destructive shape as the
    # acronym pre-pass), so this can only ever raise a score, never lower one.
    if _cjk_titles_match(a, b):
        return 1.0
    a_acr, b_acr = _normalize_title_acronym(a), _normalize_title_acronym(b)
    if a_acr == a_base and b_acr == b_base:  # no dotted run in either title
        return base
    return max(base, SequenceMatcher(None, a_acr, b_acr).ratio())


def exact_normalized_title(a: str, b: str) -> bool:
    """#431 §0.12.1: the one identity signal all four resolvers can compute.
    True iff the two titles are byte-equal under EITHER the base normalization
    OR the dotted-acronym-aware one. Both forms are checked (mirroring
    `_similarity`'s `max`, F4 non-destructive): the acronym pre-pass must only
    ever *add* matches, never drop one the base form already had. Checking only
    the acronym form would regress a punctuation-only variant where exactly one
    side is a contiguous initialism — `D.H. Lawrence` vs `D. H. Lawrence`
    normalizes byte-equal under the base form (`d h lawrence`) but NOT under the
    acronym form (`dh` vs `d h`), and would wrongly fall to `unresolvable`.
    Legitimate punctuation / case / subtitle-spacing / `R.A.G.`→`RAG` acronym
    variants all match here; a distinct related work (different subtitle, Part I
    vs Part II, a correction-notice prefix) matches under neither and stays
    `unresolvable` rather than a false `matched`."""
    return (
        _normalize_title(a) == _normalize_title(b)
        or _normalize_title_acronym(a) == _normalize_title_acronym(b)
        # CJK repair: additive third form, gated on BOTH sides carrying a Han
        # ideograph. A Latin-only or romanized shadow title is never comparable
        # this way — there is no translation oracle here, so a cross-script
        # difference must stay a non-match rather than become evidence.
        or _cjk_titles_match(a, b)
    )


# #431 §0.12.2: the closed generic/section/type/notice set. `generic_title` is
# EXACT set-membership on the normalized title — NOT substring or endswith. A
# content title that merely begins with or contains a type word (`Case Report of
# a Rare Tumor`, `A Comprehensive Review`) has a normalized form ≠ the bare type
# word, so it is NOT generic and is not demoted. This list is the single source
# of truth (spec §0.12.2); the regression fixture pins `Short Communication` /
# `Editorial Comment` / `Case Report` / `Publisher Correction` (exact title + no
# ID) → `unresolvable`.
_GENERIC_TITLES = frozenset(
    _normalize_title(t)
    for t in (
        "editorial", "guest editorial", "editorial comment", "introduction",
        "preface", "foreword", "letter", "letters", "letter to the editor",
        "letters to the editor", "reply", "comment", "commentary", "response",
        "correspondence", "book review", "book reviews", "review", "news",
        "obituary", "in memoriam", "acknowledgements", "front matter",
        "back matter", "table of contents", "abstracts", "abstract",
        "proceedings", "keynote", "panel discussion", "workshop summary",
        "special issue", "untitled", "note", "notes", "highlights", "errata",
        "erratum", "corrigendum", "addendum", "author correction",
        "publisher correction", "retraction", "expression of concern",
        "short communication", "rapid communication", "brief communication",
        "short report", "brief report", "technical report", "meeting report",
        "conference report", "case report", "case study", "research article",
        "original article", "original research", "short paper", "perspective",
        "perspectives", "viewpoint", "opinion", "discussion", "summary",
        "conclusion", "conclusions", "abstract only", "supplementary material",
    )
)


def generic_title(title: str) -> bool:
    """#431 §0.12.2: True iff the normalized title is byte-equal to a member of
    the closed generic set. Under the exact-or-bust gate an exact title match
    that is *also* generic accepts only when an ID/DOI corroborates; otherwise
    it is `unresolvable` (a bare `Editorial` collides across thousands of
    distinct works)."""
    return _normalize_title(title) in _GENERIC_TITLES
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