Skip to content

refactor(PR0–PR1): API contract freeze + CI, shared helpers + _keys adoption - #30

Merged
nceglia merged 6 commits into
mainfrom
refactor/pr0-contract-freeze
Jul 12, 2026
Merged

refactor(PR0–PR1): API contract freeze + CI, shared helpers + _keys adoption#30
nceglia merged 6 commits into
mainfrom
refactor/pr0-contract-freeze

Conversation

@nceglia

@nceglia nceglia commented Jul 12, 2026

Copy link
Copy Markdown
Owner

First two PRs of the tcri → scverse-package refactor. No behavior change — additive scaffolding + internal dedup. Full suite: 35 passed / 1 skipped.

PR0 — Contract freeze + CI scaffolding

  • tcri/_contract.pyi — frozen target public surface (27 functions, namespaced tl/pp/pl/diag/ut + TCRIModel; locked decisions baked in: n_samples=250, weighted=False, use_logits, normalize_mode, American spelling, keyword-only).
  • tests/test_contract_conformance.py — live-signature-vs-contract guard (for anything in IMPLEMENTED, empty today), an unimplemented worklist, import-smoke, and an AST-based canonical-key-literal guard.

PR1 — Shared helpers + _keys adoption

  • New shared modules: _keys.py (all uns/obsm/obs key constants), _console.py (single console helpers), _stats.py (true HDI/ETI, prob_direction, + relocated stars/auc/bootstrap), _distance.py (kl/js/l1 + dispatch). tests/test_helpers.py (8 tests).
  • Removals/dedup: deleted the 12 copied console helper defs → one _console; moved stats out of utils; migrated 85 canonical key literals → K.*; dropped dead utils imports.
  • Caught & fixed an hdi off-by-one before it shipped.

Audit

A 3-lens multi-agent audit (doc-vs-code · correctness · plan/contract) ran on this branch and caught a real regression — the key migration over-reached into 10 display/warning/docstring strings (register_model/load_tcri_session printed "K.X_LOGITS" etc.). Fixed in this branch: readable key text restored in all 10, and the key-literal guard made AST-based (checks real code, ignores prose).

Two non-blocking follow-ups deferred (tracked in docs/contract/REFACTOR_NOTES.md, pre-Phase-6):

  1. Reconcile _contract.pyi ↔ api-doc §7–§9 — the contract already carries the consistency/sufficiency decisions; the api-doc lags. Not CI-enforced yet (IMPLEMENTED={}).
  2. Canonicalize new helper names/shapes before Phase 6 (jensen_shannon/js_divergence, prob_direction/prob_gt_zero, hdi(prob=)/hdi_prob=, phenotype_distance shape).

Planning/spec docs live under docs/contract/ (excluded from the Sphinx build). The living agenda + removal ledger is docs/contract/REFACTOR_AGENDA.md.

🤖 Generated with Claude Code

nceglia and others added 6 commits June 8, 2026 00:26
Full NumPy-style docstrings (summary, parameters, returns with shapes/units,
math definitions, examples) for the core analysis API in tcri.metrics:
clonotypic_entropy, phenotypic_entropy, clonality, mutual_information, flux.
These flow into the D11 autodoc reference and mirror the D2 concepts page.

Docstring-only (no behavior change); docs build clean (0 warnings); math and
cross-references render.

Part of Notion D1 (public API docstrings). Remaining chunks: preprocessing
(register_model, joint_distribution*), model (TCRIModel), then plotting/utils.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Living refactor spec, PR agenda/diary with removal ledger, and hard rules.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…pers

PR0: tcri/_contract.pyi (frozen target surface) + test_contract_conformance.
PR1 foundation: _keys/_console/_stats/_distance + unit tests (true HDI/ETI,
kl/js/l1 dispatch). No behavior change; all additive.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Remove 12 copied _ok/_info/_warn/_fin defs across metrics/preprocessing/
plotting; relocate stars/auc_and_label_permutation/bootstrap_auc utils->_stats.
No behavior change; full suite 34 passed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Migrate 85 canonical uns/obsm/obs key literals -> K.* in preprocessing/metrics/
plotting/utils; add test_no_canonical_key_literals guard. Legacy keys left for
their removal phases. No behavior change; full suite 35 passed / 1 skipped.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…based guard

Multi-agent audit caught the K.* migration over-reaching into 10 display/
warning/docstring strings (printed code tokens instead of key names). Restore
readable key text in all 10; make the key-literal guard AST-based (checks real
subscripts/.get, ignores prose); drop 3 dead utils imports. Suite 35 passed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@nceglia
nceglia merged commit 725d379 into main Jul 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant