{
  "batch": "api_surface_coherence",
  "batch_index": 11,
  "assessments": {
    "api_surface_coherence": 78.5
  },
  "dimension_notes": {
    "api_surface_coherence": {
      "evidence": [
        "All handle_* functions follow a consistent (root, args) -> dict signature pattern, which is a strong positive for API predictability",
        "run_claude_step and run_codex_step have different parameter signatures: run_claude_step takes (step, state, plan_dir, *, root, fresh) while run_codex_step takes (step, state, plan_dir, *, root, persistent, fresh, json_trace) — the 'persistent' parameter on codex has no counterpart on claude",
        "create_claude_prompt and create_codex_prompt have identical (step, state, plan_dir) signatures but create_codex_prompt delegates to create_claude_prompt for clarify/plan/integrate steps, making the boundary between them unclear",
        "persist_session has 6 parameters (state, step, agent, session_id, mode, refreshed) which is at the edge of the >5 parameter threshold",
        "All public functions lack error contract documentation — CliError is raised throughout but callers must read implementations to know which error codes are possible",
        "The __all__ export list in cli.py exports 40+ symbols including internal helpers, constants, handlers, and utilities with no grouping or tiering"
      ],
      "impact_scope": "module",
      "fix_scope": "multi_file_refactor",
      "confidence": "medium"
    }
  },
  "dimension_judgment": {
    "api_surface_coherence": {
      "dimension_character": "The handle_* command API surface is remarkably consistent — all 16 handlers take (root, args) and return dict, making the CLI layer predictable. However, the worker-layer APIs (run_claude_step vs run_codex_step) have divergent parameter signatures that force the orchestration layer to know which agent it is calling. The massive __all__ export list mixes internal helpers with public API without tiering, making it unclear what external consumers should rely on.",
      "score_rationale": "The consistent handle_* pattern pushes toward solid quality, but the worker API shape divergence and the flat, undifferentiated __all__ export surface pull the score down. A developer working with the handle_* layer would find it predictable, but anyone integrating at the worker or utility layer would encounter friction from inconsistent shapes and missing error contracts. This places it around 78-79 — solid in the main API shape but with uneven support surfaces."
    }
  },
  "issues": [
    {
      "dimension": "api_surface_coherence",
      "identifier": "worker_api_shape_divergence",
      "summary": "run_claude_step and run_codex_step have inconsistent parameter signatures",
      "related_files": ["megaplan/cli.py"],
      "evidence": [
        "run_claude_step(step, state, plan_dir, *, root, fresh) at line 1115 vs run_codex_step(step, state, plan_dir, *, root, persistent, fresh, json_trace) at line 1154 — 'persistent' and 'json_trace' exist only on codex, making run_step_with_worker at line 1421 carry agent-specific knowledge"
      ],
      "suggestion": "Unify the keyword parameters: both functions should accept the same keyword-only interface (e.g. mode, fresh, json_trace) with sensible defaults for the agent that ignores a given parameter. This lets run_step_with_worker pass a uniform kwargs dict.",
      "confidence": "medium",
      "impact_scope": "module",
      "fix_scope": "single_edit"
    },
    {
      "dimension": "api_surface_coherence",
      "identifier": "missing_error_contracts",
      "summary": "No public function documents which CliError codes it may raise",
      "related_files": ["megaplan/cli.py"],
      "evidence": [
        "handle_execute can raise CliError with codes 'missing_confirmation', 'missing_approval', 'worker_error', 'agent_not_found' among others, but none are documented. A caller integrating programmatically must read the full implementation to handle errors."
      ],
      "suggestion": "Add a Raises section to docstrings of at least the handle_* public API functions listing the CliError codes they produce. Start with handle_execute and handle_gate which have the most complex error paths.",
      "confidence": "medium",
      "impact_scope": "module",
      "fix_scope": "single_edit"
    }
  ],
  "retrospective": {
    "root_causes": ["The two agent backends (claude/codex) evolved with different CLI interfaces, and their wrapper functions reflect those differences rather than presenting a unified abstraction"],
    "likely_symptoms": [],
    "possible_false_positives": []
  },
  "context_updates": {
    "api_surface_coherence": {
      "add": [
        {
          "header": "Consistent handle_* command signature pattern",
          "description": "All 16 command handlers use the uniform (root: Path, args: Namespace) -> dict[str, Any] signature. This makes the CLI dispatch layer fully predictable and easy to extend.",
          "settled": true,
          "positive": true
        },
        {
          "header": "Flat undifferentiated __all__ export surface",
          "description": "cli.py exports 40+ symbols in __all__ mixing constants, dataclasses, utilities, and handlers without grouping. Consumers cannot distinguish public API from internal helpers without reading the code.",
          "settled": true,
          "positive": false
        }
      ]
    }
  }
}