Skip to content

refactor: extract format layer, dedup helpers, precompile keyword regexes#22

Closed
dkships wants to merge 2 commits into
quality/scoring-resiliencefrom
quality/refactor-format
Closed

refactor: extract format layer, dedup helpers, precompile keyword regexes#22
dkships wants to merge 2 commits into
quality/scoring-resiliencefrom
quality/refactor-format

Conversation

@dkships

@dkships dkships commented Jul 2, 2026

Copy link
Copy Markdown
Owner

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.

  • Extracts src/format.ts: the PII-scrubbing formatters, quote extraction, agent-response detection, and detail trimming. index.ts can'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.
  • Dedupes the repeated blocks in index.ts: one toErrorResult replaces 4 identical catch bodies, buildLookupMaps / signalTypeOf / capTitles replace the twice-written lookup-map, signal-type, and title-capping blocks, and get_feature_requests reuses filterClientsByPortal instead of its inline copy.
  • Compiles theme keyword regexes once per analyzeFeedback run 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, no g flag, and the compilation is per-run (not module-cached) so themes.config.json stays hot-editable.
  • Adds 24 guardrail tests (64 total): parsePortalConfigs env 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; analyzeFeedback output 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

…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>
@dkships dkships deleted the branch quality/scoring-resilience July 2, 2026 03:25
@dkships dkships closed this Jul 2, 2026
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