-
Notifications
You must be signed in to change notification settings - Fork 0
feat: implement universal coupling metrics model (Layer 1) #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f62b866
feat: add universal coupling model spec artifacts
jflowers ab3aade
feat: implement universal coupling metrics model (Layer 1)
jflowers 3a63988
fix: address code review findings from review council
jflowers ab32da4
chore: mark code review passed in tasks.md
jflowers 84fd4bd
chore: store retrospective learnings from implementation session
jflowers 09bb223
fix: address review council findings (iteration 1)
jflowers 9c24254
fix: address all MEDIUM review council findings
jflowers c52906a
fix(ci): use golangci-lint-action v7 for golangci-lint v2 support
jflowers 21c46e6
fix(ci): migrate .golangci.yml linters-settings to v2 format
jflowers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: Build | ||
| run: go build ./... | ||
|
|
||
| - name: Vet | ||
| run: go vet ./... | ||
|
|
||
| - name: Test | ||
| run: go test -race -count=1 -coverprofile=coverage.out ./... | ||
|
|
||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-go@v5 | ||
| with: | ||
| go-version-file: go.mod | ||
|
|
||
| - name: golangci-lint | ||
| uses: golangci/golangci-lint-action@v7 | ||
| with: | ||
| version: latest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| version: "2" | ||
|
|
||
| run: | ||
| timeout: 5m | ||
|
|
||
| formatters: | ||
| enable: | ||
| - gofmt | ||
| - goimports | ||
| settings: | ||
| goimports: | ||
| local-prefixes: | ||
| - github.com/zero-dot-force/vibe-check | ||
|
|
||
| linters: | ||
| enable: | ||
| - errcheck | ||
| - govet | ||
| - revive | ||
| - staticcheck | ||
| - unused | ||
| - ineffassign | ||
| settings: | ||
| revive: | ||
| rules: | ||
| - name: exported | ||
| severity: warning | ||
| - name: error-return | ||
| severity: warning | ||
| - name: error-strings | ||
| severity: warning | ||
| - name: unexported-return | ||
| severity: warning |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
.uf/dewey/learnings/universal-coupling-model-20260829T005320-jay-flowers.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| tag: universal-coupling-model | ||
| author: jay-flowers | ||
| category: pattern | ||
| created_at: 2026-08-29T00:53:20Z | ||
| identity: universal-coupling-model-20260829T005320-jay-flowers | ||
| tier: draft | ||
| --- | ||
|
|
||
| When implementing a universal coupling metrics model for Go codebases (vibe-check project), the two-layer architecture pattern (Layer 1 = universal model, Layer 2 = language adapters) proved effective. The key design decisions that worked well: (1) flat metrics package rather than internal/ because the model IS the public API, (2) named metric types like Instability float64 with GoDoc documenting ranges and citations, (3) Module as the universal unit of analysis with language-neutral terminology, (4) JSON-RPC 2.0 over stdin/stdout for external adapters with newline-delimited framing. The ExternalAdapter's functional options pattern (WithAnalyzeTimeout, WithMaxResponseSize, etc.) provided clean configuration without breaking constructor signatures, though it deviates from the AP-001 Options struct convention — this deviation should be documented as a custom rule. |
10 changes: 10 additions & 0 deletions
10
.uf/dewey/learnings/universal-coupling-model-20260829T005332-jay-flowers.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| tag: universal-coupling-model | ||
| author: jay-flowers | ||
| category: gotcha | ||
| created_at: 2026-08-29T00:53:32Z | ||
| identity: universal-coupling-model-20260829T005332-jay-flowers | ||
| tier: draft | ||
| --- | ||
|
|
||
| When testing Go subprocess communication (ExternalAdapter in vibe-check), the TestHelperProcess pattern (os.Args[0] with GO_WANT_HELPER_PROCESS env var) is the standard library-compatible approach that avoids external test binaries. Key gotchas: (1) the test function parameter should use _ *testing.T since it's not a real test, (2) tests using t.Setenv cannot use t.Parallel — Go 1.17+ enforces this, (3) limitedBuffer for stderr capture must always report the full write length to avoid breaking the subprocess pipe even on internal errors, (4) Gaze quality analysis revealed that constructor functions (NewExternalAdapter, NewRegistry) often have 0% contract coverage because tests call them but never directly assert on the return value — adding nil checks and default value assertions closes this gap easily. |
10 changes: 10 additions & 0 deletions
10
.uf/dewey/learnings/universal-coupling-model-20260829T005336-jay-flowers.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| tag: universal-coupling-model | ||
| author: jay-flowers | ||
| category: gotcha | ||
| created_at: 2026-08-29T00:53:36Z | ||
| identity: universal-coupling-model-20260829T005336-jay-flowers | ||
| tier: draft | ||
| --- | ||
|
|
||
| For the vibe-check project's golangci-lint configuration, version 2 of golangci-lint treats gofmt and goimports as formatters not linters — they must go under formatters.enable, not linters.enable. Also, gosimple was merged into staticcheck in v2, so listing it separately causes an error. The .golangci.yml needs version: "2" at the top level. When implementing a hand-rolled JSON schema validator (metrics/validate.go) to avoid external dependencies, keep complexity low by extracting helper functions (validateModule, validateWarning) — Gaze flagged the main Validate function at complexity 16 which is the only Q4 Dangerous function in the codebase. |
10 changes: 10 additions & 0 deletions
10
.uf/dewey/learnings/universal-coupling-model-20260829T005344-jay-flowers.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| tag: universal-coupling-model | ||
| author: jay-flowers | ||
| category: pattern | ||
| created_at: 2026-08-29T00:53:44Z | ||
| identity: universal-coupling-model-20260829T005344-jay-flowers | ||
| tier: draft | ||
| --- | ||
|
|
||
| The review council consistently flagged zone classification threshold contradictions across spec artifacts — the design doc said thresholds are "configuration, not model" while the metrics-schema spec hardcoded them. The resolution was to accept thresholds as part of the model and update the design non-goal. This is a common spec review pattern: when a non-goal contradicts a spec requirement, the non-goal usually needs refinement rather than the spec. Another recurring theme was LCOM variant ambiguity — the constitution requires citing the measurement model, and LCOM4 (Hitz and Montazeri, 1995) was chosen for its connected-component semantics. Always specify WHICH variant of a well-known metric you're implementing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| module github.com/zero-dot-force/vibe-check | ||
|
|
||
| go 1.25.7 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package metrics | ||
|
|
||
| import "context" | ||
|
|
||
| // Adapter is the interface that all language-specific analyzers must implement. | ||
| // Adding a new language adapter requires only implementing this interface and | ||
| // registering with a [Registry]. | ||
| type Adapter interface { | ||
| // Analyze analyzes the project at projectPath and returns a complete ModuleGraph. | ||
| Analyze(ctx context.Context, projectPath string) (*ModuleGraph, error) | ||
| // Language returns the lowercase language identifier (e.g., "go", "python"). | ||
| Language() string | ||
| // Capabilities returns the list of metrics this adapter can compute. | ||
| // A nil or empty return may indicate either zero capabilities or a | ||
| // communication failure. Use Analyze for detailed error diagnostics. | ||
| Capabilities() []Capability | ||
| } | ||
|
|
||
| // Capability represents a metric that an adapter can compute. | ||
| type Capability string | ||
|
|
||
| const ( | ||
| // CapAfferentCoupling indicates the adapter can compute afferent coupling (Ca). | ||
| CapAfferentCoupling Capability = "ca" | ||
| // CapEfferentCoupling indicates the adapter can compute efferent coupling (Ce). | ||
| CapEfferentCoupling Capability = "ce" | ||
| // CapInstability indicates the adapter can compute instability (I). | ||
| CapInstability Capability = "instability" | ||
| // CapAbstractness indicates the adapter can compute abstractness (A). | ||
| CapAbstractness Capability = "abstractness" | ||
| // CapDistance indicates the adapter can compute distance from main sequence (D). | ||
| CapDistance Capability = "distance" | ||
| // CapLCOM indicates the adapter can compute Lack of Cohesion of Methods (LCOM4). | ||
| CapLCOM Capability = "lcom" | ||
| // CapCircularDeps indicates the adapter can detect circular dependencies. | ||
| CapCircularDeps Capability = "circular" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package metrics | ||
|
|
||
| import "math" | ||
|
|
||
| // ComputeInstability computes I = Ce / (Ca + Ce). | ||
| // When both Ca and Ce are 0, returns 0.0 (maximally stable by convention). | ||
| // This follows the convention that an isolated module with no coupling | ||
| // relationships is treated as stable rather than unstable. | ||
| func ComputeInstability(ca, ce int) Instability { | ||
| denom := ca + ce | ||
| if denom == 0 { | ||
| return 0.0 | ||
| } | ||
| return Instability(float64(ce) / float64(denom)) | ||
| } | ||
|
|
||
| // ComputeAbstractness computes A = abstractTypes / totalExported. | ||
| // When totalExported is 0, returns 0.0 (a module with no exported types | ||
| // is treated as fully concrete). | ||
| func ComputeAbstractness(abstractTypes, totalExported int) Abstractness { | ||
| if totalExported == 0 { | ||
| return 0.0 | ||
| } | ||
| return Abstractness(float64(abstractTypes) / float64(totalExported)) | ||
| } | ||
|
|
||
| // ComputeDistance computes D = |A + I - 1|. | ||
| // The result measures how far a module is from the main sequence, where | ||
| // the main sequence represents the ideal balance between abstractness | ||
| // and instability. | ||
| func ComputeDistance(a Abstractness, i Instability) Distance { | ||
| return Distance(math.Abs(float64(a) + float64(i) - 1.0)) | ||
| } | ||
|
|
||
| // ComputeZone classifies a module's position relative to the main sequence. | ||
| // Precedence (evaluated in order): | ||
| // 1. main-sequence: D < 0.2 | ||
| // 2. zone-of-pain: A < 0.2 AND I < 0.2 | ||
| // 3. zone-of-uselessness: A > 0.8 AND I > 0.8 | ||
| // 4. normal: all other cases | ||
| func ComputeZone(a Abstractness, i Instability, d Distance) Zone { | ||
| if d < 0.2 { | ||
| return ZoneMainSequence | ||
| } | ||
| if a < 0.2 && i < 0.2 { | ||
| return ZoneOfPain | ||
| } | ||
| if a > 0.8 && i > 0.8 { | ||
| return ZoneOfUselessness | ||
| } | ||
| return ZoneNormal | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.