@getcodesentinel/codesentinel 1.33.2 → 1.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -81,7 +81,7 @@ CI example:
81
81
 
82
82
  `--baseline-ref auto` requires enough git history to resolve a baseline deterministically. In GitHub Actions, use `fetch-depth: 0` and ensure the CI base branch ref is fetched.
83
83
 
84
- A full workflow template is available at `examples/github-actions/codesentinel-ci.yml`.
84
+ A full workflow template is available at `examples/github-actions/codesentinel-ci.yml`. For a faster setup, run `codesentinel init` in the repository root instead of copying the example: it writes the workflow and, when a `CODEOWNERS` file exists, the ownership configuration.
85
85
 
86
86
  ## Vision
87
87
 
@@ -114,6 +114,7 @@ The goal is a practical, engineering-grade model that supports both strategic ar
114
114
  - `packages/health-engine`: health posture aggregation and scoring model.
115
115
  - `packages/reporter`: structured report output (console, JSON, CI).
116
116
  - `packages/governance`: CI gate evaluation and enforcement policy checks.
117
+ - `packages/ownership`: declared ownership signals (CODEOWNERS parsing and matching).
117
118
  - `packages/cli`: user-facing CLI entrypoint.
118
119
 
119
120
  Each package is standalone, ESM-only, TypeScript-first, and built with `tsup`. The CLI depends on `core`; domain packages are kept decoupled to avoid circular dependencies.
@@ -148,6 +149,8 @@ codesentinel explain [path]
148
149
  codesentinel report [path]
149
150
  codesentinel check [path]
150
151
  codesentinel ci [path]
152
+ codesentinel owners [path]
153
+ codesentinel init [path]
151
154
  codesentinel dependency-risk <dependency[@version]>
152
155
  codesentinel update
153
156
  ```
@@ -172,6 +175,12 @@ codesentinel check --compare baseline.json --max-risk-delta 0.03 --no-new-cycles
172
175
  codesentinel ci --baseline baseline.json --snapshot current.json --report report.md --fail-on error
173
176
  codesentinel ci --baseline-ref origin/main --max-risk-delta 0.03 --no-new-cycles
174
177
  codesentinel ci --baseline-ref auto --fail-on error
178
+ codesentinel owners
179
+ codesentinel owners . --format md --output ownership.md
180
+ codesentinel owners . --fail-on error --max-unowned-critical 0 --max-ghost-owners 2 --max-drift 0.25
181
+ codesentinel init
182
+ codesentinel init . --force
183
+ codesentinel init . --ci none --dry-run
175
184
  codesentinel dependency-risk react
176
185
  codesentinel dependency-risk react@19.0.0
177
186
  codesentinel update
@@ -179,6 +188,10 @@ codesentinel update
179
188
 
180
189
  Use `codesentinel update` to manually check for a newer CLI release and install it without waiting for the startup notifier.
181
190
 
191
+ `codesentinel owners` cross-checks the owners declared in `CODEOWNERS` with the authors that history proves. It is offline, reads the `CODEOWNERS` file and the tracked tree from `--ref` so CI and a local run measure the same revision, and exits with `0` when the audit ran, `1` when a configured threshold is exceeded under `--fail-on error`, and `2` on a configuration or parse error (an untracked `CODEOWNERS`, an invalid flag value, or a file above GitHub's 3 MB limit). A repository without a `CODEOWNERS` file reports `available: false` and still exits `0`.
192
+
193
+ `codesentinel init [path]` scaffolds a working CI setup in the target repository. It writes `.github/workflows/codesentinel.yml` and, when a `CODEOWNERS` file exists, `.codesentinel/owners.json`. The workflow runs `codesentinel ci --baseline-ref auto --fail-on error --snapshot codesentinel-snapshot.json`, builds an ownership report when a `CODEOWNERS` file is present, and uploads both artifacts with 90-day retention. Use `--force` to overwrite existing generated files, `--ci none` to skip the workflow (for example when CI lives elsewhere), or `--dry-run` to print what would be written without changing anything. Existing files are never overwritten without `--force`, and the command never edits `package.json`.
194
+
182
195
  Author identity mode:
183
196
 
184
197
  ```bash
@@ -306,8 +319,15 @@ Supported gates:
306
319
  - `--max-risk-score <score>`
307
320
  - `--min-health-score <score>`
308
321
  - `--new-hotspot-score-threshold <score>`
322
+ - `--max-unowned-critical <count>` (ci only; requires a `CODEOWNERS` file)
323
+ - `--max-ghost-owners <count>` (ci only; requires a `CODEOWNERS` file)
324
+ - `--max-drift <ratio>` (ci only; requires a `CODEOWNERS` file)
309
325
  - `--fail-on error|warn`
310
326
 
327
+ The ownership gates are a no-op with an explicit warning when no `CODEOWNERS` file is found. They never pass silently.
328
+
329
+ Ownership violations are error-level, so `--fail-on` never softens them; `--fail-on warn` only adds warn-level gates such as `--max-new-hotspots`.
330
+
311
331
  `codesentinel ci` orchestrates snapshot + diff + gate evaluation + markdown summary generation.
312
332
 
313
333
  Baseline input modes:
@@ -347,6 +367,74 @@ Exit codes:
347
367
  - `3`: invalid configuration
348
368
  - `4`: internal execution error
349
369
 
370
+ ## Ownership Audit
371
+
372
+ `codesentinel owners` cross-checks the owners declared in `CODEOWNERS` against the authors that git history proves, and reports coverage, drift, ghost owners and unowned critical files. The audit is offline by contract: it reads the `CODEOWNERS` file and the tracked tree from `--ref` (default `HEAD`), so CI and a local run measure the same revision.
373
+
374
+ ### Quickstart
375
+
376
+ ```bash
377
+ codesentinel owners
378
+ codesentinel owners . --format md --output ownership.md
379
+ codesentinel ci --max-unowned-critical 0 --max-ghost-owners 2 --max-drift 0.25 --fail-on error
380
+ ```
381
+
382
+ ### Sample output
383
+
384
+ The following is illustrative output from a small four-file repository (plus its `CODEOWNERS` file), run with `--min-commits 2`:
385
+
386
+ ```
387
+ Ownership audit — 5 tracked files, window 90d, ref HEAD
388
+ CODEOWNERS CODEOWNERS · 3 entries · 0 invalid lines
389
+
390
+ Declared coverage: 60% (3/5)
391
+ Critical coverage: 0% (0/1)
392
+ Drift: 33.33% (1/3 declared files)
393
+ Owners without activity: 1 owner
394
+ Unowned critical: 1
395
+ Single-owner modules: 3
396
+
397
+ Unowned critical
398
+ scripts/deploy.txt fan-in n/a commits 6 authors 1
399
+
400
+ Drift — declared owner is not the top recent author
401
+ api/webhooks.txt declared @alice observed dave@example.com (75%)
402
+
403
+ Ghost owners — declared, no commits in the window
404
+ @carol docs/guide.txt
405
+
406
+ Warnings
407
+ - No structural analysis available: criticality falls back to hotspots and churn (p90).
408
+ ```
409
+
410
+ ### What the statuses mean
411
+
412
+ - `aligned`: a declared owner is the top author for the file's activity horizon.
413
+ - `drifted`: the file has a declaration, but the top author is not one of the declared owners. A dormant file is compared against its lifetime top author.
414
+ - `ghosted`: no declared owner has **verified** activity inside the window, and every declared owner is verifiable. A file that is merely dormant (the owner touched it historically, nothing in the window) is not ghosted.
415
+ - `unowned`: no `CODEOWNERS` pattern matches the file, or the winning entry has no owners.
416
+ - `unowned-critical`: an unowned file is also critical (structural fan-in, hotspot, risk or churn fallback).
417
+ - `insufficient-evidence`: fewer lifetime commits than `--min-commits`; no verdict is emitted.
418
+ - `unknown`: the audit degraded (an unexpanded team, an unresolved alias). It is not a verdict on the file. An unexpanded team (`@org/team` while offline) is `unknown`, never `ghosted`: absence of evidence is not evidence of absence.
419
+
420
+ ### The metric that matters
421
+
422
+ Coverage over critical files (`declaredCoverageCriticalPercent`) is the metric to watch. A single `* @someone` line takes flat coverage to 100% while the critical files that carry the risk stay orphaned.
423
+
424
+ ### Ethics
425
+
426
+ This measures system risk, not individual performance. No owner or author ranking is emitted, drift is a coordination signal rather than a fault, and the audit must not be used to evaluate people.
427
+
428
+ ### Known limitations
429
+
430
+ - No `!` negation and no `[ ]` character classes: they are literal characters, same as GitHub.
431
+ - Matching is case-sensitive on every platform, including macOS.
432
+ - A `CODEOWNERS` file above 3 MB is rejected (`codeowners_too_large`).
433
+ - `CODEOWNERS` is read per ref/branch, so a run measures the ref you pass, and a PR that edits `CODEOWNERS` is measured against the base ref in CI.
434
+ - Teams are opaque offline and stay `unknown` unless resolved; `--resolve-github` is accepted but not implemented in this iteration.
435
+ - The universe is tracked files only: untracked, ignored and binary-only files are out of scope.
436
+ - Identity matching is heuristic (noreply address, email local part, display name, alias map in `.codesentinel/owners.json`).
437
+
350
438
  ## Explain Output
351
439
 
352
440
  `codesentinel explain` uses the same risk-engine scoring model as `analyze` and adds structured explanation traces.