dsh-svn-review 0.2.3 → 0.2.4

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/lib/index.js CHANGED
@@ -216,8 +216,8 @@ export function apply(ctx) {
216
216
  if (value.engine === 'python') {
217
217
  // 不解释清楚,使用者会以为工具在乱报——正是这条让上次的审查跑偏了 12 分钟。
218
218
  lines.push(
219
- ' 说明:本进程读到的是加密容器(透明加密客户端只对白名单进程返回明文),'
220
- + '内容哈希已交给 python 子进程完成,结论与 svn status 一致。',
219
+ ' 说明:本进程读到的内容与基线对不上(多半是透明加密客户端只对白名单进程返回明文),'
220
+ + '已交给 python 子进程复核,结论与 svn status 一致。',
221
221
  )
222
222
  }
223
223
  // 清单过长会挤占上下文,而且一个真实的变更集不该有上千个文件。
package/lib/wc.js CHANGED
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { spawnSync } from 'node:child_process'
12
12
  import { createHash } from 'node:crypto'
13
- import { closeSync, existsSync, openSync, readSync, readFileSync, statSync, unlinkSync } from 'node:fs'
13
+ import { closeSync, existsSync, openSync, readdirSync, readSync, readFileSync, statSync, unlinkSync } from 'node:fs'
14
14
  import { tmpdir } from 'node:os'
15
15
  import { dirname, isAbsolute, join, resolve } from 'node:path'
16
16
  import { fileURLToPath } from 'node:url'
@@ -78,9 +78,17 @@ function extensionOf(relpath) {
78
78
  * 刻意不用"能否按 UTF-8 解码",因为 GBK 编码的源码会被误判成加密。
79
79
  */
80
80
  function readsCiphertext(root, baseFiles) {
81
- const probe = baseFiles
82
- .filter((node) => TEXT_EXTENSIONS.has(extensionOf(node.relpath)))
83
- .slice(0, 6)
81
+ const textFiles = baseFiles.filter((node) => TEXT_EXTENSIONS.has(extensionOf(node.relpath)))
82
+ if (textFiles.length === 0) return false
83
+
84
+ // 均匀取样,不能只取前几个。工作副本开头往往是 .gitignore / build.gradle 这类配置,
85
+ // 加密客户端经常不处理它们(有的库能读出配置、却读不出源码),
86
+ // 只取前缀会稳定漏判——0.2.3 第一版就是这么没生效的。
87
+ const step = Math.max(1, Math.floor(textFiles.length / 12))
88
+ const probe = []
89
+ for (let index = 0; index < textFiles.length && probe.length < 12; index += step) {
90
+ probe.push(textFiles[index])
91
+ }
84
92
 
85
93
  for (const node of probe) {
86
94
  let head
@@ -110,7 +118,7 @@ function readsCiphertext(root, baseFiles) {
110
118
  function runFallback(root) {
111
119
  const output = join(tmpdir(), `dsh-svn-review-${process.pid}-${Date.now()}.json`)
112
120
  try {
113
- for (const interpreter of ['python', 'python3', 'py']) {
121
+ for (const interpreter of interpreters()) {
114
122
  const result = spawnSync(interpreter, [FALLBACK_SCRIPT, root, output], {
115
123
  timeout: 300_000,
116
124
  windowsHide: true,
@@ -135,6 +143,26 @@ function runFallback(root) {
135
143
  return null
136
144
  }
137
145
 
146
+ /**
147
+ * 候选解释器。宿主进程的 PATH 未必和终端一致(从图形界面启动时尤其如此),
148
+ * 所以除了 PATH 里的名字,再补上 Windows 上最常见的安装位置。
149
+ */
150
+ function interpreters() {
151
+ const candidates = ['python', 'python3', 'py']
152
+ const localAppData = process.env.LOCALAPPDATA
153
+ if (typeof localAppData === 'string' && localAppData.length > 0) {
154
+ const base = join(localAppData, 'Programs', 'Python')
155
+ try {
156
+ for (const entry of readdirSync(base)) {
157
+ if (/^Python\d+$/i.test(entry)) candidates.push(join(base, entry, 'python.exe'))
158
+ }
159
+ } catch {
160
+ // 没装就跳过,不值得报错。
161
+ }
162
+ }
163
+ return candidates
164
+ }
165
+
138
166
  /**
139
167
  * 把 node:sqlite 变成可选依赖。
140
168
  *
@@ -274,6 +302,16 @@ export async function readChangeSet(start, options = {}) {
274
302
  counts.C += 1
275
303
  }
276
304
 
305
+ // 第二道保险,与加密客户端用什么格式无关:
306
+ // "几乎整份工作副本都被改过"这个结论本身不可信——正常的提交不会动掉十分之一的文件。
307
+ // 与其把几千个疑点丢给审查者去逐个核实(那会烧掉十几分钟),不如交给子进程复核一次:
308
+ // 子进程读到的是明文,它给出的才是真值。
309
+ const implausible = files.length > Math.max(50, Math.floor(baseFiles.length * 0.1))
310
+ if (implausible) {
311
+ const delegated = runFallback(root)
312
+ if (delegated !== null) return delegated
313
+ }
314
+
277
315
  files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0))
278
316
 
279
317
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-svn-review",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "displayName": "DSH SVN Review",
5
5
  "description": "SVN change-set scoping plus language and version detection for DeepSeek Harness code review: reads .svn/wc.db directly (no svn.exe), pins down the project language and version, and hands over the matching review rules so findings are judged by that language instead of generic ones.",
6
6
  "keywords": [