Skip to content

Add cgis init-ontology: auto-propose patterns.yaml from measured graph #174

Description

@zaebee

Summary

Add cgis init-ontology — auto-propose a starter patterns.yaml from the measured graph, so cgis_drift is usable without hand-authoring the ontology.

Motivation

cgis_drift is the most valuable feature but has the steepest onboarding cost: it needs a hand-written patterns.yaml binding each domain (fqn_prefix) to an expected_pattern + drift_tolerance. On a fresh repo (drift on a clone is a no-op without it), this is the single biggest barrier to adoption.

When I onboarded a real FastAPI backend I did this manually and mechanically:

  1. enumerate top-level packages → candidate domains (app.services, app.crud, app.utils, …)
  2. measure each domain's actual triad census
  3. pick the closest of the 5 templates as expected_pattern
  4. set drift_tolerance = measured + small margin (ratchet baseline)

Steps 2–4 are exactly what the engine already computes. It can propose the file.

Proposal

cgis init-ontology(db_path, out="patterns.yaml", margin=0.03, min_nodes=10)
  • discover candidate domains from package/module structure (configurable depth)
  • for each, compute the census and pick the nearest template by TV distance (report the fit + the runner-up)
  • emit drift_tolerance = measured + margin and a # measured ≈ X comment per domain
  • domains below min_nodes → hygiene-only (no expected_pattern)
  • reuse the existing language profiles / patterns blocks verbatim

Output is a ready-to-edit baseline the user ratchets down over time, instead of a blank page.

Impact

Turns drift from "expert-only, write YAML first" into "run one command, get a baseline." This is the difference between a demo and something teams actually adopt in CI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions