Repository navigation
kb init: depth-bounded module scan and route coverage metrics - #240
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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 [] |
There was a problem hiding this comment.
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 👍 / 👎.
eac94c5 to
3d488b0
Compare
67f6bf2 to
346f545
Compare
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>
346f545 to
bebee98
Compare
Summary
Part 4/9 of kb init (design v3, sol-approved): the coverage measures that decide what
kb initmust 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 mostdepthlevels below each source root. Deeper files belong to the deepest such ancestor. Modules undermin_locnon-blank lines fold into their parent, deepest first, until stable. Source roots never fold (normalize_rootcanonicalises.,./pkg,/pkg/, so folding always terminates). Nested roots own their files, hidden and non-code dirs are skipped at every level,excludefnmatch globs apply, and an unknown language returns{}.kb_service/init_coverage:load_ownersreads the_routes.yamlowners.routes_filematches by prefix.module_coverage: a module counts as covered only if every file in it is routed.make_includebuilds the path filter. Tests and docs are excluded through caller globs only, with no repo literals.pr_weighted_coveragecounts each file once per PR and reports routed and rule-bearing ratios, plus the uncovered hot paths.churn_by_moduleassigns 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.--strict, and the knowledge linters.🤖 Generated with Claude Code