dsh-git-push 2.8.4 → 2.9.1

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.
Files changed (46) hide show
  1. package/README.md +22 -3
  2. package/assets/minihost.sh +35 -0
  3. package/assets/preview.html +36703 -0
  4. package/assets/start.sh +396 -0
  5. package/assets/tree-sitter/LICENSE +21 -0
  6. package/assets/tree-sitter/README.md +69 -0
  7. package/assets/tree-sitter/VERSIONS.txt +1 -0
  8. package/assets/tree-sitter/tree-sitter-javascript.wasm +0 -0
  9. package/assets/tree-sitter/tree-sitter-python.wasm +0 -0
  10. package/assets/tree-sitter/tree-sitter-typescript.wasm +0 -0
  11. package/assets/tree-sitter/tree-sitter.js +3980 -0
  12. package/assets/tree-sitter/tree-sitter.wasm +0 -0
  13. package/lib/app/apply.js +15 -2
  14. package/lib/app/audit-api.js +1 -1
  15. package/lib/app/command-registry.js +6 -2
  16. package/lib/app/handlers/workspace-paths.js +107 -0
  17. package/lib/app/http-handlers.js +19 -2
  18. package/lib/app/inject-text.js +1 -0
  19. package/lib/app/tool-call.js +38 -4
  20. package/lib/app/tools.js +5 -11
  21. package/lib/ast/code-lines.js +52 -0
  22. package/lib/ast/index.js +1 -1
  23. package/lib/ast/tokenizer.js +7 -2
  24. package/lib/ast/treesitter.js +208 -0
  25. package/lib/audit/audit-file.js +3 -3
  26. package/lib/audit/orchestrate.js +38 -0
  27. package/lib/audit-rules/audit-rules-nodejs.yml +2 -2
  28. package/lib/audit-rules/audit-rules-paths.yml +1 -1
  29. package/lib/audit-rules/audit-rules-performance.yml +12 -0
  30. package/lib/checks/dispatch.js +3 -3
  31. package/lib/checks/filter.js +7 -1
  32. package/lib/checks/regex.js +19 -4
  33. package/lib/commit-push.js +8 -4
  34. package/lib/core/workspace-paths.js +100 -0
  35. package/lib/git/push.js +9 -3
  36. package/lib/npm/publish.js +6 -2
  37. package/lib/npm/registry.js +23 -2
  38. package/lib/rule/registry.js +7 -0
  39. package/lib/self/index.js +4 -1
  40. package/lib/user-requirements.json +2 -1
  41. package/package.json +2 -1
  42. package/scripts/cpu-sample.mjs +188 -0
  43. package/scripts/sync-plugin-install.mjs +84 -21
  44. package/scripts/sync-plugin.mjs +14 -9
  45. package/skills/guide/guide-cli-scripts.md +1 -1
  46. package/skills/guide/guide-commit-push.md +33 -0
@@ -53,11 +53,25 @@ export function resolveNpmBin({ env = process.env } = {}) {
53
53
  return 'npm';
54
54
  }
55
55
 
56
+ /**
57
+ * npm 子进程输出上限。默认 1MB 对大项目的 pack 清单偏小 —— 实测撞过 ENOBUFS。
58
+ */
59
+ const NPM_MAX_BUFFER = 16 * 1024 * 1024;
60
+ // ENOBUFS 重试上限:npm 在大依赖树上(npm ls / npm view 等)输出可能超过 16MB,
61
+ // 一旦超限 spawnSync 直接以 ENOBUFS 失败——对调用方表现为「npm 调用失败」,无法自解。
62
+ // 故首次超限后**放大缓冲重试一次**,仍失败才如实报错(并把「输出过大」这个真因写进文案)。
63
+ const NPM_MAX_BUFFER_LARGE = 128 * 1024 * 1024;
64
+
56
65
  /**
57
66
  * 跑一次 npm(短超时,收 stdout/stderr;不抛错)。
67
+ * @param {string[]} args npm 参数
68
+ * @param {{timeoutMs?:number, env?:object, cwd?:string}} [opts]
69
+ * cwd:**必须在目标包目录里跑的调用要显式传**(`npm pack` / `npm publish` 都以 cwd 为目标包)。
70
+ * 不传就继承宿主进程的工作目录 —— 实测后果是 npm 去错目录找 package.json:
71
+ * 该目录没有 package.json ⇒ ENOENT;有 ⇒ 去 pack 那整棵树 ⇒ 输出撑爆缓冲区 ⇒ ENOBUFS。
58
72
  * @returns {{ok:boolean, code:number, stdout?:string, stderr?:string, error?:string}}
59
73
  */
60
- export function runNpm(args = [], { timeoutMs = NPM_TIMEOUT_MS, env = {} } = {}) {
74
+ export function runNpm(args = [], { timeoutMs = NPM_TIMEOUT_MS, env = {}, cwd = '', maxBuffer } = {}) {
61
75
  const merged = { ...process.env, ...env };
62
76
  // 关键:npm 的入口是 `#!/usr/bin/env node` 脚本 ⇒ 子进程 PATH 里必须有 node,
63
77
  // 否则即使找到 npm 也会报「env: 'node': No such file or directory」(最小 PATH 宿主实测)。
@@ -65,7 +79,14 @@ export function runNpm(args = [], { timeoutMs = NPM_TIMEOUT_MS, env = {} } = {})
65
79
  const nodeDir = dirname(String(process.execPath || ''));
66
80
  if (nodeDir) merged.PATH = `${nodeDir}${delimiter}${merged.PATH || ''}`;
67
81
  const bin = resolveNpmBin({ env: merged });
68
- const r = spawnSync(bin, args, { encoding: 'utf8', timeout: timeoutMs, env: merged });
82
+ // maxBuffer 可注入:默认 16MB;测试传极小值(如 1)即可**确定性触发** ENOBUFS 走重试分支 ✓
83
+ const runNpmBuf = (buf) => spawnSync(bin, args, {
84
+ encoding: 'utf8', timeout: timeoutMs, env: merged, maxBuffer: buf,
85
+ ...(cwd ? { cwd } : {}),
86
+ });
87
+ const first = Number.isFinite(maxBuffer) && maxBuffer > 0 ? maxBuffer : NPM_MAX_BUFFER;
88
+ let r = runNpmBuf(first);
89
+ if (r.error && r.error.code === 'ENOBUFS') r = runNpmBuf(NPM_MAX_BUFFER_LARGE);
69
90
  if (r.error) {
70
91
  const timedOut = r.error.code === 'ETIMEDOUT';
71
92
  return { ok: false, code: -1, bin, error: timedOut ? `npm 超时(${timeoutMs}ms)` : `npm 调用失败(${bin}):${String(r.error.message || r.error)}` };
@@ -111,5 +111,12 @@ function withRuleScope(compiled, source) {
111
111
  const srcScope = source?.scopeRules || source?.scope_rules;
112
112
  if (Array.isArray(srcScope) && srcScope.length) patch(out, 'scopeRules', srcScope);
113
113
  }
114
+ // ④ 列级精筛 astConfirmSpan(2026-10-15 新增)—— 与上面 ①②③ **完全同类**的缺陷:
115
+ // 新字段只在 regex 编译器里透传,而编译器重建规则对象时又会丢 ⇒ 生产路径读不到、
116
+ // 列级过滤静默失效(实测:单元测试直连过滤器时通过,端到端审计仍照旧误报 ✗)。
117
+ // 语义:只有显式 true 才开启列级过滤(其余一律不做,避免误杀"命中本来就该在字符串里"的规则)。
118
+ if (out.astConfirmSpan === undefined && source?.astConfirmSpan !== undefined) {
119
+ patch(out, 'astConfirmSpan', source.astConfirmSpan === true);
120
+ }
114
121
  return out;
115
122
  }
package/lib/self/index.js CHANGED
@@ -9,7 +9,10 @@
9
9
  */
10
10
 
11
11
 
12
- export const VERSION = '2.8.4'; // 2.8.3:文案修正——「零改动 / 无新提交」明确为**正常成功路径**(注入用法、工具描述、README、skill 同批改),并修 job 输出自相矛盾(cleanSkipCommit 路径补 committed:false,不再显示「已提交,未推送」)
12
+ export const VERSION = '2.9.1'; // 2.9.1:AI 自设工作区路径(数组 + API,注入优先显示)+ 修 handleHttp 丢弃 JSON 字符串 body(工具/CLI 的 POST body 全丢)+ 副本漂移检查补「文件清单」。历史:2.9.0:审计接入 tree-sitter(语法树优先、token 级回退;assets/tree-sitter 钉 web-tree-sitter@0.25.10)。历史:2.8.9:审计精筛升级为**列级**(astConfirmSpan 按规则 opt-in)。历史:2.8.5:修 runNpm 不传 cwd —— npm pack/publish 会跑在**宿主进程的 cwd**(本机是 DSH 安装目录 /volume1/@appstore/DeepSeekHarness-NAS)而不是目标包目录。
13
+ // 实测后果:该目录有 package.json ⇒ npm 去打包整棵 DSH 树、输出 2.1MB > spawnSync 默认 maxBuffer 1MB ⇒ ENOBUFS(npm_publish 的体检与真发全部失败);
14
+ // 该目录没有 package.json 时报 ENOENT。现 publish 的两个调用点显式传 cwd=目标包目录,并给 runNpm 加 16MB maxBuffer。
15
+ // 2.8.3:文案修正——「零改动 / 无新提交」明确为**正常成功路径**(注入用法、工具描述、README、skill 同批改),并修 job 输出自相矛盾(cleanSkipCommit 路径补 committed:false,不再显示「已提交,未推送」)
13
16
  // 不再判「推送未落地」,改为如实标「推送已完成但未核验」(只有 404 才算远端真的没有该分支)。
14
17
  // 2.6.2:克隆「已存在且不完整」时可续传/重来——预览端点回报 partial(有进行中标记且无有效提交),
15
18
  // 前端预览框在不完整时给出「重来」(只清 .dsh-parts 分片、不动已下文件与用户内容);忙碌键前缀(clone:/vis:/push:)统一到单一出处。
@@ -9,6 +9,7 @@
9
9
  "删除需可恢复:删除文件/目录前先确认有 git 历史或备份(禁 rm -rf 无痕删除),大删除先 commit 检查点",
10
10
  "文档对话类措辞:公开仓库文档只写做了什么,不含会话引用/决策来源/AI 许可表述/商量转述等沟通措辞(见 release-docs-rule)",
11
11
  "dryRun 先行:批量/破坏性操作(重建历史、删除、迁移)先 dryRun 预演,确认无误再执行",
12
- "版本号同步:功能变更时同步更新 package.json version 与 README 版本记录表"
12
+ "版本号同步:功能变更时同步更新 package.json version 与 README 版本记录表",
13
+ "提交信息结构化:提交信息含**多个要点**或需要 why/verify 溯源时,用 messageItems 传数组(元素为字符串或 {what,type?,scope?,why?,verify?,refs?},仅 what 必填)——message 只传字符串(宿主校验只认标量类型)并作标题,条目会渲染成要点与正文;简单一句话说清时用字符串即可,不必强行结构化"
13
14
  ]
14
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-git-push",
3
- "version": "2.8.4",
3
+ "version": "2.9.1",
4
4
 
5
5
  "description": "DSH git 自动提交推送插件——统一函数入口架构(规则/审计/git/自身/侧边栏/评分/豁免/上下文/HTTP/测试十大总入口)",
6
6
  "type": "module",
@@ -15,6 +15,7 @@
15
15
  "lib",
16
16
  "skills",
17
17
  "scripts",
18
+ "assets",
18
19
  "cli.mjs",
19
20
  "cordis.patch.yml",
20
21
  "README.md",
@@ -0,0 +1,188 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * CPU 现场采样器(独立脚本,按需启动;零依赖、只读 /proc)。
4
+ *
5
+ * 用途:CPU 异常(如经常 50%+)时**现场**抓证据——事后采样复现不出来,
6
+ * 必须在「异常正在发生」的那一刻记录:哪个进程、什么命令行、系统总占用、
7
+ * 是否 chrome/headless 在跑、宿主进程内存等。
8
+ *
9
+ * 为什么不做成插件常驻任务:30s 常驻采样虽便宜,但平时没人看,反而多一份常驻逻辑;
10
+ * 按需启动最省事,也不给宿主添负担。
11
+ *
12
+ * 用法:
13
+ * node scripts/cpu-sample.mjs # 默认 120 秒、每 5 秒一次
14
+ * node scripts/cpu-sample.mjs --seconds 300 --interval 2 --top 8
15
+ * node scripts/cpu-sample.mjs --out /tmp/cpu.jsonl --high 40
16
+ *
17
+ * 输出:① 控制台一行一样本(系统% + Top 进程)② JSONL 明细(每样本一行,含命令行)
18
+ * ③ 结束打印汇总(峰值、Top 常客、chrome 出现次数)与 JSONL 路径。
19
+ *
20
+ * 判定口径:进程 CPU% = 该进程 tick 增量 / 全机 tick 增量 × 100(= 占整机百分比,
21
+ * 与 top 的聚合口径一致);系统% = 1 - idle 增量/总增量。
22
+ */
23
+ import { readdirSync, readFileSync, appendFileSync, existsSync } from 'node:fs';
24
+ import { cpus, loadavg, hostname } from 'node:os';
25
+ import { join } from 'node:path';
26
+
27
+ const argv = process.argv.slice(2);
28
+ const arg = (name, dflt) => {
29
+ const i = argv.indexOf(`--${name}`);
30
+ return i >= 0 && argv[i + 1] !== undefined ? argv[i + 1] : dflt;
31
+ };
32
+ const SECONDS = Math.max(5, Number(arg('seconds', 120)) || 120);
33
+ const INTERVAL = Math.max(1, Number(arg('interval', 5)) || 5);
34
+ const TOP = Math.max(3, Number(arg('top', 6)) || 6);
35
+ const HIGH = Number(arg('high', 40)) || 40;
36
+ const OUT = String(arg('out', '') || '') || `/tmp/cpu-sample-${new Date().toISOString().replace(/[:.]/g, '-')}.jsonl`;
37
+ const NCPU = cpus().length || 1;
38
+
39
+ /** 读 /proc/stat 的 cpu 汇总行 → { total, idle }(单位:tick)。 */
40
+ function cpuTotals() {
41
+ try {
42
+ const line = readFileSync('/proc/stat', 'utf8').split('\n')[0] || '';
43
+ const f = line.trim().split(/\s+/).slice(1).map(Number);
44
+ const total = f.reduce((a, b) => a + (Number.isFinite(b) ? b : 0), 0);
45
+ const idle = (f[3] || 0) + (f[4] || 0); // idle + iowait
46
+ return { total, idle };
47
+ } catch { return { total: 0, idle: 0 }; }
48
+ }
49
+
50
+ /** 读某进程累计 CPU tick(utime+stime)。comm 可能含空格/括号 ⇒ 取最后一个 ')' 之后解析。 */
51
+ function procTicks(pid) {
52
+ try {
53
+ const s = readFileSync(`/proc/${pid}/stat`, 'utf8');
54
+ const rest = s.slice(s.lastIndexOf(')') + 2).trim().split(/\s+/);
55
+ // rest[0] = state ⇒ utime 是第 12 个字段(1-based 14)⇒ rest 下标 11、12
56
+ return (Number(rest[11]) || 0) + (Number(rest[12]) || 0);
57
+ } catch { return null; }
58
+ }
59
+
60
+ /** 某进程常驻内存 MB(statm 第 2 项 = resident pages)。 */
61
+ function procRssMB(pid) {
62
+ try {
63
+ const f = readFileSync(`/proc/${pid}/statm`, 'utf8').trim().split(/\s+/);
64
+ return Math.round(((Number(f[1]) || 0) * 4096) / 1048576);
65
+ } catch { return 0; }
66
+ }
67
+
68
+ /** 进程名与命令行(cmdline 为 NUL 分隔;截断到 160 字符)。 */
69
+ function procInfo(pid) {
70
+ let comm = '';
71
+ let cmd = '';
72
+ try { comm = readFileSync(`/proc/${pid}/comm`, 'utf8').trim(); } catch { /* 进程可能已退出 */ }
73
+ try { cmd = readFileSync(`/proc/${pid}/cmdline`, 'utf8').split('\0').filter(Boolean).join(' '); } catch { /* 同上 */ }
74
+ return { comm, cmd: cmd.slice(0, 160) };
75
+ }
76
+
77
+ /** 枚举 /proc 下的数字目录(= 进程)。 */
78
+ function pids() {
79
+ try { return readdirSync('/proc').filter((n) => /^\d+$/.test(n)); } catch { return []; }
80
+ }
81
+
82
+ /** 内存概况(MB)。 */
83
+ function memMB() {
84
+ try {
85
+ const t = readFileSync('/proc/meminfo', 'utf8');
86
+ const get = (k) => Number((t.match(new RegExp(`^${k}:\\s+(\\d+) kB`, 'm')) || [])[1] || 0) / 1024;
87
+ return { total: Math.round(get('MemTotal')), available: Math.round(get('MemAvailable')) };
88
+ } catch { return { total: 0, available: 0 }; }
89
+ }
90
+
91
+ let prev = null; // { t: {total,idle}, pids: Map<pid, ticks> }
92
+ let hostPid = null;
93
+ const samples = [];
94
+
95
+ function detectHostPid() {
96
+ for (const p of pids()) {
97
+ const { cmd } = procInfo(p);
98
+ if (cmd.includes('packages/DeepSeekHarness-NAS/target/bin/node')) return Number(p);
99
+ }
100
+ return null;
101
+ }
102
+
103
+ /** 采一次样并返回记录(纯读,不抛错)。 */
104
+ function sampleOnce() {
105
+ const now = cpuTotals();
106
+ const cur = new Map();
107
+ for (const p of pids()) {
108
+ const t = procTicks(p);
109
+ if (t !== null) cur.set(p, t);
110
+ }
111
+ const rec = {
112
+ t: new Date().toISOString(),
113
+ ncpu: NCPU,
114
+ systemPct: null,
115
+ load: loadavg().map((x) => Number(x.toFixed(2))),
116
+ mem: memMB(),
117
+ host: null,
118
+ chrome: 0,
119
+ browsersvc: 0,
120
+ top: [],
121
+ };
122
+ if (prev && now.total > prev.t.total) {
123
+ const dTot = now.total - prev.t.total;
124
+ const dIdle = now.idle - prev.t.idle;
125
+ rec.systemPct = Number((100 * (1 - dIdle / dTot)).toFixed(1));
126
+ const list = [];
127
+ for (const [pid, ticks] of cur) {
128
+ const old = prev.pids.get(pid);
129
+ if (old === undefined) continue; // 新进程首个样本跳过(无基线)
130
+ const d = ticks - old;
131
+ if (d <= 0) continue;
132
+ const pct = Number(((100 * d) / dTot).toFixed(1));
133
+ if (pct < 0.2) continue;
134
+ const info = procInfo(pid);
135
+ list.push({ pid: Number(pid), pct, rssMB: procRssMB(pid), ...info });
136
+ }
137
+ list.sort((a, b) => b.pct - a.pct);
138
+ rec.top = list.slice(0, TOP);
139
+ rec.chrome = list.filter((x) => /chrome|headless/i.test(x.comm)).length;
140
+ rec.browsersvc = list.filter((x) => /browsersvc/i.test(x.cmd) && !/cpu-sample/.test(x.cmd)).length;
141
+ if (hostPid === null) hostPid = detectHostPid();
142
+ const h = hostPid ? list.find((x) => x.pid === hostPid) : null;
143
+ rec.host = h ? { pid: h.pid, pct: h.pct, rssMB: h.rssMB } : (hostPid ? { pid: hostPid, pct: 0, rssMB: procRssMB(hostPid) } : null);
144
+ }
145
+ prev = { t: now, pids: cur };
146
+ return rec;
147
+ }
148
+
149
+ function line(rec) {
150
+ const hi = rec.systemPct !== null && rec.systemPct >= HIGH;
151
+ const head = `${rec.t.slice(11, 19)} 系统 ${rec.systemPct === null ? '--' : `${rec.systemPct}%`} load ${rec.load[0]} mem ${rec.mem.available}/${rec.mem.total}MB chrome ${rec.chrome} browsersvc ${rec.browsersvc}`;
152
+ const tops = rec.top.slice(0, 4).map((x) => `${x.comm}:${x.pct}%`).join(' ');
153
+ return `${hi ? '⚠️ 高占用 ' : ' '}${head}${tops ? ` | ${tops}` : ''}`;
154
+ }
155
+
156
+ // ── 主流程 ──
157
+ console.log(`CPU 现场采样器 · 主机 ${hostname()} · ${NCPU} 核 · 每 ${INTERVAL}s 一次 · 共 ${SECONDS}s · 高占用阈值 ${HIGH}%`);
158
+ console.log(`输出 JSONL:${OUT}`);
159
+ sampleOnce(); // 建立基线(首样本无百分比)
160
+ let n = 0;
161
+ const timer = setInterval(() => {
162
+ const rec = sampleOnce();
163
+ n += 1;
164
+ samples.push(rec);
165
+ console.log(line(rec));
166
+ try { appendFileSync(OUT, `${JSON.stringify(rec)}\n`); } catch { /* 写失败不影响采样 */ }
167
+ if (n * INTERVAL >= SECONDS) finish();
168
+ }, INTERVAL * 1000);
169
+
170
+ function finish() {
171
+ clearInterval(timer);
172
+ const withPct = samples.filter((s) => s.systemPct !== null);
173
+ const peak = withPct.reduce((m, s) => Math.max(m, s.systemPct), 0);
174
+ const counter = new Map();
175
+ for (const s of withPct) for (const x of s.top) counter.set(x.comm, (counter.get(x.comm) || 0) + x.pct);
176
+ const regulars = [...counter.entries()].sort((a, b) => b[1] - a[1]).slice(0, 6)
177
+ .map(([c, v]) => `${c}(${Math.round(v)}%)`);
178
+ const chromeHits = withPct.filter((s) => s.chrome > 0).length;
179
+ console.log('\n── 汇总 ──');
180
+ console.log(`样本数 ${withPct.length} · 系统峰值 ${peak}% · 平均 ${withPct.length ? (withPct.reduce((a, s) => a + s.systemPct, 0) / withPct.length).toFixed(1) : 0}%`);
181
+ console.log(`chrome/headless 出现样本数:${chromeHits}/${withPct.length}`);
182
+ console.log(`Top 常客(按累计 %):${regulars.join(' · ') || '(无)'}`);
183
+ console.log(`明细:${OUT}`);
184
+ process.exit(0);
185
+ }
186
+
187
+ // Ctrl-C 也能出汇总
188
+ process.on('SIGINT', finish);
@@ -18,7 +18,7 @@
18
18
  * applyInstall 按 on/off 执行安装形态动作(用改动本体的 sync 步骤落真实文件)
19
19
  * depHints package.json 依赖声明是否还指向 node_modules / 绝对 link:
20
20
  */
21
- import { existsSync, readdirSync, lstatSync, readlinkSync, unlinkSync, symlinkSync, mkdirSync, readFileSync } from 'node:fs';
21
+ import { existsSync, readdirSync, lstatSync, unlinkSync, mkdirSync, readFileSync } from 'node:fs';
22
22
  import { join, resolve, sep } from 'node:path';
23
23
 
24
24
  /** DSH 数据根(含 .dsh 的那一层)。兼容两种入参形态:
@@ -113,9 +113,78 @@ function lstatOrNull(p) {
113
113
  try { return lstatSync(p); } catch { return null; }
114
114
  }
115
115
 
116
+ /** 读文本,失败返回 null(用于副本漂移判定)。 */
117
+ function readTextOrNull(p) {
118
+ try { return readFileSync(p, 'utf8'); } catch { return null; }
119
+ }
120
+
121
+ /** 递归列目录内文件(相对路径;跳过 .git/node_modules/.trash 等非发布内容)。 */
122
+ function listFilesRecursive(dir, prefix = '', out = new Set()) {
123
+ try {
124
+ for (const e of readdirSync(join(dir, prefix), { withFileTypes: true })) {
125
+ const rel = prefix ? `${prefix}/${e.name}` : e.name;
126
+ if (['.git', 'node_modules', '.trash', '.DS_Store'].includes(e.name)) continue;
127
+ if (e.isDirectory()) listFilesRecursive(dir, rel, out);
128
+ else out.add(rel);
129
+ }
130
+ } catch { /* 读不到按空处理,由调用方据结果判断 */ }
131
+ return out;
132
+ }
133
+
134
+ /**
135
+ * 判定 node_modules 那份副本是否与真源不一致(漂移)。**两类都要查**:
136
+ *
137
+ * ① **内容漂移**:已有文件内容与真源不同(旧副本顶掉真源 ⇒ 宿主跑旧代码)。
138
+ * 实测事故:GitHub tarball 旧版 2.6.9 顶掉 2.8.6 ⇒ 宿主自报 2.6.9、新工具整批消失。
139
+ * ② **文件清单漂移**:真源有、副本**缺** ✗ —— 硬链接孪生**不会自动带上新建文件**。
140
+ * 实测事故(2026-10-15 19:2x):新增 `lib/ast/treesitter.js` 只落 local-plugins,
141
+ * 而 node_modules 那份的 `lib/audit/orchestrate.js` 已经 import 它 ⇒ 副本 import 失败
142
+ * ⇒ 宿主日志 `dsh-git-push (dsh-git-push): failed to import`、**该插件全部工具消失** ✗✗。
143
+ * 本检查此前只比对内容 ⇒ 完全没发现这一类 ✗。
144
+ *
145
+ * 为什么不能按「是不是目录」报警:pnpm 的 `file:` 目录依赖落在 node_modules 时,
146
+ * 实测是**与 local-plugins 同 inode 的硬链接副本**(stat 同 inode、链接数 2),属正常安装产物 ✓。
147
+ *
148
+ * @param {string} localDir 真源(local-plugins/<插件>)
149
+ * @param {string} nmDir node_modules/<插件>
150
+ * @returns {string} '' = 一致(含硬链接同文件);否则是差异描述
151
+ */
152
+ export function copyDrift(localDir, nmDir) {
153
+ // ② 文件清单漂移(先查:缺文件比内容不同更致命 ⇒ 直接 import 失败)。
154
+ // 只比**加载关键子集**:lib/ 与 assets/ 是 import 与运行必需的;
155
+ // scripts/ skills/ docs/ 等不参与加载,pnpm 对 file: 依赖的拷贝口径也可能不同 ⇒
156
+ // 全量比对会产生上百条噪音,把真信号(如缺 lib/ast/treesitter.js)淹掉 ✗
157
+ const localFiles = listFilesRecursive(localDir);
158
+ const nmFiles = listFilesRecursive(nmDir);
159
+ const CRITICAL = /^(lib\/|assets\/|package\.json$|cordis\.patch\.yml$)/;
160
+ if (localFiles.size && nmFiles.size) {
161
+ const missing = [...localFiles].filter((f) => CRITICAL.test(f) && !nmFiles.has(f));
162
+ if (missing.length) return `副本缺少 ${missing.length} 个加载必需文件(如 ${missing[0]})`;
163
+ }
164
+ // ① 内容漂移:判据取「版本三处 + 入口文件」这几个标记位,任一处不同即认为副本陈旧/被替换
165
+ for (const rel of ['package.json', 'lib/self/index.js', 'lib/app/command-registry.js']) {
166
+ const a = readTextOrNull(join(localDir, rel));
167
+ const b = readTextOrNull(join(nmDir, rel));
168
+ if (a === null) continue; // 真源里没有这个文件(插件结构变体)⇒ 跳过该标记
169
+ if (b === null) return `${rel} 在副本里缺失`;
170
+ if (a !== b) return `${rel} 内容不同`;
171
+ }
172
+ return '';
173
+ }
174
+
116
175
  /**
117
- * 目标形态(对照文档 §3.2)与现状的差异清单。默认只报告,不执行。
118
- * 目标:`<profile>/local-plugins/<插件>` 为**真实目录**;`<profile>/node_modules/<插件>` 为**相对软链**指回去。
176
+ * 目标形态与现状的差异清单。默认只报告,不执行。
177
+ *
178
+ * 【2026-10-15 起】真源**只认** `<profile>/local-plugins/<插件>`(真实目录):
179
+ * `node_modules/<插件>` 的解析入口**不再由本脚本管理**(不建链、不改链)——它由
180
+ * DSH/pnpm 安装流程按 profile `package.json` 的 `file:local-plugins/<插件>` 声明自动生成,
181
+ * 安装位置就是 local-plugins。
182
+ *
183
+ * 为什么仍要报告 node_modules:实测事故(本机 2026-10-15)——node_modules 下留了一份
184
+ * **真实目录副本**(旧版 2.6.9,来自更早的 tarball 安装),它顶替 local-plugins 里的 2.8.6
185
+ * 成为宿主实际加载源,宿主 `git_api status` 报 2.6.9、`npm_publish` 等新工具整批消失。
186
+ * 更硬的证据:删掉该条目后,从 profile 根 `require.resolve('dsh-git-push')` 直接 MODULE_NOT_FOUND
187
+ * ⇒ **没有入口 = 解析不到 = 插件不加载**;入口必须存在,但该由安装流程生成,而非本脚本伪造。
119
188
  * @returns {Array<{kind: string, path: string, desc: string}>}
120
189
  */
121
190
  export function planInstall({ profileDir, pluginName }) {
@@ -127,19 +196,16 @@ export function planInstall({ profileDir, pluginName }) {
127
196
  if (ls && ls.isSymbolicLink()) {
128
197
  actions.push({ kind: 'delink-local', path: local, desc: 'local-plugins 下是软链:真实加载源应是**真实目录**(执行时会先删链再落一份真实副本)' });
129
198
  } else if (!ls) {
130
- actions.push({ kind: 'create-local', path: local, desc: 'local-plugins 下缺该插件:需先同步一份真实目录(HMR 的覆盖点与真实加载源都在这里)' });
199
+ actions.push({ kind: 'create-local', path: local, desc: 'local-plugins 下缺该插件:需先同步一份真实目录(真实加载源在这里)' });
131
200
  }
132
201
  const ns = lstatOrNull(nm);
133
- if (ns && ns.isSymbolicLink()) {
134
- let t = '';
135
- try { t = readlinkSync(nm); } catch { t = ''; }
136
- if (!t.startsWith('.')) {
137
- actions.push({ kind: 'relink-nm', path: nm, desc: `node_modules 下是绝对软链(→ ${t}):应改相对链 ../local-plugins/${pluginName}(换机/换卷仍有效)` });
202
+ if (ns && !ns.isSymbolicLink()) {
203
+ // 真实目录在 pnpm `file:` 目录依赖下是**正常产物**(实测与真源同 inode 的硬链接)⇒ 不能只看形态报警,
204
+ // 要比**内容**:只有副本与真源不一致(陈旧/被替换)才会顶掉真源、让宿主跑旧代码 ✓
205
+ const drift = copyDrift(local, nm);
206
+ if (drift) {
207
+ actions.push({ kind: 'nm-drift', path: nm, desc: `node_modules 下的副本与真源**内容不一致**(${drift}):它会顶掉 local-plugins 成为实际加载源(实测旧副本 2.6.9 顶掉 2.8.6、新工具整批消失)⇒ 应重装该依赖或删除此副本` });
138
208
  }
139
- } else if (!ns) {
140
- actions.push({ kind: 'link-nm', path: nm, desc: `node_modules 下缺软链:应建相对链 ../local-plugins/${pluginName}` });
141
- } else {
142
- actions.push({ kind: 'dir-nm', path: nm, desc: 'node_modules 下是真实目录:按目标形态应让真实源落在 local-plugins、这里只留相对软链(本工具不自动搬移,避免动到既有数据)' });
143
209
  }
144
210
  return actions;
145
211
  }
@@ -148,26 +214,23 @@ export function planInstall({ profileDir, pluginName }) {
148
214
  * 执行安装形态动作(仅在调用方传入 on=true 时写盘)。
149
215
  * delink-local:删软链(真实内容由后续同步步骤落进来)
150
216
  * create-local:建目录(同上)
151
- * relink-nm / link-nm:替换/新建相对软链
152
- * dir-nm:只报告(搬移真实目录有数据风险,交给人工或既有搬迁流程)
217
+ * nm-real-dir:只报告(删副本属破坏性动作,交人工或安装流程;本工具不动既有数据)
218
+ *
219
+ * 注:本工具**不建 node_modules 软链**(真源只认 local-plugins;解析入口由 DSH/pnpm 安装流程生成)。
153
220
  * @returns {{done: string[], skipped: string[]}}
154
221
  */
155
222
  export function applyInstall(actions, { on = false } = {}) {
156
223
  const done = [];
157
224
  const skipped = [];
158
225
  for (const a of actions) {
159
- if (!on || a.kind === 'dir-nm') { skipped.push(a.kind); continue; }
226
+ // 只有「改 local-plugins 真实目录」是他的活;node_modules 相关一律只报告(不建链、不删数据)
227
+ if (!on || (a.kind !== 'delink-local' && a.kind !== 'create-local')) { skipped.push(a.kind); continue; }
160
228
  try {
161
229
  if (a.kind === 'delink-local') {
162
230
  unlinkSync(a.path); // 只删软链本身,不触及它指向的任何内容
163
231
  mkdirSync(a.path, { recursive: true });
164
232
  } else if (a.kind === 'create-local') {
165
233
  mkdirSync(a.path, { recursive: true });
166
- } else if (a.kind === 'relink-nm') {
167
- unlinkSync(a.path);
168
- symlinkSync(join('..', 'local-plugins', a.path.split(sep).pop()), a.path);
169
- } else if (a.kind === 'link-nm') {
170
- symlinkSync(join('..', 'local-plugins', a.path.split(sep).pop()), a.path);
171
234
  }
172
235
  done.push(a.kind);
173
236
  } catch (e) {
@@ -2,7 +2,9 @@
2
2
  * 双副本同步脚本(1.0.0)
3
3
  *
4
4
  * 源 = 本仓库(脚本所在插件仓库根)
5
- * 目标 = DSH 插件目录(.dsh/profiles/<profile>/node_modules/<插件名>)
5
+ * 目标 = DSH 插件的**真实安装位置**:`.dsh/profiles/<profile>/local-plugins/<插件名>`
6
+ * (`node_modules/<插件名>` 只是**解析入口**,由 DSH/pnpm 安装流程按 profile
7
+ * `package.json` 的 `file:local-plugins/<插件>` 声明生成 —— 本脚本不建链、不改链)
6
8
  *
7
9
  * 默认 **dryRun**(只打印将要同步的差异,不写入);`--write` 才真同步。
8
10
  * 同步内容:lib/** skills/** scripts/** cli.mjs package.json cordis.patch.yml README.md
@@ -120,14 +122,17 @@ export async function listSyncFiles(root = SOURCE_ROOT) {
120
122
  }
121
123
 
122
124
  /**
123
- * 探测 DSH 插件目录。
125
+ * 探测 DSH 插件的部署位置。
124
126
  *
125
- * **两个位置都要同步**(最大教训:只同步 node_modules 导致改动看不到):
126
- * 1) `<profile>/local-plugins/<插件名>` ← **真实加载源**(profile 的 package.json
127
- * 写的是 `"<插件名>": "file:./local-plugins/<插件名>"`,DSH 加载这里)
128
- * 2) `<profile>/node_modules/<插件名>` ← npm link 产物(部分运行路径会解析到这里)
127
+ * **真实安装位置 = `<profile>/local-plugins/<插件名>`**(profile 的 package.json 写的是
128
+ * `"<插件名>": "file:local-plugins/<插件名>"`)—— 同步目标就是它。
129
129
  *
130
- * 历史上 UI 改动「刷新看不到」,根因就是只 rsync 了 node_modules。
130
+ * `<profile>/node_modules/<插件名>` 只作**解析入口**探测(部分解析路径经此;实测删掉条目后
131
+ * 从 profile 根 require.resolve 直接 MODULE_NOT_FOUND ⇒ 入口缺失 = 插件加载不到):
132
+ * 该入口由 DSH/pnpm 安装流程生成与维护,**本脚本不再创建/修补它**。
133
+ *
134
+ * 历史教训(2026-10-15):node_modules 下残留真实目录副本(旧版)会**顶替** local-plugins
135
+ * 成为实际加载源,宿主跑旧代码、新工具整批消失 —— 故 planInstall 会对这种形态报警。
131
136
  * @param {string} [home] DSH_HOME(默认从环境变量推断)
132
137
  * @param {string} [pluginName] 插件名
133
138
  * @returns {string[]} 命中的目标目录(local-plugins 在前)
@@ -258,13 +263,13 @@ export async function main(argv = process.argv.slice(2)) {
258
263
  console.log(` 免重启热重载:${verdict.hot ? '✅ 可(改代码后同步即生效)' : `❌ 不可 —— ${verdict.reason}`}`);
259
264
  const actions = planInstall({ profileDir: pd, pluginName });
260
265
  if (actions.length) {
261
- console.log(' 安装形态待办(目标:local-plugins 真实目录 + node_modules 相对软链):');
266
+ console.log(' 安装形态待办(真源 = local-plugins 真实目录;node_modules 入口由 DSH 安装流程生成,本脚本不建链):');
262
267
  for (const a of actions) console.log(` · [${a.kind}] ${a.desc}`);
263
268
  if (fix) {
264
269
  const res = applyInstall(actions, { on: true });
265
270
  console.log(` 已执行:${res.done.join(', ') || '(无)'}${res.skipped.length ? `|跳过:${res.skipped.join(', ')}` : ''}`);
266
271
  } else {
267
- console.log(' (加 --fix 才执行:删软链/建相对链,真实文件由上面的同步步骤落盘)');
272
+ console.log(' (加 --fix 才执行:解 local-plugins 软链 / 建真实目录;node_modules 相关只报告不动盘)');
268
273
  }
269
274
  }
270
275
  for (const h of depHints(pd, pluginName)) console.log(` ⚠️ ${h}`);
@@ -73,7 +73,7 @@ git-sluice self-check
73
73
  | `scripts/readme-gen.mjs` | README 生成 |
74
74
  | `scripts/preview-gen.mjs`(默认生成 / `--data-only` 只更数据段 / `check` 漂移门禁 / `--watch` 监听) / `scripts/preview-server.mjs`(默认反代真后端 / `--direct` 直连插件 / `--local` 免重启) | 界面预览页生成与漂移门禁、本地真实后端测试服务 |
75
75
  | `scripts/browser-page-probe.mjs` | 无头浏览器探针:读页面真实渲染文本 + 抓前端运行时错误(零硬编码路径,自动探测环境) |
76
- | `scripts/sync-plugin.mjs` | 双副本同步(工作区 ↔ 安装副本)+ 部署形态与免重启热重载自检:`--profile <名>` 指定 profile(多 profile 必给)、`--fix` 按目标形态修正(local-plugins 真实目录 + node_modules 相对软链) |
76
+ | `scripts/sync-plugin.mjs` | 同步(工作区 → 安装副本;**安装位置 = local-plugins 真源**)+ 部署形态与免重启热重载自检:`--profile <名>` 指定 profile(多 profile 必给)、`--fix` 只修 local-plugins 侧形态(解软链 / 建真实目录)。node_modules 入口由 DSH 安装流程生成,本脚本不建链;若那里的副本**内容与真源不一致**会报警(实测会顶掉真源;同 inode 硬链接副本不报) |
77
77
  | `scripts/sync-plugin-install.mjs` | 安装形态 / HMR 自检的实现模块(`sync-plugin.mjs` 引用,非独立入口) |
78
78
  | `scripts/verify-prestep.mjs` | 上下文注入自检(真实触发 pre-step 校验注入内容) |
79
79
  | `scripts/rename-locator.mjs` | 变量重命名位置定位(按作用域聚合) |
@@ -153,4 +153,37 @@ git_commit_push({ repo: "<仓库路径>", message: "chore: 重写历史后同步
153
153
  | `git_set_visibility` | 切换 public/private;改 public 前先确认无私密内容 |
154
154
  | `git_clone` | 从 GitHub 克隆仓库(Git Data API,不直连 github.com) |
155
155
  | `git_sluice` | 浅包装 git 透传(log/diff/branch/tag 等只读或低频命令),凭据自动注入 |
156
+
157
+ ## 推荐提交信息写法(结构化条目 `messageItems`)
158
+
159
+ **为什么需要它**:宿主在进插件前按工具 JSON schema 校验参数,`message` **只接受字符串**
160
+ (数组/对象会被直接拒 ✗,报 `invalid arguments: "message" must be a string`)。要写多条目,配 `messageItems`。
161
+
162
+ **推荐用法**:`message` 传标题字符串 + `messageItems` 传要点数组
163
+ (元素为字符串,或 `{what,type?,scope?,why?,verify?,refs?}`;**仅 what 必填**)。
164
+
165
+ ```jsonc
166
+ {
167
+ "repo": "/path/to/repo",
168
+ "message": "fix(audit): 修 secret-email 把 @2x 资源名当邮箱的误报",
169
+ "messageItems": [
170
+ { "what": "pattern 增加资源后缀负向前瞻", "type": "fix", "scope": "audit-rules",
171
+ "why": "视网膜文件名被当成 x@y.tld", "verify": "双向自测 6 例通过" },
172
+ "门禁四项绿;全量测试 0 失败"
173
+ ]
174
+ }
175
+ ```
176
+
177
+ **渲染结果**:标题(`message`)+ 逐条 `- 要点` + `why:` / `verify:` / `refs:` 脚注 ✓
178
+
179
+ **该用它的信号**(两个,满足任一即推荐):
180
+ 1. 一次提交含**多个要点**(写成一个长句会难读 ✗)
181
+ 2. 需要 **why / verify 溯源**(评审时要能看出「为什么改」与「怎么验证的」✓)
182
+
183
+ **不该硬用** ✗:一句话就能说清时用字符串即可 ✓(强行结构化只增加噪音)。
184
+ CLI(`git-sluice commit <仓库> -m "msg"`)只支持字符串 ✓;`messageItems` 走工具/HTTP API ✓。
185
+
186
+ **该用却没用会怎样**:不会失败 ✓;但当单串信息偏长(>150 字符或含换行)时,工具结果会带
187
+ `usageHint` 提醒改用 `messageItems` ✓;采用率留痕在 `<DSH_HOME>/git-push/commit-usage.log`
188
+ (每行一条 JSON:`structured` / `items` / `msgLen` / `repo` ✓,可据此统计实际采用率)。
156
189
  | CLI | `git-sluice commit <仓库> -m "msg"` 与工具同源(审计门禁一致);CLI 默认只提交,加 `--push` 才推 |