Skip to content

kb init: depth-bounded module scan and route coverage metrics - #240

Merged
tzhouam merged 1 commit into
mainfrom
kb/init-coverage
Sep 30, 2026
Merged

tzhouam merged 1 commit into
mainfrom
kb/init-coverage

Conversation

@tzhouam

@tzhouam tzhouam commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Part 4/9 of kb init (design v3, sol-approved): the coverage measures that decide what kb init must route (module pass) and how far it deepens (PR pass).

  • profiles/establish.scan_modules_at_depth(repo, language, *, source_roots, depth, min_loc, exclude=()): directory modules at most depth levels below each source root. Deeper files belong to the deepest such ancestor. Modules under min_loc non-blank lines fold into their parent, deepest first, until stable. Source roots never fold (normalize_root canonicalises ., ./pkg, /pkg/, so folding always terminates). Nested roots own their files, hidden and non-code dirs are skipped at every level, exclude fnmatch globs apply, and an unknown language returns {}.
  • kb_service/init_coverage:
    • load_owners reads the _routes.yaml owners.
    • routes_file matches by prefix.
    • module_coverage: a module counts as covered only if every file in it is routed.
    • make_include builds the path filter. Tests and docs are excluded through caller globs only, with no repo literals.
    • pr_weighted_coverage counts each file once per PR and reports routed and rule-bearing ratios, plus the uncovered hot paths.
    • churn_by_module assigns each file to the longest matching module prefix.

Pure and deterministic, with no model calls. Nothing in src/ is repo-specific.

Tests

  • test/test_kb_init_coverage.py: depth, folding until stable, roots never fold, nested roots, repo-root spellings terminate, exclude, unknown language, determinism, routes parsing errors, every-file module coverage, per-PR weighting, rule-bearing, ties, and longest-prefix churn.
  • The local mirror of CI passes: full pytest, doc links/citations, SPEC freshness --strict, and the knowledge linters.

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-30T09:11:24.164514Z eac94c5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eac94c5b4f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

raise ValueError("_routes.yaml must be a mapping")
if data.get("schema_version", 1) != 1:
raise ValueError(f"unsupported _routes.yaml schema_version {data.get('schema_version')!r}")
owners = data.get("owners") or []

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate falsey route collections before defaulting

When _routes.yaml contains a falsey value of the wrong type, such as owners: {} (or an owner's scope_prefixes: {}), or [] converts it into an empty list before the type check. load_owners therefore silently computes coverage with missing routes instead of raising the promised ValueError, which can skew kb init routing decisions for malformed files; only absent or null values should receive the empty-list default.

Useful? React with 👍 / 👎.

kb init (design v3 section 7) measures how much of a repository its
knowledge routes reach, first per module, then weighted by merged-PR churn.

profiles/establish.scan_modules_at_depth: directory modules at most `depth`
levels below each source root; modules under `min_loc` non-blank lines fold
into their parent until stable; roots never fold; nested roots own their
files; hidden and non-code dirs skipped at every level; exclude globs;
unknown language scans nothing.

kb_service/init_coverage: load_owners (_routes.yaml owners), routes_file,
module_coverage (every file routed), make_include, pr_weighted_coverage
(once per PR; routed and rule-bearing ratios; uncovered hot paths),
churn_by_module (longest module prefix). Pure, no repo literals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tzhouam
tzhouam merged commit a57a20c into main Sep 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant