{
  "batch": "abstraction_fitness",
  "batch_index": 6,
  "assessments": {
    "abstraction_fitness": 72.5
  },
  "dimension_notes": {
    "abstraction_fitness": {
      "evidence": [
        "30 dict[str, Any] annotations across cli.py — the 'state' dict is threaded through ~25 functions without a typed structure, acting as an implicit parameter bag",
        "sha256_file is a trivial pass-through to sha256_text (read file then hash), though it does add file-reading policy",
        "No protocol/base-class abstractions with single implementations — good",
        "No cross-module wrapper chains — the codebase is a single module",
        "SCHEMAS dict defines JSON schemas inline rather than using dataclasses/TypedDicts, creating a parallel type system",
        "Wide param bags: 6 functions have wide parameter lists, 52 config_bag_mentions in cli.py",
        "create_claude_prompt and create_codex_prompt share significant structure but are separate ~150-line functions with duplicated patterns"
      ],
      "impact_scope": "module",
      "fix_scope": "multi_file_refactor",
      "confidence": "high",
      "sub_axes": {
        "abstraction_leverage": 82.0,
        "indirection_cost": 88.0,
        "interface_honesty": 85.0,
        "delegation_density": 95.0,
        "definition_directness": 90.0,
        "type_discipline": 45.0
      }
    }
  },
  "dimension_judgment": {
    "abstraction_fitness": {
      "dimension_character": "The codebase avoids over-abstraction — there are no unnecessary base classes, protocols, or wrapper chains. Functions call real logic directly. However, the pervasive use of dict[str, Any] for the central 'state' object means the code relies on implicit key contracts across 25+ functions, creating a large implicit parameter bag that undermines type discipline and makes the real data shape invisible at call sites.",
      "score_rationale": "The codebase scores well on indirection avoidance and directness — a developer navigating from handle_plan to its helpers never gets lost in wrapper layers. This pulls toward 80+. However, the dict[str, Any] state bag threaded everywhere is a significant abstraction fitness problem: it hides the actual contract, prevents static analysis, and forces developers to grep for key usage. With 30 such annotations, this is not isolated — it pulls the score into the low 70s."
    }
  },
  "issues": [
    {
      "dimension": "abstraction_fitness",
      "identifier": "state_dict_param_bag",
      "summary": "Central 'state' dict passed to 25+ functions as dict[str, Any] — implicit parameter bag",
      "related_files": ["megaplan/cli.py"],
      "evidence": [
        "30 dict[str, Any] annotations in cli.py per mechanical scan",
        "Functions like infer_next_steps, require_state, build_evaluation, create_claude_prompt, persist_session all accept state: dict[str, Any] and access deeply nested keys like state['config']['project_dir'], state['meta']['weighted_scores'], state.get('last_evaluation', {}).get('recommendation')",
        "The actual shape is well-defined (initialized in handle_init lines 1446-1472) but never declared as a type"
      ],
      "suggestion": "Define a PlanState TypedDict (or dataclass) capturing the known shape: name, idea, current_state, iteration, config (with its own typed shape), sessions, plan_versions, history, meta, last_evaluation, clarification. This replaces dict[str, Any] with a declared contract without adding indirection — the type is the documentation.",
      "confidence": "high",
      "impact_scope": "module",
      "fix_scope": "multi_file_refactor"
    },
    {
      "dimension": "abstraction_fitness",
      "identifier": "inline_json_schemas",
      "summary": "JSON schemas defined as inline dicts duplicate the shape information that TypedDicts would provide",
      "related_files": ["megaplan/cli.py"],
      "evidence": [
        "SCHEMAS dict (lines 113-220) defines 6 JSON schemas as nested dicts with 'type', 'properties', 'required' keys",
        "validate_payload (line 620) does a separate key-presence check that partially overlaps with these schemas",
        "The schemas are written to disk for agent consumption but also serve as internal documentation of expected shapes"
      ],
      "suggestion": "This is a deliberate design — schemas are for external agent consumption via --json-schema and --output-schema flags, not for internal type checking. The validate_payload function is a lightweight fallback. No change needed unless internal type safety is desired, in which case deriving schemas from TypedDicts would unify both uses.",
      "confidence": "low",
      "impact_scope": "module",
      "fix_scope": "multi_file_refactor"
    }
  ],
  "retrospective": {
    "root_causes": ["The codebase grew as a single-module CLI where dict-based JSON state was the natural serialization format, and typed wrappers were never introduced as the state shape stabilized"],
    "likely_symptoms": ["inline_json_schemas"],
    "possible_false_positives": []
  },
  "context_updates": {
    "abstraction_fitness": {
      "add": [
        {
          "header": "No unnecessary indirection layers",
          "description": "The codebase has zero protocol/base-class abstractions, zero delegation-heavy classes, and only one trivial pass-through wrapper (sha256_file). Functions call real logic directly without intermediary layers.",
          "settled": true,
          "positive": true
        },
        {
          "header": "Direct single-module architecture",
          "description": "All logic lives in one module (cli.py) with no cross-module wrapper chains or helper-layer indirection. This is appropriate for the codebase size (~2500 LOC).",
          "settled": true,
          "positive": true
        },
        {
          "header": "Untyped state dict as implicit contract",
          "description": "The central 'state' dict is threaded through 25+ functions as dict[str, Any]. Its shape is well-defined in handle_init but never declared as a type, making the contract implicit and invisible to static analysis.",
          "settled": true,
          "positive": false
        }
      ]
    }
  }
}