refactor(rag): extract evidence-gate predicates into rag-evidence-gates (maturity X3)#997
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughRAG evidence-gating predicates were extracted from ChangesRAG evidence gate refactor
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
…es (maturity X3) First step of the rag.ts monolith decomposition (X3), enabled by X2's src/lib/rag/ directory. Moves 14 pure query/evidence gate predicates — the document-alias / admission title-support checks and the dose/route/frequency/risk-flowchart/source-image evidence gates — into a new src/lib/rag/rag-evidence-gates.ts. Behaviour-preserving: the function bodies are byte-identical to their previous rag.ts definitions. rag.ts imports the 13 it still calls (normalizeDocumentAliasText stays module-internal, used only by the alias helpers) and drops the sibling imports those predicates alone consumed. Ratchets the rag.ts maintainability budget 5238 -> 5030 to lock in the reduction (now 5018 lines), directly addressing the audit's "caps but never reduces" note. Verified: typecheck, lint (0 warnings), full test suite (3012 pass; the only failure is the pre-existing container-only pdf-extraction-budget flake, unrelated to rag), maintainability budgets, docs index/links, and prettier all green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Jc1ZYHFjXjn6mE6U6riVU
7b72d17 to
88cd591
Compare
Summary
Phase 5 / maturity X3: the first real decomposition of the
rag.tsmonolith, enabled by X2'ssrc/lib/rag/directory (#994, now merged).rag.tsinto a newsrc/lib/rag/rag-evidence-gates.ts: the document-alias / admission title-support checks (hasDocumentAliasWithoutTopTitleSupport,hasAdmissionCommunityLookupIntent,hasAdmissionCommunityTitleSupport,directTitleOrAliasSupport, and the internalnormalizeDocumentAliasText) and the evidence-sufficiency gates (topEvidenceText,hasAnyTerm,isRiskFlowchartNextStepQuery,hasRiskFlowchartActionEvidence,hasDoseAmountEvidenceForGate,hasRouteEvidenceForGate,hasFrequencyEvidenceForGate,hasDirectSourceImageEvidence,sourceImageRequiredForQuery).rag.tsdefinitions.rag.tsimports the 13 it still calls (normalizeDocumentAliasTextstays module-internal — used only by the alias helpers) and drops the four sibling imports those predicates alone consumed.rag.tsmaintainability budget 5238 → 5030 to lock in the reduction (now 5018 lines), directly addressing the audit's "budget caps but never reduces" note.shouldReturnBeforeMemorydeliberately stayed inrag.ts(it depends on the later-definedshouldUseMemoryBeforeFastPath), keeping the extraction a clean closure with no forward references.Diff: 3 files —
+rag-evidence-gates.ts(154),rag.ts(−146/+15), budget (±1). Rebased ontomainafter #994 landed (the interim stacked base is gone); the diff is now purely the X3 extraction.Verification
Full local gate on the rebased branch (on top of current
main), all green:npm run typecheck— pass.npm run test— 3017 pass; the only failure is the pre-existing container-onlypdf-extraction-budgetflake (a Python child-tree kill-timing assertion, no rag dependency), which refactor(rag): extract the rag cluster into src/lib/rag/ (maturity X2) #994 already proved fails identically on cleanorigin/main— X3's diff touches only rag + the budget script, so it cannot affect it.npm run lint— pass (0 warnings; removed the now-unused imports).npm run check:maintainability-budgets— pass (src/lib/rag/rag.ts5018/5030);npm run check:github-actions— pass.npm run docs:check-index— pass;npm run docs:check-links— pass (989 refs);npm run format:check— pass.Risk and rollout
Clinical Governance Preflight
Behaviour-preserving relocation of pure predicate helpers; no clinical behaviour, data flow, or configuration changed. Each item holds by construction:
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
Next X3 increments (separate PRs) can peel further cohesive clusters off
rag.ts(e.g. the answer-JSON schema + section-sanitization group, or the classifier-verdict memo cluster). A separate docs pass is also queued to re-verify the now-stalefile:linecitations inclinical-hazard-analysis.md/rag-injection-threat-model.md, which reference a bygone ~7,000-linerag.ts.Generated by Claude Code
Summary by CodeRabbit