@getcodesentinel/codesentinel 1.42.0 → 1.43.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
@@ -496,7 +496,7 @@ Reading path: packages/ownership (directory)
496
496
  8 steps (truncated)
497
497
 
498
498
  1. packages/ownership/src/index.ts [entry]
499
- external interface: 4 imports from outside the module
499
+ entry: highest external fan-in (4 imports from outside the module)
500
500
  owner: @aleixalonso · observed: aleixalonso@hotmail.com · commits 3 · churn 99 · fan-in 0
501
501
  2. packages/ownership/src/domain/codeowners.ts [core]
502
502
  most changed together with packages/ownership/src/index.ts (3 commits)
@@ -562,7 +562,7 @@ Warnings
562
562
  "order": 1,
563
563
  "filePath": "packages/ownership/src/index.ts",
564
564
  "role": "entry",
565
- "reason": "external interface: 4 imports from outside the module",
565
+ "reason": "entry: highest external fan-in (4 imports from outside the module)",
566
566
  "owner": [
567
567
  {
568
568
  "kind": "user",
@@ -580,7 +580,15 @@ The payload keys are `schemaVersion`, `target`, `targetKind`, `steps`, `people`,
580
580
 
581
581
  ### How the order is chosen
582
582
 
583
- The entry step is the file with the highest fan-in from outside the module. 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`.
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.
584
592
 
585
593
  ### Degraded and edge behaviour
586
594
 
@@ -600,6 +608,111 @@ The entry step is the file with the highest fan-in from outside the module. From
600
608
 
601
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.
602
610
 
611
+ ## MCP server
612
+
613
+ `codesentinel mcp` serves the ownership, risk, trend and reading-path data that CodeSentinel already computes to MCP clients over stdio. It uses JSON-RPC on stdin/stdout and writes every log to stderr. All tools are read-only except `run_scan`, which analyzes the repository and writes a snapshot under `.codesentinel/snapshots`.
614
+
615
+ ### Register it
616
+
617
+ Claude Code:
618
+
619
+ ```bash
620
+ claude mcp add codesentinel --env CODESENTINEL_ROOT=/absolute/path/to/repository -- codesentinel mcp
621
+ ```
622
+
623
+ Claude Desktop (`claude_desktop_config.json`):
624
+
625
+ ```json
626
+ {
627
+ "mcpServers": {
628
+ "codesentinel": {
629
+ "command": "npx",
630
+ "args": ["-y", "@getcodesentinel/mcp"],
631
+ "env": { "CODESENTINEL_ROOT": "/absolute/path/to/repository" }
632
+ }
633
+ }
634
+ }
635
+ ```
636
+
637
+ Cursor (`.cursor/mcp.json`):
638
+
639
+ ```json
640
+ {
641
+ "mcpServers": {
642
+ "codesentinel": {
643
+ "command": "npx",
644
+ "args": ["-y", "@getcodesentinel/mcp"],
645
+ "env": { "CODESENTINEL_ROOT": "/absolute/path/to/repository" }
646
+ }
647
+ }
648
+ }
649
+ ```
650
+
651
+ VS Code (`.vscode/mcp.json`):
652
+
653
+ ```json
654
+ {
655
+ "servers": {
656
+ "codesentinel": {
657
+ "type": "stdio",
658
+ "command": "npx",
659
+ "args": ["-y", "@getcodesentinel/mcp"],
660
+ "env": { "CODESENTINEL_ROOT": "/absolute/path/to/repository" }
661
+ }
662
+ }
663
+ }
664
+ ```
665
+
666
+ Set `CODESENTINEL_ROOT` whenever the client does not start the process from the repository root. `codesentinel mcp` and `npx -y @getcodesentinel/mcp` launch the same server; the wrapper only forwards arguments.
667
+
668
+ ### Tools
669
+
670
+ | Tool | Parameters | Returns | Read-only |
671
+ | ------------------ | ------------------------------------------------------------- | --------------------------------------------------------------------------------------- | --------- |
672
+ | `get_file_owner` | `path` | Declared owners, observed authorship, criticality and warnings for one tracked file. | yes |
673
+ | `get_file_risk` | `path`, `ref?` (only `HEAD`) | File risk score, normalized score, factor breakdown, hotspot rank and repository score. | yes |
674
+ | `get_reading_path` | `target`, `maxSteps?` | Ordered reading steps with roles, reasons, owners, people and suggested commands. | yes |
675
+ | `get_trend` | `metric`, `path?` (unsupported), `since?`, `until?` | Repository-level metric series from snapshot artifacts, oldest to newest. | yes |
676
+ | `list_hotspots` | `limit?`, `cursor?` | Ranked hotspots with cursor pagination. | yes |
677
+ | `run_scan` | `path?`, `changedOnly?` | Fresh analysis written to a new snapshot file, plus scope and changed-file hotspots. | no |
678
+ | `search_findings` | `path?`, `severity?`, `rule?`, `status?`, `cursor?`, `limit?` | Ownership findings with severity, status, message and CODEOWNERS line. | yes |
679
+
680
+ A real `get_file_owner` call against this repository:
681
+
682
+ ```json
683
+ {
684
+ "path": "packages/ownership/src/index.ts",
685
+ "ref": "HEAD",
686
+ "owners": [{ "kind": "user", "value": "@aleixalonso" }],
687
+ "teams": [],
688
+ "status": "aligned",
689
+ "matchLine": 1,
690
+ "topAuthor": { "id": "aleixalonso@users.noreply.github.com", "share": 1 },
691
+ "observed": {
692
+ "commits": 3,
693
+ "recentCommits": 3,
694
+ "authors": 1,
695
+ "dormant": false,
696
+ "busFactor": null,
697
+ "lastCommitUnix": 1792689223
698
+ },
699
+ "criticality": { "isCritical": true, "isHotspot": false, "fanIn": 5, "riskScore": null },
700
+ "warnings": [
701
+ "Ignored 183 commits attributed to 3 ignored authors matched by \"ignoreAuthors\": 29139614+renovate[bot]@users.noreply.github.com, 49699333+dependabot[bot]@users.noreply.github.com, semantic-release-bot@martynus.net."
702
+ ]
703
+ }
704
+ ```
705
+
706
+ The full request/response capture is in [`docs/mcp-transcript.md`](docs/mcp-transcript.md).
707
+
708
+ ### Security
709
+
710
+ No credentials are accepted as tool arguments. Git and CI credentials come from the environment (credential helper, SSH agent or CI token), and error messages are redacted. Stdout carries only MCP messages; logs go to stderr. The server never accepts a token, password or remote URL as a tool input.
711
+
712
+ ### Trend source
713
+
714
+ `get_trend` reads snapshots from `CODESENTINEL_SNAPSHOTS_DIR`, defaulting to `<root>/.codesentinel/snapshots`. Snapshots are repository-level, so `get_trend` does not support `path`; use `search_findings` or `get_file_risk` for per-file questions.
715
+
603
716
  ## Trend
604
717
 
605
718
  `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.