dsh-git-push 2.9.1 → 2.9.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.
@@ -0,0 +1,107 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * dsh-git-push — FS 热点静态扫描(独立 CLI,咨询性,恒退出码 0)
4
+ *
5
+ * 用法:
6
+ * node scripts/scan-fs-hotspots.mjs [root] [--json] [--top N] [--include 子串] [--exclude 子串] [--include-tests]
7
+ *
8
+ * 判据(六类,与审计规则 performance/multi-file-scanners 同源 ✓):
9
+ * ① stat 热点 按 stat 调用点数排序的文件
10
+ * ② 重复 stat 同一函数内同一表达式 stat ≥2 次
11
+ * ③ 重复 readdir 同一函数内同一表达式 readdir ≥2 次
12
+ * ④ 遍历入口 readdir + (自递归 或 已知 walker 名)
13
+ * ⑤ 逐文件扫描实现 同一函数内既有 readdir 又有 stat
14
+ * ⑥ 汇总 totals
15
+ *
16
+ * 【为什么不自己再写一遍判据】判据实现只在 lib/ast/fs-hotspots.js 一份 —— 审计规则
17
+ * (lib/checks/fs-scanner.js)与 CLI 都用它 ⇒ 不会出现「脚本说 9 个、规则说 7 个」的漂移 ✗
18
+ * (2026-10-16 由 bench-template 的 scan-fs-hotspots.mjs 交接而来:规则化 + 复用插件 tokenizer)
19
+ * 【退出码恒 0】这是**咨询性报告**,不拦提交(要拦走审计规则 ✓)
20
+ * dsh-skip-i18n: 用户可见文案硬编码为产品设计
21
+ */
22
+ import { readFileSync, readdirSync } from 'node:fs';
23
+ import { join, relative, extname } from 'node:path';
24
+ import { scanFsHotspots, FS_WALKERS } from '../lib/ast/fs-hotspots.js';
25
+
26
+ /** 默认豁免目录(与审计规则口径一致:审计侧由 collector 跳过,这里显式列同一份)。 */
27
+ const SKIP_DIRS = new Set(['node_modules', '.git', 'dist', 'release', '.trash', '.auto-update-tmp', 'cache-index', 'cache-gifs', '__pycache__']);
28
+ const TEST_DIRS = new Set(['test', 'tests']);
29
+ const EXTS = new Set(['.js', '.mjs', '.cjs']);
30
+
31
+ function parseArgs(argv) {
32
+ const o = { root: process.cwd(), json: false, top: 10, include: '', exclude: '', includeTests: false };
33
+ for (let i = 0; i < argv.length; i += 1) {
34
+ const a = argv[i];
35
+ if (a === '--json') o.json = true;
36
+ else if (a === '--top') o.top = Number(argv[++i]) || 10;
37
+ else if (a === '--include') o.include = String(argv[++i] || '');
38
+ else if (a === '--exclude') o.exclude = String(argv[++i] || '');
39
+ else if (a === '--include-tests') o.includeTests = true;
40
+ else if (!a.startsWith('--')) o.root = a;
41
+ }
42
+ return o;
43
+ }
44
+
45
+ /** 递归收集待扫文件(跳过 SKIP_DIRS;test/tests 默认跳过,--include-tests 纳入 ✓)。 */
46
+ function collectFiles(dir, o, out = []) {
47
+ let ents = [];
48
+ try {
49
+ ents = readdirSync(dir, { withFileTypes: true });
50
+ } catch {
51
+ return out; // 权限/竞态:跳过该目录,不让整轮失败
52
+ }
53
+ for (const e of ents) {
54
+ const full = join(dir, e.name);
55
+ if (e.isDirectory()) {
56
+ if (SKIP_DIRS.has(e.name)) continue;
57
+ if (!o.includeTests && TEST_DIRS.has(e.name)) continue;
58
+ collectFiles(full, o, out);
59
+ } else if (EXTS.has(extname(e.name))) {
60
+ const rel = relative(o.root, full);
61
+ if (o.include && !rel.includes(o.include)) continue;
62
+ if (o.exclude && rel.includes(o.exclude)) continue;
63
+ out.push(full);
64
+ }
65
+ }
66
+ return out;
67
+ }
68
+
69
+ const opts = parseArgs(process.argv.slice(2));
70
+ const files = collectFiles(opts.root, opts);
71
+ const fileTexts = files.map((full) => {
72
+ try {
73
+ return { path: relative(opts.root, full), text: readFileSync(full, 'utf8') };
74
+ } catch {
75
+ return { path: relative(opts.root, full), text: '' };
76
+ }
77
+ });
78
+ const agg = scanFsHotspots(fileTexts);
79
+
80
+ if (opts.json) {
81
+ console.log(JSON.stringify({
82
+ root: opts.root,
83
+ includeTests: opts.includeTests,
84
+ walkerNames: FS_WALKERS,
85
+ totals: agg.totals,
86
+ hot: agg.hot.slice(0, opts.top),
87
+ scanners: agg.scanners,
88
+ dupStats: agg.dupStats,
89
+ dupReaddirs: agg.dupReaddirs,
90
+ walkers: agg.walkers,
91
+ }, null, 2));
92
+ } else {
93
+ const t = agg.totals;
94
+ console.log(`FS 热点扫描(${t.files} 文件 · stat ${t.stats} · readdir ${t.readdirs} · 重复 stat ${t.dupStats} · 重复 readdir ${t.dupReaddirs} · 遍历入口 ${t.walkerCalls} · 逐文件扫描实现 ${t.scanners})`);
95
+ console.log('\n① stat 热点(按 stat 调用点数):');
96
+ for (const h of agg.hot.slice(0, opts.top)) console.log(` ${String(h.stats).padStart(3)} stat / ${String(h.readdirs).padStart(3)} readdir ${h.file}`);
97
+ console.log('\n④ 遍历入口(readdir + 自递归/已知 walker):');
98
+ if (!agg.walkers.length) console.log(' (无)');
99
+ for (const w of agg.walkers) console.log(` ${w.file}:${w.line} ${w.fn}() → ${w.calls}`);
100
+ if (agg.dupStats.length || agg.dupReaddirs.length) {
101
+ console.log('\n②③ 同函数内重复的 stat/readdir(可合并成一次):');
102
+ for (const d of [...agg.dupStats, ...agg.dupReaddirs]) console.log(` ${d.file}:${d.line} ${d.fn}() ${d.expr}`);
103
+ }
104
+ console.log(`\n⑤ 逐文件扫描实现(readdir+stat 同函数,共 ${agg.scanners.length} 个;> 3 时审计规则 performance/multi-file-scanners 会报 notice):`);
105
+ for (const s of agg.scanners) console.log(` ${s.file}:${s.line} ${s.fn}()`);
106
+ }
107
+ process.exit(0); // 咨询性:恒 0(要拦提交走审计规则 ✓)
@@ -31,7 +31,7 @@ generatedBy: deepseek-official/deepseek-v4-flash · EIGHTfs 2026-10-02
31
31
  | `git_cred_env` | — | 输出凭据环境变量前缀(SSH `GIT_SSH_COMMAND` / HTTPS `GIT_ASKPASS`,不含明文) |
32
32
  | `git_gen_ssh_key` | `email`(必填), `force?` | 生成 SSH 密钥对(写入插件配置目录;私钥不出本机,公钥整行回传) |
33
33
  | `git_sluice` | `args`(必填) | git 命令透传(凭据自动注入;返回 status + stdout/stderr 原文) |
34
- | `git_api` | `path?`, `method?`, `query?`, `body?` | **直接调用本插件 28 条 HTTP API**(内部走 `handleHttp` 同一条代码路径,不另写实现);不传 `path` 则列出全部接口 |
34
+ | `git_api` | `path?`, `method?`, `query?`, `body?` | **直接调用本插件 35 条 HTTP API**(内部走 `handleHttp` 同一条代码路径,不另写实现);不传 `path` 则列出全部接口 |
35
35
 
36
36
  典型流程:`git_scan` 看改动 → `code_audit` 自查 → `git_commit_push`(审计通过才推)。
37
37
 
@@ -321,3 +321,20 @@ node scripts/readme-gen.mjs <repoPath> [--write <path>] [--template <path>]
321
321
  | 函数/复杂度被报为 blocker | 规则 `severity` 是上限,检查器不越级;报 blocker 说明 yml 里写的就是 error/blocker |
322
322
  | 克隆大文件反复失败 | 失败项的分片必须保留(`.dsh-parts`)才能跨轮 Range 续传;同轮清理分片会让大文件永远从 0 重来 |
323
323
  | 建了远端但推送报「远端查不到分支 master(API 404 / ls-remote 无该分支)」 | `git_remote_create` 旧版把 origin 写成 **REST API 端点**(`https://api.github.com/repos/<o>/<r>` ✗ 那不是 git remote)⇒ `git push/fetch origin` 必然失败。2026-10-09 已修(`lib/git/remote.js`):origin 统一写 `https://github.com/<o>/<r>`,并**自愈**——仓库已存在但 origin 仍是 API 形态时 `set-url` 改回;返回体新增 `originAction`(`add`/`repair`/`keep`)。旧仓库手工修:`git remote set-url origin ssh://git@ssh.github.com:443/<o>/<r>.git` 再 `git push -u origin master`(凭据用插件 `id_rsa` + `-p 443`)。⚠️ `lib/git/clone.js` 仍写 API 形态 origin(设计如此,插件自身推送不受影响,但 `git push origin` 会失败) |
324
+
325
+ ## 端点:AI 自设工作区路径(workspace-paths)
326
+
327
+ 环境注入里的「当前工作目录 cwd」原先取自**会话文件**(`agent.session.header.cwd`),实测可能是**陈旧路径**
328
+ (本机注入过 `0.1.6-alpha.1` 的旧工作区 ⇒ 反而误导)⇒ 改为让 AI 自己登记真实工作区:
329
+
330
+ | 方法 | 路径 | 说明 |
331
+ |---|---|---|
332
+ | GET | `/api/git-push/workspace-paths` | 读清单 + 注入预览(`injection` / `injectionActive` / `file`) |
333
+ | POST | `/api/git-push/workspace-paths` | 写清单:`{paths:[…], mode:"set"\|"add"\|"remove"}`;`{clear:true}` 清空 |
334
+
335
+ - **校验**:只收**绝对路径**、必须**存在且是目录**、去重、上限 20;全被拒或缺参一律 **400**(不返回"成功但空")
336
+ - **存储**:`<配置目录>/workspace-paths.json`(`paths` / `updatedAt` / `updatedBy`,原子写入)
337
+ - **注入**:自设清单**优先显示**(逐条 + 修改入口),会话 cwd 降级标注为「仅兜底,可能陈旧」;
338
+ 注入缓存键带上自设清单(否则改完不刷新)
339
+ - **调用**:`git_api({path:'workspace-paths', method:'POST', body:'{"paths":["/abs/path"]}'})`
340
+ - **回归**:`test/test-workspace-paths.mjs`(8 例,含「经 handleHttp 的 JSON 字符串 body」)