@getcodesentinel/codesentinel 1.41.0 → 1.42.1

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
@@ -477,6 +477,137 @@ This measures system risk, not individual performance. No owner or author rankin
477
477
  - Identity matching is heuristic (noreply address, email local part, display name, alias map in `.codesentinel/owners.json`).
478
478
  - Machine accounts are excluded by the built-in author patterns; add repository-specific patterns with `ignoreAuthors` in `.codesentinel/owners.json` or `--ignore-author <glob>`.
479
479
 
480
+ ## Reading Path
481
+
482
+ `codesentinel path` prints an ordered, explainable reading path for a module directory or a single file. It uses the existing CodeSentinel structural graph, git evolution history and, when present, `CODEOWNERS`. The command is offline, local and deterministic: the same repository state produces the same output.
483
+
484
+ ### Quickstart
485
+
486
+ ```bash
487
+ codesentinel path packages/ownership
488
+ ```
489
+
490
+ ### Sample output
491
+
492
+ The following is the real console output for `packages/ownership`:
493
+
494
+ ```text
495
+ Reading path: packages/ownership (directory)
496
+ 8 steps (truncated)
497
+
498
+ 1. packages/ownership/src/index.ts [entry]
499
+ entry: highest external fan-in (4 imports from outside the module)
500
+ owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 3 · churn 99 · fan-in 0
501
+ 2. packages/ownership/src/domain/codeowners.ts [core]
502
+ most changed together with packages/ownership/src/index.ts (3 commits)
503
+ owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 4 · churn 135 · fan-in 8
504
+ 3. packages/ownership/src/application/audit-ownership.ts [helper]
505
+ most changed together with packages/ownership/src/domain/codeowners.ts (3 commits)
506
+ owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 3 · churn 392 · fan-in 2
507
+ tests: packages/ownership/src/application/audit-ownership.test.ts
508
+ 4. packages/ownership/src/domain/classify.ts [core]
509
+ most changed together with packages/ownership/src/application/audit-ownership.ts (3 commits)
510
+ owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 3 · churn 215 · fan-in 4
511
+ tests: packages/ownership/src/domain/classify.test.ts
512
+ 5. packages/ownership/src/domain/identity.ts [core]
513
+ central inside the module: 4 importers
514
+ owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 1 · churn 62 · fan-in 4
515
+ 6. packages/ownership/src/application/ignore-authors.ts [core]
516
+ central inside the module: 5 importers
517
+ owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 1 · churn 68 · fan-in 5
518
+ tests: packages/ownership/src/application/ignore-authors.test.ts
519
+ 7. packages/ownership/src/application/resolve-identities.ts [helper]
520
+ most churned neighbour (348 lines changed)
521
+ owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 2 · churn 348 · fan-in 3
522
+ tests: packages/ownership/src/application/resolve-identities.test.ts
523
+ 8. packages/ownership/src/application/parse-codeowners.ts [core]
524
+ central inside the module: 4 importers
525
+ owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 1 · churn 157 · fan-in 4
526
+ tests: packages/ownership/src/application/parse-codeowners.test.ts
527
+
528
+ People to ask
529
+ - aleixalonso@hotmail.com (18 commits): packages/ownership/src/application/audit-ownership.ts, packages/ownership/src/application/ignore-authors.ts, packages/ownership/src/application/parse-codeowners.ts, packages/ownership/src/application/resolve-identities.ts, packages/ownership/src/domain/classify.ts, packages/ownership/src/domain/codeowners.ts, packages/ownership/src/domain/identity.ts, packages/ownership/src/index.ts
530
+
531
+ Suggested commands (not discovered, not run)
532
+ - pnpm test
533
+
534
+ Warnings
535
+ - showing 8 of 10 files (truncated)
536
+ ```
537
+
538
+ ### Flags
539
+
540
+ | Flag | Description |
541
+ | ---------------------- | --------------------------------------------------------------------------------------------------------- |
542
+ | `target` | File or directory to read, relative to the repository root. |
543
+ | `--max-steps <count>` | Maximum number of files in the reading path (1..25). Default `8`. |
544
+ | `--format <mode>` | Output format: `console` (default), `md` or `json`. |
545
+ | `--output <file>` | Write the rendered output to a file instead of stdout. |
546
+ | `--window-days <days>` | Ownership observation window in days. Default `90`. |
547
+ | `--include-tests` | Include test files as their own steps instead of attaching them to their source. |
548
+ | `--ref <ref>` | Git ref to read CODEOWNERS and the tracked history from. Default `HEAD`. |
549
+ | `--log-level <level>` | Log verbosity: `silent`, `error`, `warn`, `info` or `debug` (logs are written to stderr). Default `info`. |
550
+
551
+ ### Formats
552
+
553
+ `console` is the default. `md` produces the same content as a Markdown document that drops into a pull request. `json` emits a stable payload that is byte-identical across runs on the same repository state.
554
+
555
+ ```json
556
+ {
557
+ "schemaVersion": "codesentinel.path.v1",
558
+ "target": "packages/ownership",
559
+ "targetKind": "directory",
560
+ "steps": [
561
+ {
562
+ "order": 1,
563
+ "filePath": "packages/ownership/src/index.ts",
564
+ "role": "entry",
565
+ "reason": "entry: highest external fan-in (4 imports from outside the module)",
566
+ "owner": [
567
+ {
568
+ "kind": "user",
569
+ "handle": "aleixalonso"
570
+ }
571
+ ],
572
+ "observedTopAuthor": "aleixalonso@hotmail.com",
573
+ "commits": 3,
574
+ "churn": 99,
575
+ "fanInInternal": 0,
576
+ ...
577
+ ```
578
+
579
+ The payload keys are `schemaVersion`, `target`, `targetKind`, `steps`, `people`, `commands`, `warnings`, `truncated`.
580
+
581
+ ### How the order is chosen
582
+
583
+ The entry step is chosen in five steps:
584
+
585
+ 1. **Seed file.** When the target is a single file, that file is the entry.
586
+ 2. **Single-file module.** When the steppable universe contains a single file, that file is the entry.
587
+ 3. **Package index.** For a directory target, a file directly at the target root is the entry when it is named `index.ts`, `index.tsx`, `main.ts`, `mod.ts` or `public-api.ts` (checked in that order). The file must be part of the steppable universe: a test file excluded by default does not trigger this rule.
588
+ 4. **Highest external fan-in.** Otherwise the file with the most imports from outside the module is the entry. When several files share that maximum, the one with the highest internal fan-out wins: the file that imports the most distinct files inside the module. This tie-break reports `entry: highest internal fan-out (N imports inside the module)`. If the fan-out maximum is zero, or files still tie, the shortest path and then alphabetical order decide, and the reason reports the external-fan-in rule.
589
+ 5. **Highest internal fan-in.** When every file has zero external fan-in, the file with the most importers inside the module is the entry. Ties use the same shortest-then-alphabetical breakers.
590
+
591
+ A single-file target still starts at that file. From there a greedy walk scores change coupling at 0.5, internal fan-in at 0.3 and churn at 0.2. When the walk is exhausted it jumps to the highest remaining internal fan-in. Every step carries the signal that selected it, and its role is one of `entry`, `core`, `helper` or `test`. The git-only fallback (no structural graph) orders by churn and change coupling and does not apply the package-index rule.
592
+
593
+ ### Degraded and edge behaviour
594
+
595
+ - No `CODEOWNERS` file: `owner` is `null`.
596
+ - No structural graph: ordering falls back to git history only and a warning is emitted.
597
+ - Fewer files than `--max-steps`: `truncated` is `false`.
598
+ - More files than `--max-steps`: `truncated` is `true` and a warning records how many files were shown.
599
+ - A target outside the repository, a missing target or invalid flags exit `2`; success exits `0`.
600
+
601
+ ### Limitations
602
+
603
+ - Commits are a biased proxy for knowledge: they measure what was committed, not what is understood.
604
+ - There is no tacit knowledge signal: design discussions, reviews, incidents and conversations are invisible.
605
+ - There is no documentation-maintenance signal: documentation pages are not tracked as knowledge carriers.
606
+ - There are no collaboration or team features: no multi-repository paths, no chat, no maps and no HTML view.
607
+ - The repository must be a git work tree with tracked files.
608
+
609
+ `--ref` pins `CODEOWNERS` and the tracked history, while the structural graph and churn come from the working tree. The suggested test command is only a suggestion: nothing is discovered and nothing is run.
610
+
480
611
  ## Trend
481
612
 
482
613
  `codesentinel trend` reads snapshot JSON artifacts written by `codesentinel ci --snapshot` and prints the series over time. Snapshots are CI artifacts, not repository files: `trend` never writes history into the repository and never changes the snapshot schema.