Skip to content

vibe-check analyze — Go-native package-level coupling metrics #2

Description

@jflowers

Summary

Add a vibe-check analyze command that computes package-level structural quality metrics for Go codebases using the Go-native toolchain.

RFC: https://github.com/orgs/unbound-force/discussions/483 — Group 1
Phase: P0 (Foundation)

Context

The metrics package (merged via PR #17) provides the universal coupling model — named metric types, the Adapter interface, ExternalAdapter with JSON-RPC 2.0 protocol, Registry, and JSON Schema validation. This issue builds the Go-native adapter and CLI on top of that foundation, making the metrics computable and accessible.

Architecture

vibe-check analyze [packages...]
        │
        ├── cmd/vibe-check/          CLI entry point (cobra)
        ├── internal/go/             Go-native adapter (implements metrics.Adapter)
        │     └── uses golang.org/x/tools/go/packages
        └── metrics/                 Universal model (already merged)
              ├── adapter.go         Adapter interface
              ├── compute.go         ComputeInstability, ComputeAbstractness, etc.
              ├── graph.go           ModuleGraph, ModuleResult
              └── values.go          Instability, Abstractness, Distance, LCOM

Metrics to Compute

Metric Symbol Description
Afferent Coupling Ca Number of packages that depend on this package
Efferent Coupling Ce Number of packages this package depends on
Instability I Ce / (Ca + Ce) — ranges from 0 (stable) to 1 (unstable)
Abstractness A Ratio of abstract types (interfaces) to total types
Distance from Main Sequence D |A + I − 1| — proximity to the ideal balance
Cohesion LCOM LCOM4 variant (Hitz & Montazeri, 1995)
Circular Dependencies Detection of import cycles

Implementation

  • Go adapter: Implements metrics.Adapter interface using golang.org/x/tools/go/packages for type-aware dependency resolution
  • CLI: vibe-check analyze [packages...] using cobra
  • Output: JSON conforming to metrics.ModuleGraph schema (validated by metrics.Validate)
  • Registration: Go adapter registered in metrics.Registry at startup

CI Gate Flags

vibe-check analyze ./... \
  --max-instability=0.67 \
  --max-distance=0.3 \
  --no-circular-deps \
  --min-cohesion=0.5

Exit code non-zero if any threshold is violated.

JSON Output

{
  "schemaVersion": "1.0",
  "language": "go",
  "projectPath": "./...",
  "status": "complete",
  "modules": [
    {
      "path": "internal/analyzer",
      "afferentCoupling": 5,
      "efferentCoupling": 3,
      "instability": 0.375,
      "abstractness": 0.2,
      "distance": 0.425,
      "lcom": 2,
      "cycles": []
    }
  ],
  "warnings": []
}

Acceptance Criteria

  • vibe-check analyze command implemented using cobra
  • Go adapter implements metrics.Adapter interface
  • Uses golang.org/x/tools/go/packages for dependency resolution
  • All 7 metrics computed correctly (Ca, Ce, I, A, D, LCOM, circular deps)
  • JSON output conforms to metrics.ModuleGraph schema (passes metrics.Validate)
  • CI gate flags work (--max-instability, --max-distance, --no-circular-deps, --min-cohesion)
  • Non-zero exit code on threshold violations
  • Tests covering metric computation accuracy
  • go build ./..., go test -race -count=1 ./..., golangci-lint run ./... all pass

Dependencies

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Critical priority — Phase 1 foundation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions