Skip to content

Phase 1.2 — Refactor plan.ts to read from MODE_DEFINITIONS #1727

@CraigBuckmaster

Description

@CraigBuckmaster

Part of epic #1725. Depends on #1726. Phase 1 — Mode-as-data refactor.

Objective

Replace the scattered mode-aware constants and conditionals in plan.ts with reads from MODE_DEFINITIONS. Must produce zero visible behavior change — snapshot tests in #1.4 will prove this.

Files

Modify

  • app/src/services/guidedStudy/plan.ts

Do NOT modify

  • MODE_DEFINITIONS itself (this card consumes it; Phase 2 extends it)
  • types.ts
  • Any UI component

What to remove from plan.ts

  • const DEFAULT_MODE
  • const MODE_RECOMMENDATION_LIMIT
  • const MODE_TRAIL_ORDER
  • function normalizeMode body (replace with call to getModeDefinition)
  • function modeLabel body (replace with getModeDefinition(mode).label)
  • The mode-specific switch statement inside betterQuestionPrompt — keep the function but make it pure-of-mode for now (covered fully in Phase 2.1)

What to add

import { getModeDefinition } from './modes/definitions';

Replace MODE_RECOMMENDATION_LIMIT[mode] with getModeDefinition(mode).recommendationLimit.
Replace MODE_TRAIL_ORDER[mode] with getModeDefinition(mode).trailOrder.
Replace normalizeMode(mode) with getModeDefinition(mode ?? 'deep').key where it's currently used to validate, and a thin shim function that just delegates.

buildRecommendations() panel weights wiring

Add panelWeights parameter to buildRecommendations, but default to {} and apply no behavior in Phase 1. The signature must accept weights so Phase 2.4 can flip them on without another plan.ts refactor. When weights are empty, sort order is exactly the existing RECOMMENDATION_ORDER array (no change).

function buildRecommendations(
  input: GuidedStudyPlanInput,
  panelWeights: Record<string, number> = {},
): GuidedPanelRecommendation[];

Inside buildGuidedStudyPlan, call:

const def = getModeDefinition(mode);
const allRecommendations = buildRecommendations(input, def.panelWeights);

def.panelWeights is {} for all four modes after Phase 1, so this is a no-op behaviorally.

Acceptance

  1. MODE_RECOMMENDATION_LIMIT and MODE_TRAIL_ORDER constants are deleted.
  2. plan.ts references getModeDefinition exclusively for mode-shaped values.
  3. buildRecommendations accepts a panelWeights parameter with {} default.
  4. tsc, lint, test all clean.
  5. Phase 1.4 snapshot tests pass without modification.

Out of scope

  • Adding mode-specific betterQuestionPrompt per-mode-via-MODE_DEFINITIONS (that's Phase 2.1).
  • Implementing actual weight bias logic (that's Phase 2.4).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions