fix(viewer): split CommandPalette's search/ranking helpers into their own module

Merged
PE
3mo ago
+166-110

Summary

CommandPalette.tsx grew to 852 lines on main against its 849-line scripts/module-size-allowlist.txt budget after #3942 and #3945 each landed a command entry the same day. Neither PR individually crossed the budget; together they did, so node scripts/check-module-size.mjs exits 1 on a clean checkout of main and every open PR inherits the red.

Closes #3957

Fix

Extracted a coherent, dependency-free seam: the fuzzy-search/ranking and recent-usage-tracking helpers (Category/Command/FlatItem types, score/rankCommand, getRecentIds/recordUsage) into a new commandPaletteSearch.ts. None of it touches React or the Zustand store, so it lifts out cleanly.

  • CommandPalette.tsx: 852 -> 752 lines (97 lines of headroom against the new 752-line budget)
  • commandPaletteSearch.ts: 116 lines (new, well under the 400-line rule)
  • The moved code is byte-identical apart from the mechanical export keywords the extraction requires (diffed against the pre-extraction file).
  • Every command id is unchanged (diffed the full id: '...' list before/after); the new module is imported and its exports (Command, FlatItem, MAX_RECENT, CATEGORY_ORDER, rankCommand, getRecentIds, recordUsage) are used in place, not orphaned.

This is a pure internal refactor — no command was renamed, removed, or behaviorally changed. Never raised the budget or touched CI workflow files.

Verification

$ node scripts/check-module-size.mjs
check-module-size: OK (2339 files measured, 340 allowlisted, 0 new over 400)

(exit 0)

  • pnpm --filter @ifc-lite/viewer typecheck — clean.
  • Both existing CommandPalette test files pass:
    • CommandPalette.anonymized-export.test.tsx
    • CommandPalette.exact-type.test.ts
    • tests 2, pass 2, fail 0
  • node scripts/check-test-wiring.mjs — OK.
  • node scripts/check-source-text-assertions.mjs — OK (0 new).
  • Changeset added (@ifc-lite/viewer patch) describing this as a pure internal refactor.

Test plan

  • node scripts/check-module-size.mjs exits 0
  • pnpm --filter @ifc-lite/viewer typecheck
  • Targeted CommandPalette tests pass
  • check-test-wiring / check-source-text-assertions pass
  • CI (full viewer suite left to CI per repo convention)

Summary by CodeRabbit

  • Bug Fixes

    • No user-facing behavior changes. Command palette search, ranking, and recent-command functionality continue to work as before.
  • Refactor

    • Improved the internal organization and maintainability of command palette functionality while preserving available commands and user interactions.
  • Tests

    • Added coverage for search matching, ranking, and result prioritization to help ensure consistent command palette behavior.