rag.ts decomposition — part 1: quote verification, source block, numeric verification, context selection - #341
Merged
Merged
Conversation
…ation.ts (move-only) Move 1 of the rag.ts decomposition. The 7-function family (normalizeQuoteVerificationText, tableFactQuoteText, sourceTextForQuoteVerification, isExactSourceQuote, sanitizeQuoteCards, sanitizeConflictsOrGaps, enrichGroundedReviewCitations) moved verbatim. Four tiny shared helpers re-homed to their domain siblings so the new module stays cycle-free: allowedChunkMap -> citations.ts, safeRecord -> rag-answer-text.ts, appendRoutingReason -> rag-routing.ts, and rag.ts's resultCitation was an exact duplicate of citations.citationFromResult so it now imports that under the old alias. rag.ts 7,874 -> 7,740 lines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPVNBVo4cg9PEYtNhJZBQY
…ve-only) Move 2 of the rag.ts decomposition. truncateForModel, compactContextText, RagSourceBlockOptions, richTableSourceContextEnabled, tableSnippetForFact, formatTableFactForSourceBlock, and buildRagSourceBlock moved verbatim. metadataText re-homed to rag-answer-text.ts beside safeRecord. rag.ts re-exports buildRagSourceBlock + truncateForModel so existing consumers (tests/rag-trust, tests/rag-content-accuracy) are unchanged. rag.ts 7,740 -> 7,589 lines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPVNBVo4cg9PEYtNhJZBQY
…fication.ts (move-only) Move 3a of the rag.ts decomposition. actionableNumericAnswerPattern, hasActionableNumericContext, applyNumericVerification, and unboldUnverifiedNumbers moved verbatim next to the verifyAnswerNumbers / extractNumericTokens primitives they wrap. rag.ts re-exports applyNumericVerification + unboldUnverifiedNumbers for existing test consumers. rag.ts 7,589 -> 7,484 lines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPVNBVo4cg9PEYtNhJZBQY
…on.ts (move-only) Move 4 of the rag.ts decomposition. capPerDocumentCrowding, selectModelContextResults, maxContextChunksPerDocument, and fastRoutineModelContextLimit moved verbatim; rag.ts re-exports the two functions for existing consumers (tests/rag-context-budget). The adjacent context-packing family (packedContextCacheKey/packAdjacentSourceContext) stays for the cache-region move — it depends on stableHash and committed-generation helpers that belong there. rag.ts 7,484 -> 7,446 lines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPVNBVo4cg9PEYtNhJZBQY
…for remaining moves Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPVNBVo4cg9PEYtNhJZBQY
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
BigSimmo
marked this pull request as ready for review
July 7, 2026 05:18
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
BigSimmo
enabled auto-merge
July 7, 2026 05:19
15 tasks
8 tasks
14 tasks
BigSimmo
added a commit
that referenced
this pull request
Aug 17, 2026
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First tranche of the
src/lib/rag.tsdecomposition (7,874 → ~7,450 lines), applying the same verbatim move-only playbook used for the ClinicalDashboard decomposition. Four leaf families extracted, all cycle-free, one commit per move with per-move gates (typecheck + focused vitest + lint + prettier):src/lib/rag-quote-verification.ts—normalizeQuoteVerificationText,tableFactQuoteText,sourceTextForQuoteVerification,isExactSourceQuote,sanitizeQuoteCards,sanitizeConflictsOrGaps,enrichGroundedReviewCitations.src/lib/rag-source-block.ts—truncateForModel,compactContextText,richTableSourceContextEnabled,tableSnippetForFact,formatTableFactForSourceBlock,buildRagSourceBlock.src/lib/answer-verification.ts—applyNumericVerification,unboldUnverifiedNumbers,hasActionableNumericContextnow live beside theverifyAnswerNumbers/extractNumericTokensprimitives they wrap.src/lib/rag-context-selection.ts—capPerDocumentCrowding,selectModelContextResults(+ their consts).Supporting re-homes (all one-way, no new cycles):
allowedChunkMap→citations.ts;safeRecord+metadataText→rag-answer-text.ts;appendRoutingReason→rag-routing.ts; and rag.ts'sresultCitationwas an exact duplicate ofcitations.citationFromResult, so it now imports that under the old alias (a dedup win).rag.tsre-exports every moved name that tests or routes import, so no consumer changed.The debt log (
docs/process-hardening.md) gained a dated part-1 entry including the measured coupling for the remaining regions: the extractive-answer (L) and answer-quality (M) families are mutually entangled on main and must move together in a dedicated pass; retrieval variants (H) additionally depend on owner-scope helpers; context packing (J) belongs with the cache region (F). The pre-drift region map should not be trusted for part 2.Verification
npm run verify:cheap— pass (runtime, sitemap, lint [5 pre-existing warnings, 0 errors], typecheck, 1,181 unit tests)npm run verify:ui— 109/109 passednpm run build— pass (production build)npm run verify:releasebefore release or handoff confidence claimsnpm run format:check— pass (prettier run per move)npm run eval:retrieval:quality(must stay 23/23) — could not run here (needs live keys). These moves are answer-side and verbatim (no retrieval selection/ordering/scoring logic changed), but per the standing gate please run it locally before merge and paste the summary.npm run eval:rag/eval:quality— no answer-generation logic changed (verbatim moves); same caveat as above if you want belt-and-bracesnpm run check:production-readiness— N/A: no env/privacy/deployment behavior changenpm run check:deployment-readiness— N/APer-move gates that ran green on every commit:
tsc --noEmit, focused vitest (rag-trust,rag-content-accuracy,answer-ranking,answer-verification,rag-context-budget— 43–59 tests per move), eslint, prettier. Every moved block was diff-verified byte-identical against its rag.ts source before deletion.Clinical Governance Preflight
Code-motion only in the answer pipeline; no behavior, prompt, ranking, or data-access change.
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
🤖 Generated with Claude Code
https://claude.ai/code/session_01XPVNBVo4cg9PEYtNhJZBQY
Generated by Claude Code