dsh-svn-review 0.2.4 → 0.2.6
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 +124 -124
- package/README.zh.md +139 -139
- package/lib/detect.js +20 -6
- package/lib/index.js +30 -7
- package/package.json +1 -1
- package/rules/PROMPT.md +57 -11
- package/rules/REVIEW_RULES.md +55 -22
- package/rules/SVN_WORKFLOW.md +3 -3
- package/rules/languages/cpp.md +1 -1
- package/rules/languages/csharp.md +1 -1
- package/rules/languages/java.md +230 -0
- package/rules/languages/javascript.md +1 -1
- package/rules/languages/java8.md +0 -167
package/README.md
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
# dsh-svn-review
|
|
2
|
-
|
|
3
|
-
Two things a code review needs before it can be right: **which files actually changed**, and **what kind of project this is**.
|
|
4
|
-
|
|
5
|
-
This plugin answers both, offline, with no `svn.exe` and no arguments.
|
|
6
|
-
|
|
7
|
-
## Why
|
|
8
|
-
|
|
9
|
-
**Scope.** SVN hides its change set behind a GUI on most machines — the TortoiseSVN commit dialog, the "Check for modifications" menu item. `svn status` gives the same answer, but plenty of installs only ship the GUI shell. The agent is exactly the party that needs that list. Without it you re-paste the rules every time and hope it stays in scope; with it, going out of scope becomes something a tool can check.
|
|
10
|
-
|
|
11
|
-
**Language.** "This could be a null pointer" is a real defect in Java and a false positive in TypeScript that already uses `?.`. "Add a lock" is good advice in a multi-threaded Java service and meaningless in a single-threaded JavaScript process. A reviewer that does not know the language produces confident nonsense — so this plugin pins down the language and version first, then hands over the matching rule file.
|
|
12
|
-
|
|
13
|
-
## Install
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
dsh plugin --profile web add dsh-svn-review
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
Refresh the page afterwards; a restart is usually not needed.
|
|
20
|
-
|
|
21
|
-
## What you get
|
|
22
|
-
|
|
23
|
-
| Name | Kind | Description |
|
|
24
|
-
|---|---|---|
|
|
25
|
-
| `svn_change_set` | tool | The working copy's change set: `M` modified, `A` added, `D` deleted, `!` missing, `C` conflicted — plus a summary of the detected stack |
|
|
26
|
-
| `project_profile` | tool | Language, version, build system, test infrastructure, and **which rule file to load** |
|
|
27
|
-
|
|
28
|
-
Both take one optional `path` (any directory inside the working copy; it walks up to `.svn/wc.db`).
|
|
29
|
-
|
|
30
|
-
### `project_profile`
|
|
31
|
-
|
|
32
|
-
| Field | Meaning |
|
|
33
|
-
|---|---|
|
|
34
|
-
| `languages[].language` / `.version` | Detected stack. `version: null` means *detected but undeclared* — never a guessed default |
|
|
35
|
-
| `languages[].file` | Absolute path to the language rule file. Read this before writing any finding |
|
|
36
|
-
| `languages[].available` | `false` when no rule file covers that language/version, with a `reason` |
|
|
37
|
-
| `languages[].evidence` | The exact build-file line the detection came from, so you can check it |
|
|
38
|
-
| `projectName` | Detected project name, used to look up `projects/<name>.md` |
|
|
39
|
-
| `build` | `gradle` / `maven` / `cmake` / `msbuild` / `npm` / `cargo` / … |
|
|
40
|
-
| `testInfra` | Test framework and version, if any. Empty means "add a unit test" is not an actionable suggestion |
|
|
41
|
-
| `concurrencyHints` | Concurrency-related dependencies found in build files. A hint, never a verdict |
|
|
42
|
-
| `rules` | Paths to the common rule files and to the project profile, if one exists |
|
|
43
|
-
|
|
44
|
-
Detected from build and project files:
|
|
45
|
-
|
|
46
|
-
| Language | Markers | Version source |
|
|
47
|
-
|---|---|---|
|
|
48
|
-
| Java | `build.gradle`, `pom.xml`, `*.java` | `sourceCompatibility`, `maven.compiler.source`, `java.version` |
|
|
49
|
-
| C / C++ | `CMakeLists.txt`, `Makefile`, `*.vcxproj` | `CMAKE_CXX_STANDARD`, `-std=c++NN`, `LanguageStandard` |
|
|
50
|
-
| C# | `*.csproj` | `TargetFramework`, `LangVersion` |
|
|
51
|
-
| JavaScript / TypeScript | `package.json`, `tsconfig.json` | `engines.node`, `typescript` version |
|
|
52
|
-
| Go | `go.mod` | `go` directive |
|
|
53
|
-
| Rust | `Cargo.toml` | `edition` |
|
|
54
|
-
| Python | `pyproject.toml`, `.python-version` | `requires-python` |
|
|
55
|
-
| Kotlin | `build.gradle(.kts)` kotlin plugin, `*.kt` | plugin version |
|
|
56
|
-
| HarmonyOS ArkTS | `build-profile.json5`, `module.json5`, `*.ets` | `compatibleSdkVersion` |
|
|
57
|
-
| Swift | `Package.swift`, `*.xcodeproj` | `swift-tools-version` |
|
|
58
|
-
| Dart / Flutter | `pubspec.yaml` | `sdk` constraint |
|
|
59
|
-
| PHP / Ruby / Scala | `composer.json`, `Gemfile`, `build.sbt` | `require.php`, `ruby`, `scalaVersion` |
|
|
60
|
-
| **anything else** | source file extensions | none — falls back to `generic.md` |
|
|
61
|
-
|
|
62
|
-
Detection runs two passes: build files give an authoritative **version**, and an extension census
|
|
63
|
-
(3000 files, 6 levels, skipping vendored directories) catches languages that ship no build file at
|
|
64
|
-
all — a Lua or Elixir repo still lands on a profile instead of "unknown".
|
|
65
|
-
|
|
66
|
-
Build scripts are often GBK-encoded, so matching happens on the raw bytes rather than a decoded string — the ASCII directives survive either way.
|
|
67
|
-
|
|
68
|
-
## Language rule files
|
|
69
|
-
|
|
70
|
-
The package ships a rule set under `rules/`:
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
rules/
|
|
74
|
-
├─ REVIEW_RULES.md methodology: scope, severity, evidence, verdict
|
|
75
|
-
├─ SVN_WORKFLOW.md what counts as in-scope for edits
|
|
76
|
-
├─ PROMPT.md ready-to-paste commands
|
|
77
|
-
├─ languages/
|
|
78
|
-
│ ├─
|
|
79
|
-
│ ├─ kotlin.md Kotlin
|
|
80
|
-
│ ├─ cpp.md C / C++
|
|
81
|
-
│ ├─ csharp.md C#
|
|
82
|
-
│ ├─ javascript.md JavaScript / TypeScript
|
|
83
|
-
│ ├─ rust.md Rust
|
|
84
|
-
│ ├─ go.md Go
|
|
85
|
-
│ ├─ python.md Python
|
|
86
|
-
│ ├─ arkts.md HarmonyOS ArkTS
|
|
87
|
-
│ └─ generic.md fallback for any other language
|
|
88
|
-
└─ projects/_template.md template for a project-specific profile
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Each language file has the same shape: version constraints, idioms, real defects, and — the part that matters most — **a false-positive list**, meaning the findings that are wrong in that language specifically.
|
|
92
|
-
|
|
93
|
-
To use your own rule set instead of the bundled one, either set `DSH_SVN_REVIEW_RULES` or drop a `rules/local.json` (git- and npm-ignored) next to the package:
|
|
94
|
-
|
|
95
|
-
```json
|
|
96
|
-
{ "rulesRoot": "E:\\rules\\ai_code_review_files" }
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
`node tools/sync-rules.mjs` copies the shared rule files from a local rule set into the package before publishing.
|
|
100
|
-
|
|
101
|
-
## How the change set is decided
|
|
102
|
-
|
|
103
|
-
`NODES` records a base checksum and a commit-time snapshot (size, mtime) for every versioned file.
|
|
104
|
-
|
|
105
|
-
1. File gone → `!`
|
|
106
|
-
2. Size differs from the snapshot → `M`, decided without reading the file
|
|
107
|
-
3. Size and mtime both match the snapshot → skip, considered untouched
|
|
108
|
-
4. Same size, different mtime → SHA-1 the file and compare against the base checksum before calling it `M`
|
|
109
|
-
|
|
110
|
-
Step 3 matters: hashing every file in a several-thousand-file working copy takes a dozen seconds, while the fast path lands under one. Step 4 makes sure an edit that kept the length is still caught.
|
|
111
|
-
|
|
112
|
-
`A` / `D` come from nodes with `op_depth > 0`; conflicts come from `ACTUAL_NODE`.
|
|
113
|
-
|
|
114
|
-
## Limits
|
|
115
|
-
|
|
116
|
-
- No `?` (unversioned files). They cannot enter this commit, so they are not part of the change scope.
|
|
117
|
-
- No diff. Once you have the file list, the agent's own file-reading tool is a better fit than a diff grown inside the plugin.
|
|
118
|
-
- Requires Node's built-in `node:sqlite` (Node 22.5+; unflagged since 23.4). On an older host the tool says so instead of throwing a SQLite stack.
|
|
119
|
-
- Opens `.svn/wc.db` read-only and writes nothing into the working copy.
|
|
120
|
-
- Language detection reads build and project files only. It cannot infer a concurrency model — that belongs in a project profile.
|
|
121
|
-
|
|
122
|
-
## License
|
|
123
|
-
|
|
124
|
-
MIT
|
|
1
|
+
# dsh-svn-review
|
|
2
|
+
|
|
3
|
+
Two things a code review needs before it can be right: **which files actually changed**, and **what kind of project this is**.
|
|
4
|
+
|
|
5
|
+
This plugin answers both, offline, with no `svn.exe` and no arguments.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
**Scope.** SVN hides its change set behind a GUI on most machines — the TortoiseSVN commit dialog, the "Check for modifications" menu item. `svn status` gives the same answer, but plenty of installs only ship the GUI shell. The agent is exactly the party that needs that list. Without it you re-paste the rules every time and hope it stays in scope; with it, going out of scope becomes something a tool can check.
|
|
10
|
+
|
|
11
|
+
**Language.** "This could be a null pointer" is a real defect in Java and a false positive in TypeScript that already uses `?.`. "Add a lock" is good advice in a multi-threaded Java service and meaningless in a single-threaded JavaScript process. A reviewer that does not know the language produces confident nonsense — so this plugin pins down the language and version first, then hands over the matching rule file.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
dsh plugin --profile web add dsh-svn-review
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Refresh the page afterwards; a restart is usually not needed.
|
|
20
|
+
|
|
21
|
+
## What you get
|
|
22
|
+
|
|
23
|
+
| Name | Kind | Description |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `svn_change_set` | tool | The working copy's change set: `M` modified, `A` added, `D` deleted, `!` missing, `C` conflicted — plus a summary of the detected stack |
|
|
26
|
+
| `project_profile` | tool | Language, version, build system, test infrastructure, and **which rule file to load** |
|
|
27
|
+
|
|
28
|
+
Both take one optional `path` (any directory inside the working copy; it walks up to `.svn/wc.db`).
|
|
29
|
+
|
|
30
|
+
### `project_profile`
|
|
31
|
+
|
|
32
|
+
| Field | Meaning |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `languages[].language` / `.version` | Detected stack. `version: null` means *detected but undeclared* — never a guessed default |
|
|
35
|
+
| `languages[].file` | Absolute path to the language rule file. Read this before writing any finding |
|
|
36
|
+
| `languages[].available` | `false` when no rule file covers that language/version, with a `reason` |
|
|
37
|
+
| `languages[].evidence` | The exact build-file line the detection came from, so you can check it |
|
|
38
|
+
| `projectName` | Detected project name, used to look up `projects/<name>.md` |
|
|
39
|
+
| `build` | `gradle` / `maven` / `cmake` / `msbuild` / `npm` / `cargo` / … |
|
|
40
|
+
| `testInfra` | Test framework and version, if any. Empty means "add a unit test" is not an actionable suggestion |
|
|
41
|
+
| `concurrencyHints` | Concurrency-related dependencies found in build files. A hint, never a verdict |
|
|
42
|
+
| `rules` | Paths to the common rule files and to the project profile, if one exists |
|
|
43
|
+
|
|
44
|
+
Detected from build and project files:
|
|
45
|
+
|
|
46
|
+
| Language | Markers | Version source |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| Java | `build.gradle`, `pom.xml`, `*.java` | `sourceCompatibility`, `maven.compiler.source`, `java.version` |
|
|
49
|
+
| C / C++ | `CMakeLists.txt`, `Makefile`, `*.vcxproj` | `CMAKE_CXX_STANDARD`, `-std=c++NN`, `LanguageStandard` |
|
|
50
|
+
| C# | `*.csproj` | `TargetFramework`, `LangVersion` |
|
|
51
|
+
| JavaScript / TypeScript | `package.json`, `tsconfig.json` | `engines.node`, `typescript` version |
|
|
52
|
+
| Go | `go.mod` | `go` directive |
|
|
53
|
+
| Rust | `Cargo.toml` | `edition` |
|
|
54
|
+
| Python | `pyproject.toml`, `.python-version` | `requires-python` |
|
|
55
|
+
| Kotlin | `build.gradle(.kts)` kotlin plugin, `*.kt` | plugin version |
|
|
56
|
+
| HarmonyOS ArkTS | `build-profile.json5`, `module.json5`, `*.ets` | `compatibleSdkVersion` |
|
|
57
|
+
| Swift | `Package.swift`, `*.xcodeproj` | `swift-tools-version` |
|
|
58
|
+
| Dart / Flutter | `pubspec.yaml` | `sdk` constraint |
|
|
59
|
+
| PHP / Ruby / Scala | `composer.json`, `Gemfile`, `build.sbt` | `require.php`, `ruby`, `scalaVersion` |
|
|
60
|
+
| **anything else** | source file extensions | none — falls back to `generic.md` |
|
|
61
|
+
|
|
62
|
+
Detection runs two passes: build files give an authoritative **version**, and an extension census
|
|
63
|
+
(3000 files, 6 levels, skipping vendored directories) catches languages that ship no build file at
|
|
64
|
+
all — a Lua or Elixir repo still lands on a profile instead of "unknown".
|
|
65
|
+
|
|
66
|
+
Build scripts are often GBK-encoded, so matching happens on the raw bytes rather than a decoded string — the ASCII directives survive either way.
|
|
67
|
+
|
|
68
|
+
## Language rule files
|
|
69
|
+
|
|
70
|
+
The package ships a rule set under `rules/`:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
rules/
|
|
74
|
+
├─ REVIEW_RULES.md methodology: scope, severity, evidence, verdict
|
|
75
|
+
├─ SVN_WORKFLOW.md what counts as in-scope for edits
|
|
76
|
+
├─ PROMPT.md ready-to-paste commands
|
|
77
|
+
├─ languages/
|
|
78
|
+
│ ├─ java.md Java 8
|
|
79
|
+
│ ├─ kotlin.md Kotlin
|
|
80
|
+
│ ├─ cpp.md C / C++
|
|
81
|
+
│ ├─ csharp.md C#
|
|
82
|
+
│ ├─ javascript.md JavaScript / TypeScript
|
|
83
|
+
│ ├─ rust.md Rust
|
|
84
|
+
│ ├─ go.md Go
|
|
85
|
+
│ ├─ python.md Python
|
|
86
|
+
│ ├─ arkts.md HarmonyOS ArkTS
|
|
87
|
+
│ └─ generic.md fallback for any other language
|
|
88
|
+
└─ projects/_template.md template for a project-specific profile
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Each language file has the same shape: version constraints, idioms, real defects, and — the part that matters most — **a false-positive list**, meaning the findings that are wrong in that language specifically.
|
|
92
|
+
|
|
93
|
+
To use your own rule set instead of the bundled one, either set `DSH_SVN_REVIEW_RULES` or drop a `rules/local.json` (git- and npm-ignored) next to the package:
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{ "rulesRoot": "E:\\rules\\ai_code_review_files" }
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
`node tools/sync-rules.mjs` copies the shared rule files from a local rule set into the package before publishing.
|
|
100
|
+
|
|
101
|
+
## How the change set is decided
|
|
102
|
+
|
|
103
|
+
`NODES` records a base checksum and a commit-time snapshot (size, mtime) for every versioned file.
|
|
104
|
+
|
|
105
|
+
1. File gone → `!`
|
|
106
|
+
2. Size differs from the snapshot → `M`, decided without reading the file
|
|
107
|
+
3. Size and mtime both match the snapshot → skip, considered untouched
|
|
108
|
+
4. Same size, different mtime → SHA-1 the file and compare against the base checksum before calling it `M`
|
|
109
|
+
|
|
110
|
+
Step 3 matters: hashing every file in a several-thousand-file working copy takes a dozen seconds, while the fast path lands under one. Step 4 makes sure an edit that kept the length is still caught.
|
|
111
|
+
|
|
112
|
+
`A` / `D` come from nodes with `op_depth > 0`; conflicts come from `ACTUAL_NODE`.
|
|
113
|
+
|
|
114
|
+
## Limits
|
|
115
|
+
|
|
116
|
+
- No `?` (unversioned files). They cannot enter this commit, so they are not part of the change scope.
|
|
117
|
+
- No diff. Once you have the file list, the agent's own file-reading tool is a better fit than a diff grown inside the plugin.
|
|
118
|
+
- Requires Node's built-in `node:sqlite` (Node 22.5+; unflagged since 23.4). On an older host the tool says so instead of throwing a SQLite stack.
|
|
119
|
+
- Opens `.svn/wc.db` read-only and writes nothing into the working copy.
|
|
120
|
+
- Language detection reads build and project files only. It cannot infer a concurrency model — that belongs in a project profile.
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT
|
package/README.zh.md
CHANGED
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
# dsh-svn-review
|
|
2
|
-
|
|
3
|
-
一次审查要想审得对,需要先知道两件事:**这次到底改了哪些文件**,以及**这是个什么项目**。
|
|
4
|
-
|
|
5
|
-
这个插件把两件事都做了,离线、不需要 `svn.exe`、不用传参数。
|
|
6
|
-
|
|
7
|
-
## 为什么需要它
|
|
8
|
-
|
|
9
|
-
**改动范围。** SVN 的改动集通常藏在图形界面里:TortoiseSVN 的提交对话框、右键菜单的「检查修改」。命令行 `svn status` 能给出同样的答案,但很多机器上只装了图形壳。而 Agent 恰恰最需要这份清单——没有它,你只能把规则复述一遍、再祈祷它别越界;有了它,越界就变成一个可以被工具检查的事实。
|
|
10
|
-
|
|
11
|
-
**语言与版本。** 同一句「这里可能空指针」,在 Java 里是缺陷,在已经用了 `?.` 的 TypeScript 里是误报;「建议加锁」在 Java 多线程服务里是对的,在 JS 单线程事件循环里根本无从谈起。不知道语言的审查方会一本正经地说废话——所以这个插件先把语言和版本钉死,再把对应的规则文件递过去。
|
|
12
|
-
|
|
13
|
-
## 安装
|
|
14
|
-
|
|
15
|
-
```sh
|
|
16
|
-
dsh plugin --profile web add dsh-svn-review
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
装完刷新页面即可,通常不需要重启。
|
|
20
|
-
|
|
21
|
-
## 用到的东西
|
|
22
|
-
|
|
23
|
-
| 名称 | 类型 | 说明 |
|
|
24
|
-
|---|---|---|
|
|
25
|
-
| `svn_change_set` | 工具 | 工作副本的变更集:`M` 已修改、`A` 本地新增、`D` 已删除、`!` 文件缺失、`C` 冲突;同时附带识别到的技术栈摘要 |
|
|
26
|
-
| `project_profile` | 工具 | 语言、版本、构建系统、测试基建,以及**该加载哪份规则文件** |
|
|
27
|
-
|
|
28
|
-
两个工具都只有一个可选参数 `path`(工作副本内任意目录,会自动向上找 `.svn/wc.db`)。
|
|
29
|
-
|
|
30
|
-
### `project_profile`
|
|
31
|
-
|
|
32
|
-
| 字段 | 含义 |
|
|
33
|
-
|---|---|
|
|
34
|
-
| `languages[].language` / `.version` | 识别出的技术栈。`version: null` 表示**识别到了但没声明版本**,绝不给默认值 |
|
|
35
|
-
| `languages[].file` | 语言规则文件的绝对路径。**写任何意见之前先读它** |
|
|
36
|
-
| `languages[].available` | 为 `false` 时表示没有覆盖该语言/版本的规则,并给出 `reason` |
|
|
37
|
-
| `languages[].evidence` | 判定所依据的那一行构建脚本原文,可自行核对 |
|
|
38
|
-
| `projectName` | 识别到的工程名,用于查找 `projects/<工程名>.md` |
|
|
39
|
-
| `build` | `gradle` / `maven` / `cmake` / `msbuild` / `npm` / `cargo` 等 |
|
|
40
|
-
| `testInfra` | 测试框架与版本。为空时,「建议补单元测试」就不是一条可执行的建议 |
|
|
41
|
-
| `concurrencyHints` | 构建文件里出现的并发相关依赖,**只是线索,不是结论** |
|
|
42
|
-
| `rules` | 通用规则文件与项目档案的路径 |
|
|
43
|
-
|
|
44
|
-
识别依据:
|
|
45
|
-
|
|
46
|
-
| 语言 | 识别文件 | 版本来源 |
|
|
47
|
-
|---|---|---|
|
|
48
|
-
| Java | `build.gradle`、`pom.xml`、`*.java` | `sourceCompatibility`、`maven.compiler.source`、`java.version` |
|
|
49
|
-
| C / C++ | `CMakeLists.txt`、`Makefile`、`*.vcxproj` | `CMAKE_CXX_STANDARD`、`-std=c++NN`、`LanguageStandard` |
|
|
50
|
-
| C# | `*.csproj` | `TargetFramework`、`LangVersion` |
|
|
51
|
-
| JavaScript / TypeScript | `package.json`、`tsconfig.json` | `engines.node`、`typescript` 版本 |
|
|
52
|
-
| Go | `go.mod` | `go` 指令 |
|
|
53
|
-
| Rust | `Cargo.toml` | `edition` |
|
|
54
|
-
| Python | `pyproject.toml`、`.python-version` | `requires-python` |
|
|
55
|
-
| Kotlin | `build.gradle(.kts)` 的 kotlin 插件、`*.kt` | 插件版本 |
|
|
56
|
-
| 鸿蒙 ArkTS | `build-profile.json5`、`module.json5`、`*.ets` | `compatibleSdkVersion` |
|
|
57
|
-
| Swift | `Package.swift`、`*.xcodeproj` | `swift-tools-version` |
|
|
58
|
-
| Dart / Flutter | `pubspec.yaml` | `sdk` 约束 |
|
|
59
|
-
| PHP / Ruby / Scala | `composer.json`、`Gemfile`、`build.sbt` | `require.php`、`ruby`、`scalaVersion` |
|
|
60
|
-
| **其它任何语言** | 源码扩展名 | 无 → 落到 `generic.md` |
|
|
61
|
-
|
|
62
|
-
识别跑两路:构建文件给**权威版本**,扩展名普查(3000 个文件、6 层、跳过 vendor 目录)兜住"根本没有构建文件"的语言——
|
|
63
|
-
只有 `.lua` 或 `.ex` 的仓库也能落到档案上,而不是返回"未知"。
|
|
64
|
-
|
|
65
|
-
构建脚本经常是 GBK 编码,所以判定是在**原始字节**上做的,不走解码——关键指令都是 ASCII,两条路径都能命中。
|
|
66
|
-
|
|
67
|
-
## 输出示例
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
工作目录 E:\x_japan
|
|
71
|
-
工程名 x_main
|
|
72
|
-
|
|
73
|
-
java 1.8
|
|
74
|
-
|
|
75
|
-
依据:build.gradle: sourceCompatibility = 1.8
|
|
76
|
-
|
|
77
|
-
构建系统:gradle(20 个模块)
|
|
78
|
-
测试基建:junit 4.12(Gradle 依赖中声明)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## 随包附带的规则
|
|
84
|
-
|
|
85
|
-
包里自带一套规则,装在 `rules/`:
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
rules/
|
|
89
|
-
├─ REVIEW_RULES.md 方法论:范围、分级、举证、结论
|
|
90
|
-
├─ SVN_WORKFLOW.md 什么算在改动范围内
|
|
91
|
-
├─ PROMPT.md 可直接复制的命令模板
|
|
92
|
-
├─ languages/
|
|
93
|
-
│ ├─
|
|
94
|
-
│ ├─ kotlin.md Kotlin
|
|
95
|
-
│ ├─ cpp.md C / C++
|
|
96
|
-
│ ├─ csharp.md C#
|
|
97
|
-
│ ├─ javascript.md JavaScript / TypeScript
|
|
98
|
-
│ ├─ rust.md Rust
|
|
99
|
-
│ ├─ go.md Go
|
|
100
|
-
│ ├─ python.md Python
|
|
101
|
-
│ ├─ arkts.md 鸿蒙 ArkTS
|
|
102
|
-
│ └─ generic.md 其它任何语言的兜底
|
|
103
|
-
└─ projects/_template.md 项目档案模板
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
每份语言档案结构一致:版本约束、惯用法、真实缺陷,以及最重要的一节——**误报清单**,也就是"在这个语言里说这话就是错的"。
|
|
107
|
-
|
|
108
|
-
想用自己的规则库而不是包里这份,两种方式:设 `DSH_SVN_REVIEW_RULES` 环境变量,或者在包内放一个 `rules/local.json`(已加入 git/npm 忽略):
|
|
109
|
-
|
|
110
|
-
```json
|
|
111
|
-
{ "rulesRoot": "E:\\rules\\ai_code_review_files" }
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
发布前跑 `node tools/sync-rules.mjs`,把本地规则库里通用的那几份同步进包。
|
|
115
|
-
|
|
116
|
-
## 判定方式
|
|
117
|
-
|
|
118
|
-
`.svn/wc.db` 的 `NODES` 表为每个受控文件记录了基线校验和与上次提交时的快照(大小、mtime)。
|
|
119
|
-
|
|
120
|
-
1. 文件不在了 → `!`
|
|
121
|
-
2. 大小和快照不同 → `M`,直接判定,不读文件内容
|
|
122
|
-
3. 大小与 mtime 都和快照一致 → 跳过,认为没动过
|
|
123
|
-
4. 大小相同但 mtime 不同 → 计算 SHA-1 与基线校验和比对,确认后才判定 `M`
|
|
124
|
-
|
|
125
|
-
第 3 步是关键:一个几千个文件的工作副本如果逐个算哈希要十几秒,走快路径通常不到一秒。第 4 步保证「改了但长度没变」的编辑不会漏掉。
|
|
126
|
-
|
|
127
|
-
`A` / `D` 来自 `op_depth > 0` 的节点,冲突来自 `ACTUAL_NODE`。
|
|
128
|
-
|
|
129
|
-
## 限制
|
|
130
|
-
|
|
131
|
-
- 不返回 `?`(未纳入版本控制的文件)。这类文件进不了本次提交,不构成修改范围。
|
|
132
|
-
- 不生成 diff。文件清单拿到之后,读文件用 Agent 自己的工具即可,比在插件里造一份 diff 更省事也更准确。
|
|
133
|
-
- 依赖 Node 内置的 `node:sqlite`(Node 22.5+,23.4 之后无需实验开关)。宿主 Node 太旧时,工具会明确说明而不是抛一个 SQLite 栈。
|
|
134
|
-
- 只读 `.svn/wc.db`,不写入工作副本的任何位置。
|
|
135
|
-
- 语言识别只读构建与工程文件,**推不出并发模型**——那属于项目档案的内容。
|
|
136
|
-
|
|
137
|
-
## 许可
|
|
138
|
-
|
|
139
|
-
MIT
|
|
1
|
+
# dsh-svn-review
|
|
2
|
+
|
|
3
|
+
一次审查要想审得对,需要先知道两件事:**这次到底改了哪些文件**,以及**这是个什么项目**。
|
|
4
|
+
|
|
5
|
+
这个插件把两件事都做了,离线、不需要 `svn.exe`、不用传参数。
|
|
6
|
+
|
|
7
|
+
## 为什么需要它
|
|
8
|
+
|
|
9
|
+
**改动范围。** SVN 的改动集通常藏在图形界面里:TortoiseSVN 的提交对话框、右键菜单的「检查修改」。命令行 `svn status` 能给出同样的答案,但很多机器上只装了图形壳。而 Agent 恰恰最需要这份清单——没有它,你只能把规则复述一遍、再祈祷它别越界;有了它,越界就变成一个可以被工具检查的事实。
|
|
10
|
+
|
|
11
|
+
**语言与版本。** 同一句「这里可能空指针」,在 Java 里是缺陷,在已经用了 `?.` 的 TypeScript 里是误报;「建议加锁」在 Java 多线程服务里是对的,在 JS 单线程事件循环里根本无从谈起。不知道语言的审查方会一本正经地说废话——所以这个插件先把语言和版本钉死,再把对应的规则文件递过去。
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
dsh plugin --profile web add dsh-svn-review
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
装完刷新页面即可,通常不需要重启。
|
|
20
|
+
|
|
21
|
+
## 用到的东西
|
|
22
|
+
|
|
23
|
+
| 名称 | 类型 | 说明 |
|
|
24
|
+
|---|---|---|
|
|
25
|
+
| `svn_change_set` | 工具 | 工作副本的变更集:`M` 已修改、`A` 本地新增、`D` 已删除、`!` 文件缺失、`C` 冲突;同时附带识别到的技术栈摘要 |
|
|
26
|
+
| `project_profile` | 工具 | 语言、版本、构建系统、测试基建,以及**该加载哪份规则文件** |
|
|
27
|
+
|
|
28
|
+
两个工具都只有一个可选参数 `path`(工作副本内任意目录,会自动向上找 `.svn/wc.db`)。
|
|
29
|
+
|
|
30
|
+
### `project_profile`
|
|
31
|
+
|
|
32
|
+
| 字段 | 含义 |
|
|
33
|
+
|---|---|
|
|
34
|
+
| `languages[].language` / `.version` | 识别出的技术栈。`version: null` 表示**识别到了但没声明版本**,绝不给默认值 |
|
|
35
|
+
| `languages[].file` | 语言规则文件的绝对路径。**写任何意见之前先读它** |
|
|
36
|
+
| `languages[].available` | 为 `false` 时表示没有覆盖该语言/版本的规则,并给出 `reason` |
|
|
37
|
+
| `languages[].evidence` | 判定所依据的那一行构建脚本原文,可自行核对 |
|
|
38
|
+
| `projectName` | 识别到的工程名,用于查找 `projects/<工程名>.md` |
|
|
39
|
+
| `build` | `gradle` / `maven` / `cmake` / `msbuild` / `npm` / `cargo` 等 |
|
|
40
|
+
| `testInfra` | 测试框架与版本。为空时,「建议补单元测试」就不是一条可执行的建议 |
|
|
41
|
+
| `concurrencyHints` | 构建文件里出现的并发相关依赖,**只是线索,不是结论** |
|
|
42
|
+
| `rules` | 通用规则文件与项目档案的路径 |
|
|
43
|
+
|
|
44
|
+
识别依据:
|
|
45
|
+
|
|
46
|
+
| 语言 | 识别文件 | 版本来源 |
|
|
47
|
+
|---|---|---|
|
|
48
|
+
| Java | `build.gradle`、`pom.xml`、`*.java` | `sourceCompatibility`、`maven.compiler.source`、`java.version` |
|
|
49
|
+
| C / C++ | `CMakeLists.txt`、`Makefile`、`*.vcxproj` | `CMAKE_CXX_STANDARD`、`-std=c++NN`、`LanguageStandard` |
|
|
50
|
+
| C# | `*.csproj` | `TargetFramework`、`LangVersion` |
|
|
51
|
+
| JavaScript / TypeScript | `package.json`、`tsconfig.json` | `engines.node`、`typescript` 版本 |
|
|
52
|
+
| Go | `go.mod` | `go` 指令 |
|
|
53
|
+
| Rust | `Cargo.toml` | `edition` |
|
|
54
|
+
| Python | `pyproject.toml`、`.python-version` | `requires-python` |
|
|
55
|
+
| Kotlin | `build.gradle(.kts)` 的 kotlin 插件、`*.kt` | 插件版本 |
|
|
56
|
+
| 鸿蒙 ArkTS | `build-profile.json5`、`module.json5`、`*.ets` | `compatibleSdkVersion` |
|
|
57
|
+
| Swift | `Package.swift`、`*.xcodeproj` | `swift-tools-version` |
|
|
58
|
+
| Dart / Flutter | `pubspec.yaml` | `sdk` 约束 |
|
|
59
|
+
| PHP / Ruby / Scala | `composer.json`、`Gemfile`、`build.sbt` | `require.php`、`ruby`、`scalaVersion` |
|
|
60
|
+
| **其它任何语言** | 源码扩展名 | 无 → 落到 `generic.md` |
|
|
61
|
+
|
|
62
|
+
识别跑两路:构建文件给**权威版本**,扩展名普查(3000 个文件、6 层、跳过 vendor 目录)兜住"根本没有构建文件"的语言——
|
|
63
|
+
只有 `.lua` 或 `.ex` 的仓库也能落到档案上,而不是返回"未知"。
|
|
64
|
+
|
|
65
|
+
构建脚本经常是 GBK 编码,所以判定是在**原始字节**上做的,不走解码——关键指令都是 ASCII,两条路径都能命中。
|
|
66
|
+
|
|
67
|
+
## 输出示例
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
工作目录 E:\x_japan
|
|
71
|
+
工程名 x_main
|
|
72
|
+
|
|
73
|
+
java 1.8
|
|
74
|
+
规范:规则库\languages\java.md
|
|
75
|
+
依据:build.gradle: sourceCompatibility = 1.8
|
|
76
|
+
|
|
77
|
+
构建系统:gradle(20 个模块)
|
|
78
|
+
测试基建:junit 4.12(Gradle 依赖中声明)
|
|
79
|
+
|
|
80
|
+
项目档案:规则库\projects\x_main.md
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 随包附带的规则
|
|
84
|
+
|
|
85
|
+
包里自带一套规则,装在 `rules/`:
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
rules/
|
|
89
|
+
├─ REVIEW_RULES.md 方法论:范围、分级、举证、结论
|
|
90
|
+
├─ SVN_WORKFLOW.md 什么算在改动范围内
|
|
91
|
+
├─ PROMPT.md 可直接复制的命令模板
|
|
92
|
+
├─ languages/
|
|
93
|
+
│ ├─ java.md Java 8
|
|
94
|
+
│ ├─ kotlin.md Kotlin
|
|
95
|
+
│ ├─ cpp.md C / C++
|
|
96
|
+
│ ├─ csharp.md C#
|
|
97
|
+
│ ├─ javascript.md JavaScript / TypeScript
|
|
98
|
+
│ ├─ rust.md Rust
|
|
99
|
+
│ ├─ go.md Go
|
|
100
|
+
│ ├─ python.md Python
|
|
101
|
+
│ ├─ arkts.md 鸿蒙 ArkTS
|
|
102
|
+
│ └─ generic.md 其它任何语言的兜底
|
|
103
|
+
└─ projects/_template.md 项目档案模板
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
每份语言档案结构一致:版本约束、惯用法、真实缺陷,以及最重要的一节——**误报清单**,也就是"在这个语言里说这话就是错的"。
|
|
107
|
+
|
|
108
|
+
想用自己的规则库而不是包里这份,两种方式:设 `DSH_SVN_REVIEW_RULES` 环境变量,或者在包内放一个 `rules/local.json`(已加入 git/npm 忽略):
|
|
109
|
+
|
|
110
|
+
```json
|
|
111
|
+
{ "rulesRoot": "E:\\rules\\ai_code_review_files" }
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
发布前跑 `node tools/sync-rules.mjs`,把本地规则库里通用的那几份同步进包。
|
|
115
|
+
|
|
116
|
+
## 判定方式
|
|
117
|
+
|
|
118
|
+
`.svn/wc.db` 的 `NODES` 表为每个受控文件记录了基线校验和与上次提交时的快照(大小、mtime)。
|
|
119
|
+
|
|
120
|
+
1. 文件不在了 → `!`
|
|
121
|
+
2. 大小和快照不同 → `M`,直接判定,不读文件内容
|
|
122
|
+
3. 大小与 mtime 都和快照一致 → 跳过,认为没动过
|
|
123
|
+
4. 大小相同但 mtime 不同 → 计算 SHA-1 与基线校验和比对,确认后才判定 `M`
|
|
124
|
+
|
|
125
|
+
第 3 步是关键:一个几千个文件的工作副本如果逐个算哈希要十几秒,走快路径通常不到一秒。第 4 步保证「改了但长度没变」的编辑不会漏掉。
|
|
126
|
+
|
|
127
|
+
`A` / `D` 来自 `op_depth > 0` 的节点,冲突来自 `ACTUAL_NODE`。
|
|
128
|
+
|
|
129
|
+
## 限制
|
|
130
|
+
|
|
131
|
+
- 不返回 `?`(未纳入版本控制的文件)。这类文件进不了本次提交,不构成修改范围。
|
|
132
|
+
- 不生成 diff。文件清单拿到之后,读文件用 Agent 自己的工具即可,比在插件里造一份 diff 更省事也更准确。
|
|
133
|
+
- 依赖 Node 内置的 `node:sqlite`(Node 22.5+,23.4 之后无需实验开关)。宿主 Node 太旧时,工具会明确说明而不是抛一个 SQLite 栈。
|
|
134
|
+
- 只读 `.svn/wc.db`,不写入工作副本的任何位置。
|
|
135
|
+
- 语言识别只读构建与工程文件,**推不出并发模型**——那属于项目档案的内容。
|
|
136
|
+
|
|
137
|
+
## 许可
|
|
138
|
+
|
|
139
|
+
MIT
|
package/lib/detect.js
CHANGED
|
@@ -716,9 +716,15 @@ export function detectProject(start = process.cwd()) {
|
|
|
716
716
|
}
|
|
717
717
|
}
|
|
718
718
|
|
|
719
|
-
/**
|
|
719
|
+
/**
|
|
720
|
+
* 语言 → 档案文件名(不含 .md)。没有专用档案的走 generic。
|
|
721
|
+
*
|
|
722
|
+
* 档案按语言分,不按版本分:一份 `java.md` 用版本矩阵覆盖 8/11/17/21/≥22。
|
|
723
|
+
* 早先的 `java8.md` 只写了 8 这一档,其它版本只能退回 generic,
|
|
724
|
+
* 等于把 Java 21 的工程当成无名语言审——那是错的。
|
|
725
|
+
*/
|
|
720
726
|
const PROFILE_BY_LANGUAGE = {
|
|
721
|
-
java: '
|
|
727
|
+
java: 'java',
|
|
722
728
|
kotlin: 'kotlin',
|
|
723
729
|
rust: 'rust',
|
|
724
730
|
go: 'go',
|
|
@@ -739,13 +745,21 @@ export function profileForLanguage(language) {
|
|
|
739
745
|
}
|
|
740
746
|
|
|
741
747
|
/**
|
|
742
|
-
*
|
|
743
|
-
*
|
|
748
|
+
* 版本门槛。
|
|
749
|
+
*
|
|
750
|
+
* 只拦"档案明确不覆盖"的版本,不拦"版本没探测到":
|
|
751
|
+
* 档案正文有版本矩阵,版本未知时仍能按与版本无关的通用判据审,
|
|
752
|
+
* 退回 generic 反而丢掉全部语言层知识。
|
|
753
|
+
*
|
|
754
|
+
* Java 档案覆盖 8 及以上;7 及更老的语法差异太大(没有 lambda/Stream),
|
|
755
|
+
* 与其套错不如明说没有档案。
|
|
744
756
|
*/
|
|
745
757
|
export function profileSupportsVersion(language, version) {
|
|
746
758
|
if (language !== 'java') return true
|
|
747
|
-
if (!version) return
|
|
748
|
-
|
|
759
|
+
if (!version) return true
|
|
760
|
+
const major = Number.parseInt(String(version).replace(/^(?:1\.)?(?=\d)/, ''), 10)
|
|
761
|
+
if (Number.isNaN(major)) return true
|
|
762
|
+
return major >= 8
|
|
749
763
|
}
|
|
750
764
|
|
|
751
765
|
/** 扩展名 → 语言,供上层把变更集里的文件映射到档案。 */
|
package/lib/index.js
CHANGED
|
@@ -24,11 +24,26 @@ export const inject = ['tools']
|
|
|
24
24
|
|
|
25
25
|
const HERE = dirname(fileURLToPath(import.meta.url))
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* 用户级配置目录:`%APPDATA%\dsh-svn-review`(Windows)/ `~/.config/dsh-svn-review`。
|
|
29
|
+
*
|
|
30
|
+
* 放在这里而不是包目录里,是因为包目录会被插件更新整份替换——
|
|
31
|
+
* 写在那儿的配置和项目档案,用户下次更新插件就没了(这件事已经发生过一次)。
|
|
32
|
+
*/
|
|
33
|
+
function userConfigDir() {
|
|
34
|
+
const appData = process.env.APPDATA
|
|
35
|
+
if (typeof appData === 'string' && appData.length > 0) return join(appData, 'dsh-svn-review')
|
|
36
|
+
const home = process.env.HOME ?? process.env.USERPROFILE
|
|
37
|
+
if (typeof home === 'string' && home.length > 0) return join(home, '.config', 'dsh-svn-review')
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
27
41
|
/**
|
|
28
42
|
* 规则目录解析顺序:
|
|
29
43
|
* 1. 环境变量 `DSH_SVN_REVIEW_RULES`(临时切换用)
|
|
30
|
-
* 2.
|
|
31
|
-
* 3.
|
|
44
|
+
* 2. 用户配置 `%APPDATA%\dsh-svn-review\local.json` 的 `rulesRoot`(更新插件不会丢)
|
|
45
|
+
* 3. 包内 `rules\local.json`(旧位置,仍然认,方便已有安装)
|
|
46
|
+
* 4. 包内自带的 `rules\`(市场用户默认走这里,跟着包走,任何盘都能用)
|
|
32
47
|
*/
|
|
33
48
|
function rulesRoot() {
|
|
34
49
|
const override = process.env.DSH_SVN_REVIEW_RULES
|
|
@@ -40,10 +55,16 @@ function rulesRoot() {
|
|
|
40
55
|
/* 落回下一层 */
|
|
41
56
|
}
|
|
42
57
|
}
|
|
43
|
-
|
|
44
|
-
|
|
58
|
+
|
|
59
|
+
const configs = []
|
|
60
|
+
const userDir = userConfigDir()
|
|
61
|
+
if (userDir !== null) configs.push(join(userDir, 'local.json'))
|
|
62
|
+
configs.push(join(HERE, '..', 'rules', 'local.json'))
|
|
63
|
+
|
|
64
|
+
for (const configPath of configs) {
|
|
65
|
+
if (!existingFile(configPath)) continue
|
|
45
66
|
try {
|
|
46
|
-
const parsed = JSON.parse(readFileSync(
|
|
67
|
+
const parsed = JSON.parse(readFileSync(configPath, 'utf8'))
|
|
47
68
|
if (typeof parsed?.rulesRoot === 'string' && parsed.rulesRoot.trim()) {
|
|
48
69
|
const absolute = resolve(parsed.rulesRoot.trim())
|
|
49
70
|
if (statSync(absolute).isDirectory()) return absolute
|
|
@@ -52,6 +73,7 @@ function rulesRoot() {
|
|
|
52
73
|
/* 配置坏了就忽略,别让插件起不来 */
|
|
53
74
|
}
|
|
54
75
|
}
|
|
76
|
+
|
|
55
77
|
return join(HERE, '..', 'rules')
|
|
56
78
|
}
|
|
57
79
|
|
|
@@ -82,10 +104,11 @@ function resolveProfiles(detection) {
|
|
|
82
104
|
const profileName = dedicated ?? GENERIC_PROFILE
|
|
83
105
|
const generic = dedicated === null
|
|
84
106
|
|
|
85
|
-
//
|
|
107
|
+
// 档案不覆盖这个版本时才退回通用兜底——"无档案可读"比"读错档案"更糟。
|
|
108
|
+
// Java 8 以下会走到这里;Java 8/11/17/21/≥22 都由同一份 java.md 的版本矩阵覆盖。
|
|
86
109
|
if (!profileSupportsVersion(stack.language, stack.version)) {
|
|
87
110
|
const fallback = existingFile(join(root, 'languages', `${GENERIC_PROFILE}.md`))
|
|
88
|
-
const reason = `专用档案 ${profileName}
|
|
111
|
+
const reason = `专用档案 ${profileName} 不覆盖版本 ${stack.version ?? '未知'}(Java 档案从 8 起),已改用通用兜底;不要套用 ${profileName} 的豁免清单`
|
|
89
112
|
return fallback
|
|
90
113
|
? { ...base, available: true, profile: GENERIC_PROFILE, generic: true, file: fallback, note: reason }
|
|
91
114
|
: { ...base, available: false, reason }
|