refactor: extract format layer, dedup helpers, precompile keyword regexes#22
Closed
dkships wants to merge 2 commits into
Closed
refactor: extract format layer, dedup helpers, precompile keyword regexes#22dkships wants to merge 2 commits into
dkships wants to merge 2 commits into
Conversation
…exes Pure move plus dedup; no behavior change. analyzeFeedback output verified byte-for-byte identical on a fixed dataset across this change. - New src/format.ts holds the PII-scrubbing formatters, quote extraction, agent-response detection, and detail trimming (index.ts is untestable by import: it exits without env and connects a transport at load) - New helpers replace duplicated blocks in index.ts: toErrorResult (4 identical catch bodies), buildLookupMaps, signalTypeOf, capTitles; get_feature_requests reuses filterClientsByPortal - Theme keyword regexes compile once per analyzeFeedback run instead of per data point x theme x keyword; matchesTheme keeps its signature and semantics (multi-word substring, word-boundary singles, escaping, no g flag) - New guardrail tests for parsePortalConfigs env parsing and the format layer (24 new tests; 64 total) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Stacked on #21 (base is
quality/scoring-resilience); merge that first. This PR is a pure refactor and should review as moved code with zero behavior change.src/format.ts: the PII-scrubbing formatters, quote extraction, agent-response detection, and detail trimming.index.tscan't be imported in tests (it exits without env vars and connects a stdio transport at module load), so the testable format layer had to move out to get coverage.index.ts: onetoErrorResultreplaces 4 identical catch bodies,buildLookupMaps/signalTypeOf/capTitlesreplace the twice-written lookup-map, signal-type, and title-capping blocks, andget_feature_requestsreusesfilterClientsByPortalinstead of its inline copy.analyzeFeedbackrun instead of once per data point per theme per keyword. Semantics preserved exactly: multi-word keywords stay substring matches, single-word keywords stay word-boundary regexes with escaping, nogflag, and the compilation is per-run (not module-cached) sothemes.config.jsonstays hot-editable.parsePortalConfigsenv parsing (multi-portal, pipes inside API keys, trimming, malformed entries, single-portal fallback) and the format layer (thread-count mapping, email redaction, PII sink collection, no commenter names, detail-level shapes, title capping).Verification: build and tests green;
analyzeFeedbackoutput compared byte-for-byte on a fixed 22-conversation / 16-request synthetic dataset built from the real theme config, run on both branches — identical. A live A/B smoke run was inconclusive only because ProductLift rate-limited 3 of 4 portals on one side (which the new per-portal warnings from #21 surfaced correctly).🤖 Generated with Claude Code