ratchet brief - xopherdeep/do-it-for-the-xp GitHub Wiki

Ratchet cleanup: bring the whole-project audit back under its ratchet (lead's task before the Gate)

Why: CI's Verify (chemx verify) has been red on master since the owner merged Project Towers T1-T7 (73ca9395): the audit's ratchet gate fails. The PR for T8-T12 runs the same whole-project audit, so it cannot go green until these regressions are gone. Every regression below comes from this feature's code; nothing else needs touching.

chemx audit (run at the worktree root) reports today:

gate: fail (ratchet)
  regression: AI_SLOP_REDUNDANT_PASSTHROUGH 0 -> 5
  regression: CONTROL_FLOW_DISPATCH_SWITCH 36 -> 38
  regression: CONTROL_FLOW_INLINE_BOOLEAN 8 -> 22
  regression: LINE_BUDGET_FILE 39 -> 40

The items that are ours (fix exactly these; leave every other file alone):

  1. AI_SLOP_REDUNDANT_PASSTHROUGH ("Inline redundant single-use passthrough assignments directly into return expressions"): src/lib/databases/ProjectDb.ts:19, src/lib/engine/dungeons/generator/templeSolver.ts:82, src/lib/services/projects/projectChores.ts:117, src/lib/services/projects/projectQuests.ts:66, src/lib/services/projects/projectTower.ts:107. A boolean named only to be returned on the next line: return the expression (keep it readable; a named helper function is fine).
  2. CONTROL_FLOW_DISPATCH_SWITCH ("Replace repetitive dispatch switch with an O(1) keyed dictionary or method map"): the switch (door.lock) the branch added in src/lib/engine/dungeons/generator/templeSolver.ts (~L91) and the switch (lock) in src/lib/services/temples/roomInteractions/travel.ts (~L71). Replace each with a keyed record of handlers (typed Record<LockKind, ...> or Partial<...> with a default), same behaviour. Do not touch the other switches in travel.ts (~L153) or doors.ts unless the audit shows they are new.
  3. CONTROL_FLOW_INLINE_BOOLEAN ("The if asks instead of reading a named condition. Name the question first"): src/lib/services/projects/floorBonus.ts:45; projectChores.ts:144, 186, 195; projectSchedule.ts:30, 60, 68, 92; projectTower.ts:90, 92, 93, 110; src/lib/services/temples/roomInteractions/travel.ts:132, 143. Name the condition in a const isX = ...; (or hasX, canX) before the if. Caution from the audit's own hint: for a nullable handle, act on the handle directly (an alias of the test breaks TypeScript narrowing); where naming would break narrowing, use a small type-guard function instead. Do not trade an INLINE_BOOLEAN for a new PASSTHROUGH.
  4. LINE_BUDGET_FILE ("Decompose monolith into domain capsules"): src/lib/engine/quests/QuestSchedule.ts grew from 491 to 519 lines on this branch (Task 1's project-quest rules). Bring it to 500 lines or fewer by moving the project-quest block (the isProjectQuest rules and their helpers) into a sibling module, e.g. src/lib/engine/quests/projectQuestSchedule.ts, re-exported from QuestSchedule.ts so no importer changes. No behaviour change.

Line numbers are from the audit at 2908506a; files may have shifted a few lines. Find each with chemx audit <dir> (it lists file:line per rule) before editing.

Done means: chemx audit at the worktree root prints gate: pass (or, if some other session's unrelated code regresses a rule meanwhile, none of the four rules above lists a file of this list), and every spec covering a changed file is green.

Specs to run (each touched file's): tests/unit/ProjectDb.spec.ts, tests/unit/FloorClearedClimb.spec.ts, tests/unit/TowerFloorLock.spec.ts, tests/unit/projectChores.spec.ts, tests/unit/projectQuests.spec.ts, tests/unit/projectTower.spec.ts, tests/unit/floorBonus.spec.ts, tests/unit/projectSchedule.spec.ts, tests/unit/QuestScheduleProjectQuests.spec.ts, plus the QuestSchedule and templeSolver / travel specs that exist (find them: chemx q -g "QuestSchedule" tests/unit -l, chemx q -g "templeSolver" tests/unit -l, chemx q -g "roomInteractions/travel" tests/unit -l). Run them before your edits too, so you know they were green.

⚠️ **GitHub.com Fallback** ⚠️