Skip to content

feat: AnalysisRunner interface + ClaudeNativeRunner + ProviderRunner #239

@melagiri

Description

@melagiri

Context

Part of the Native Analysis via Claude Code Hooks feature (Phase 12, v4.8.0).
Plan: docs/plans/2026-03-28-native-analysis-hooks.md

Issue 2 of 6 — Depends on #238 (prompt module migration).

Problem

The insights command needs to run analysis via two different backends: claude -p (native) and the existing LLM provider abstraction. We need a clean interface so the command doesn't care which backend is used.

Solution

AnalysisRunner Interface

interface AnalysisRunner {
  readonly name: string;
  runAnalysis(params: RunAnalysisParams): Promise<RunAnalysisResult>;
}

Two Implementations

  1. ClaudeNativeRunner — executes claude -p via execFileSync (not exec — shell injection safety)

    • Writes system prompt to temp file
    • Writes JSON schema to temp file
    • Pipes conversation via stdin
    • Returns raw JSON response
    • Records tokens=0, cost=0 (counted in Claude subscription)
  2. ProviderRunner — wraps existing server/src/llm/client.ts LLM abstraction

    • Same behavior as current dashboard/API analysis
    • Returns actual token counts and costs

JSON Schema Files

Hand-maintained flat JSON schemas for claude -p --json-schema:

  • cli/src/analysis/schemas/session-analysis.json (from AnalysisResponse type)
  • cli/src/analysis/schemas/prompt-quality.json (from PromptQualityResponse type)

Test that validates schema properties match TypeScript interface fields.

New Files

File Purpose
cli/src/analysis/runner-types.ts AnalysisRunner interface + param/result types
cli/src/analysis/native-runner.ts ClaudeNativeRunner (claude -p via execFileSync)
cli/src/analysis/provider-runner.ts ProviderRunner (wraps existing LLM client)
cli/src/analysis/schemas/session-analysis.json JSON schema for session analysis
cli/src/analysis/schemas/prompt-quality.json JSON schema for prompt quality
cli/src/analysis/schemas/__tests__/schema-sync.test.ts Schema ↔ TypeScript sync test

Acceptance Criteria

  • AnalysisRunner interface defined with RunAnalysisParams/RunAnalysisResult
  • ClaudeNativeRunner validates claude CLI in PATH, uses execFileSync
  • ProviderRunner delegates to existing LLM client
  • JSON schema files cover all required fields of AnalysisResponse and PromptQualityResponse
  • Schema sync test passes in CI
  • Unit tests for both runners (mocked execFileSync / LLM client)
  • SOLID: adding future runners (e.g., Cursor) requires only implementing the interface

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureNew functionalityinfrastructureBuild, CI, tooling, refactoring

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions