Skip to content

Commit 2a7eb33

Browse files
committed
docs: sync help text, README, and AI docs with recent features
1 parent e635952 commit 2a7eb33

4 files changed

Lines changed: 46 additions & 14 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ grade: legacy debt never blocks a PR, only the changes do ("clean as
9393
you code"). The delta ("B 87.9 → C 77.2") renders in console, markdown
9494
(great for PR comments), and JSON.
9595

96+
On very large codebases, `--no-dup-scan` skips line-duplication
97+
collection to save memory; the health score then omits the duplication
98+
dimension (it is not scored as clean — the remaining weights are
99+
renormalized), and machine-readable output reports the scoring model as
100+
`default-no-dup` instead of `default`.
101+
96102
### Hotspot Detection
97103

98104
Find the riskiest files by combining git change frequency (churn) with code complexity — files that change often AND are complex are the most likely sources of bugs.
@@ -275,6 +281,12 @@ depth = 10
275281
276282
# Show git info
277283
git_info = true
284+
285+
# Skip line-duplication analysis (health score omits the duplication dimension)
286+
no_dup_scan = true
287+
288+
# Custom language definitions (relative paths resolve against this file's directory)
289+
languages_file = "my-langs.toml"
278290
```
279291

280292
## Custom Languages

crates/codelens/src/cli.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const STYLES: Styles = Styles::styled()
1616
#[command(
1717
name = "codelens",
1818
version,
19-
about = "High performance code analysis tool — stats, health scores, hotspots, trends, and cost estimation\n\n\
19+
about = "High performance code analysis tool — stats, health scores, hotspots, coupling, diffs, trends, and cost estimation\n\n\
2020
Author: Tiger <DropFan@Gmail.com>\n\
2121
GitHub: https://github.com/DropFan/codelens",
2222
styles = STYLES,
@@ -62,7 +62,8 @@ pub enum Command {
6262
commit. Strong coupling between files that the module structure does not connect \
6363
reveals hidden dependencies and refactoring targets. Requires a git repository.\n\n\
6464
Noise controls: --min-shared (minimum shared commits), --min-coupling (minimum \
65-
coupling percentage), --max-changeset (bulk commits above this size are ignored)."
65+
coupling percentage), --max-changeset (bulk commits above this size are ignored). \
66+
Test files are excluded by default; --include-tests restores them."
6667
)]
6768
Coupling(CouplingArgs),
6869
/// Compare two git refs: health delta, complexity delta, regressions.
@@ -167,6 +168,7 @@ pub struct CouplingArgs {
167168
pub since: String,
168169

169170
/// Only show files coupled to this file (repo-relative path).
171+
/// Pointing at a test file implies --include-tests.
170172
#[arg(long = "for", value_name = "FILE")]
171173
pub focus: Option<PathBuf>,
172174

@@ -196,7 +198,8 @@ pub struct CouplingArgs {
196198

197199
#[derive(Args, Debug)]
198200
pub struct DiffArgs {
199-
/// Base git ref, or "FROM..TO" combined form.
201+
/// Base git ref, or "FROM..TO" combined form ("FROM...TO" compares
202+
/// from the merge base).
200203
pub from: String,
201204

202205
/// Target git ref (defaults to the working tree).
@@ -365,7 +368,8 @@ pub struct FilterArgs {
365368
#[arg(short, long)]
366369
pub depth: Option<usize>,
367370

368-
/// Count extensions as another language, e.g. "jsp:html,tpl:php".
371+
/// Count extensions as another language, e.g. "jsp:html,tpl:php"
372+
/// (MATLAB repos: "m:matlab", since .m defaults to Objective-C).
369373
#[arg(long, value_name = "EXT:LANG,...")]
370374
pub count_as: Option<String>,
371375

@@ -399,9 +403,8 @@ pub struct FilterArgs {
399403
#[derive(Args, Debug)]
400404
pub struct OutputArgs {
401405
/// Output format [default: console].
402-
///
403-
/// Left as `Option` so config-file values are only overridden when the
404-
/// user explicitly passes the flag.
406+
// Left as `Option` so config-file values are only overridden when the
407+
// user explicitly passes the flag.
405408
#[arg(short, long, value_enum)]
406409
pub format: Option<OutputFormatArg>,
407410

@@ -472,8 +475,9 @@ pub struct AdvancedArgs {
472475
#[arg(long, global = true)]
473476
pub no_config: bool,
474477

475-
/// Load custom language definitions from a TOML file, merged on top
476-
/// of the built-in languages (verify with --list-languages).
478+
/// Load custom language definitions from a TOML file, added on top
479+
/// of the built-in languages; a definition with the same id replaces
480+
/// the built-in entirely (verify with --list-languages).
477481
#[arg(long, global = true, value_name = "PATH")]
478482
pub languages_file: Option<PathBuf>,
479483

@@ -562,6 +566,8 @@ const EXAMPLES: &str = "\
562566
\x1b[1;36mcodelens --top 20 --sort code\x1b[0m \x1b[2m# Show top 20 by code lines\x1b[0m
563567
\x1b[1;36mcodelens --git-info\x1b[0m \x1b[2m# Include git information\x1b[0m
564568
\x1b[1;36mcodelens --list-languages\x1b[0m \x1b[2m# List supported languages\x1b[0m
569+
\x1b[1;36mcodelens --no-dup-scan\x1b[0m \x1b[2m# Skip duplication scan (saves memory)\x1b[0m
570+
\x1b[1;36mcodelens --languages-file my.toml\x1b[0m \x1b[2m# Custom language definitions\x1b[0m
565571
566572
\x1b[1;32mHealth\x1b[0m \x1b[2m(code health score):\x1b[0m
567573
\x1b[1;36mcodelens health .\x1b[0m \x1b[2m# Health report for current directory\x1b[0m
@@ -574,6 +580,16 @@ const EXAMPLES: &str = "\
574580
\x1b[1;36mcodelens hotspot . --since 6m\x1b[0m \x1b[2m# Hotspots in last 6 months\x1b[0m
575581
\x1b[1;36mcodelens hotspot . --top 5\x1b[0m \x1b[2m# Show top 5 hotspots\x1b[0m
576582
583+
\x1b[1;32mCoupling\x1b[0m \x1b[2m(files changing together):\x1b[0m
584+
\x1b[1;36mcodelens coupling .\x1b[0m \x1b[2m# Coupled pairs, tests excluded by default\x1b[0m
585+
\x1b[1;36mcodelens coupling . --include-tests\x1b[0m \x1b[2m# Include test files\x1b[0m
586+
\x1b[1;36mcodelens coupling . --for src/api.rs\x1b[0m \x1b[2m# Files coupled to one file\x1b[0m
587+
588+
\x1b[1;32mDiff\x1b[0m \x1b[2m(compare two git refs):\x1b[0m
589+
\x1b[1;36mcodelens diff main\x1b[0m \x1b[2m# main vs working tree\x1b[0m
590+
\x1b[1;36mcodelens diff v1.0..v2.0\x1b[0m \x1b[2m# Two refs\x1b[0m
591+
\x1b[1;36mcodelens diff main --fail-on-regression\x1b[0m \x1b[2m# Gate CI on health regressions\x1b[0m
592+
577593
\x1b[1;32mTrend\x1b[0m \x1b[2m(snapshot comparison):\x1b[0m
578594
\x1b[1;36mcodelens trend --save\x1b[0m \x1b[2m# Save a snapshot\x1b[0m
579595
\x1b[1;36mcodelens trend --save --label v1.0\x1b[0m \x1b[2m# Save with label\x1b[0m

crates/codelens/src/mcp.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
//! `codelens mcp` speaks the Model Context Protocol so coding agents
44
//! (Claude Code, Cursor, ...) can query repository statistics, health
55
//! scores, hotspots, and change coupling before editing code. Tools
6-
//! return compact JSON strings mirroring the `-f json` CLI output.
6+
//! return compact JSON strings mirroring the shape of the `-f json` CLI
7+
//! output. Known divergence: `change_coupling` here pairs ALL files in
8+
//! history (no tree restriction, test files included), while the CLI
9+
//! default excludes test files.
710
811
use std::path::PathBuf;
912

@@ -53,6 +56,7 @@ pub struct GitWindowArgs {
5356
#[serde(default)]
5457
pub path: Option<String>,
5558
/// Time window like "30d", "6m", "1y", or YYYY-MM-DD; defaults to "90d".
59+
/// Only honored by hotspots and change_coupling; code_health ignores it.
5660
#[serde(default)]
5761
pub since: Option<String>,
5862
/// Maximum entries to return; defaults to 10.

docs/ai-integration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ claude mcp add codelens -- codelens mcp
2525
| `repo_overview` | 仓库概览:文件/行数/语言分布/复杂度/测试占比/token 估算 |
2626
| `code_health` | 健康报告:项目评分(A-F)、六维度得分(含重复度)、最差目录与文件 |
2727
| `hotspots` | 变更热点:又复杂又频繁改动的文件(最可能出 bug),含代码年龄与作者集中度(知识孤岛标记) |
28-
| `change_coupling` | 变更耦合:总是一起改的文件对(改 A 通常还要改 B) |
28+
| `change_coupling` | 变更耦合:总是一起改的文件对(改 A 通常还要改 B)。注意:MCP 路径目前包含测试文件,与 CLI 默认(排除测试)口径不同 |
2929
| `file_metrics` | 单文件指标:行数、圈/认知复杂度、嵌套深度、健康分 |
3030
3131
典型用法:代理在改一个文件前先查 `hotspots``change_coupling`,知道"这个文件风险多高、动它会牵连谁";改完后用 `code_health` 确认没有劣化。
@@ -38,12 +38,12 @@ MCP 属于默认开启的 cargo feature;如需更小的二进制,可用 `car
3838
3939
```bash
4040
codelens . -f json # 仓库统计(含 token 估算、测试占比、ULOC)
41-
codelens health . -f json # 健康报告(六维度
41+
codelens health . -f json # 健康报告(默认六维度;--no-dup-scan 时省略重复度维度
4242
codelens health . --baseline main -f json # 相对 main 分支的健康回归
4343
codelens diff main -f json # 改动前后健康分对比(改完代码后验证)
4444
codelens hotspot . -f json --top 10 # 热点文件(含知识孤岛)
4545
codelens hotspot . --functions -f json # 函数级热点
46-
codelens coupling . -f json # 变更耦合
46+
codelens coupling . -f json # 变更耦合(默认排除测试文件,--include-tests 找回)
4747
```
4848
4949
可以把这段加进项目的 `CLAUDE.md` / `AGENTS.md`,代理会自己学会用:
@@ -53,7 +53,7 @@ codelens coupling . -f json # 变更耦合
5353
改动前先了解风险:
5454
- `codelens health <path> -f json` — 文件健康分(A-F),低分文件谨慎重构
5555
- `codelens hotspot . -f json` — 高频修改且复杂的文件,改动需额外小心
56-
- `codelens coupling . --for <file> -f json` — 改这个文件通常还要同步改什么
56+
- `codelens coupling . --for <file> -f json` — 改这个文件通常还要同步改什么(默认不含测试文件配对,需要含测试时加 --include-tests)
5757
```
5858
5959
## 上下文窗口预估

0 commit comments

Comments
 (0)