dsh-git-push 2.8.6 → 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 (38) hide show
  1. package/README.md +18 -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/command-registry.js +1 -1
  15. package/lib/app/handlers/workspace-paths.js +107 -0
  16. package/lib/app/http-handlers.js +19 -2
  17. package/lib/app/inject-text.js +1 -1
  18. package/lib/app/tool-call.js +25 -1
  19. package/lib/ast/code-lines.js +52 -0
  20. package/lib/ast/index.js +1 -1
  21. package/lib/ast/tokenizer.js +7 -2
  22. package/lib/ast/treesitter.js +208 -0
  23. package/lib/audit/audit-file.js +3 -3
  24. package/lib/audit/orchestrate.js +38 -0
  25. package/lib/audit-rules/audit-rules-nodejs.yml +2 -2
  26. package/lib/audit-rules/audit-rules-paths.yml +1 -1
  27. package/lib/audit-rules/audit-rules-performance.yml +7 -3
  28. package/lib/checks/dispatch.js +3 -3
  29. package/lib/checks/regex.js +19 -4
  30. package/lib/core/workspace-paths.js +100 -0
  31. package/lib/rule/registry.js +7 -0
  32. package/lib/self/index.js +1 -1
  33. package/lib/user-requirements.json +2 -1
  34. package/package.json +2 -1
  35. package/scripts/sync-plugin-install.mjs +84 -21
  36. package/scripts/sync-plugin.mjs +14 -9
  37. package/skills/guide/guide-cli-scripts.md +1 -1
  38. package/skills/guide/guide-commit-push.md +33 -0
@@ -427,8 +427,8 @@ rules:
427
427
  name: "真实邮箱入库(隐私泄漏)"
428
428
  category: "security"
429
429
  severity: "error"
430
- description: "疑似真实个人邮箱硬编码/入库(隐私信息),请确认——示例域(example.com)、GitHub 匿名邮箱(users.noreply.github.com)、SSH 地址(git@github.com / git@ssh.github.com)、GitHub token 前缀用户名(ghp_/gho_/ghu_/ghs_/ghr_/github_pat_ 开头的用户名 + github.com 域;token 本体由 secret-github-pat 规则拦截)、本地虚拟域(.local/.lan/.internal/.test)豁免;真实邮箱(如 QQ 号@qq.com 等)一旦进公开仓库可被爬取,招致营销骚扰/社工"
431
- pattern: "\\b(?!git@(?:ssh\\.)?github\\.com\\b|(?:gh[opsur]_|github_pat_)[A-Za-z0-9_]+@github\\.com\\b)[A-Za-z0-9._%+-]+@(?!example\\.com\\b|users\\.noreply\\.github\\.com\\b|[A-Za-z0-9-]+\\.(?:local|lan|internal|test|invalid|localhost)\\b)[A-Za-z0-9-]+\\.[A-Za-z]{2,}\\b"
430
+ description: "疑似真实个人邮箱硬编码/入库(隐私信息),请确认——示例域(example.com)、GitHub 匿名邮箱(users.noreply.github.com)、SSH 地址(git@github.com / git@ssh.github.com)、GitHub token 前缀用户名(ghp_/gho_/ghu_/ghs_/ghr_/github_pat_ 开头的用户名 + github.com 域;token 本体由 secret-github-pat 规则拦截)、本地虚拟域(.local/.lan/.internal/.test)豁免;真实邮箱(如 QQ 号@qq.com 等)一旦进公开仓库可被爬取,招致营销骚扰/社工;确需提交(公开联系方式/测试夹具/版权声明等)时可临时关闭审计再推送(插件设置 →「提交前审计」auditEnabled=false)"
431
+ pattern: "\\b(?!git@(?:ssh\\.)?github\\.com\\b|(?:gh[opsur]_|github_pat_)[A-Za-z0-9_]+@github\\.com\\b)[A-Za-z0-9._%+-]+@(?!example\\.com\\b|users\\.noreply\\.github\\.com\\b|[A-Za-z0-9-]+\\.(?:local|lan|internal|test|invalid|localhost)\\b|[A-Za-z0-9-]+\\.(?:png|jpe?g|gif|webp|svg|avif|ico|bmp|js|mjs|cjs|ts|tsx|jsx|css|scss|less|html?|json|ya?ml|md|markdown|txt|zip|gz|tgz|mp[34]|webm|pdf|woff2?|ttf|eot)\\b)[A-Za-z0-9-]+\\.[A-Za-z]{2,}\\b"
432
432
  fixable: false
433
433
  mitigation: "真实邮箱不写进代码/文档;示例一律用 your-name@example.com 占位;GitHub 匿名邮箱 users.noreply.github.com 豁免(git 提交默认 author);已入库的用 git filter 清历史"
434
434
  - id: credfile-common
@@ -44,7 +44,7 @@ rules:
44
44
  name: "路径穿越防护"
45
45
  category: "security"
46
46
  severity: "error"
47
- description: "直接使用用户输入作为文件路径存在目录遍历风险"
47
+ description: "人工核查提示:请核对本仓库是否存在「用户输入直接拼进文件路径」的目录遍历风险(本规则是**人工核查占位**,不指向具体行;命中行号仅作锚点)"
48
48
  fixable: false
49
49
  mitigation: "使用 path.resolve + startsWith 白名单校验"
50
50
 
@@ -13,9 +13,12 @@ rules:
13
13
  - id: performance/memory-bomb
14
14
  # astConfirm: 正则只做初筛,命中行必须再经 token 级确认「真在代码里」——
15
15
  # 已消除**注释行**里的示例文本误报(如讲解「while(true) 占死线程」的注释 ✗)。
16
- # 已知边界:匹配落在**字符串字面量内**时仍会报(makeCodeLineFilter 是行级判定,
17
- # 看不到列号位置)——实测影响面仅第三方插件测试脚本 1 处,评估后**不修** ✓
16
+ # 已知边界(2026-10-15 已修):匹配落在**字符串字面量内**时也曾误报 ——
17
+ # astConfirmSpan(**按规则 opt-in**)在行级确认之上再做**列级**确认:
18
+ # 命中位置落在字符串/模板串/注释区间内 ⇒ 不算真实代码。本规则开启它 ✓
19
+ # ⚠️ 不可无条件对所有 astConfirm 规则开启:硬编码路径/凭据等规则的命中**本来就该在字符串里**。
18
20
  astConfirm: true
21
+ astConfirmSpan: true
19
22
  name: "检测可能导致内存爆炸的代码"
20
23
  category: "performance"
21
24
  severity: "warning"
@@ -141,8 +144,9 @@ rules:
141
144
  # ── 无界循环 / 高 CPU 轮询(性能补充)──
142
145
  - id: performance/busy-wait-loop
143
146
  # 同上:注释里的 while(true) 已不再误报 ✓;
144
- # 字符串字面量里的 'while (true) {}'(测试用)仍会报 —— 已知边界、评估后不修 ✓
147
+ # 并开启 astConfirmSpan ⇒ 字符串字面量里的 'while (true) {}'(测试用)也不再误报 ✓
145
148
  astConfirm: true
149
+ astConfirmSpan: true
146
150
  name: "忙等待循环(高 CPU 空转)"
147
151
  category: "performance"
148
152
  severity: "warning"
@@ -63,9 +63,9 @@ export function runChecks({ file, relPath, text, grouped }, opts = {}) {
63
63
  // 三层审计 L1——file_patterns 文件内容级初筛(未命中 = 非候选,剔除进 L2)
64
64
  grouped = filterRulesByFileText(grouped, text);
65
65
  let findings = [];
66
- if (grouped['[FUNC]']) findings = findings.concat(checkRegexRules({ file, text, rules: grouped['[FUNC]'], repoPath: opts?.repoPath }));
67
- if (grouped['credential-ref']) findings = findings.concat(checkRegexRules({ file, text, rules: grouped['credential-ref'], repoPath: opts?.repoPath }));
68
- if (grouped['regex']) findings = findings.concat(checkRegexRules({ file, text, rules: grouped['regex'], repoPath: opts?.repoPath }));
66
+ if (grouped['[FUNC]']) findings = findings.concat(checkRegexRules({ file, text, rules: grouped['[FUNC]'], repoPath: opts?.repoPath, treeConfirm: opts?.treeConfirm }));
67
+ if (grouped['credential-ref']) findings = findings.concat(checkRegexRules({ file, text, rules: grouped['credential-ref'], repoPath: opts?.repoPath, treeConfirm: opts?.treeConfirm }));
68
+ if (grouped['regex']) findings = findings.concat(checkRegexRules({ file, text, rules: grouped['regex'], repoPath: opts?.repoPath, treeConfirm: opts?.treeConfirm }));
69
69
  if (grouped['path-regex']) findings = findings.concat(checkPathRegexRules({ file, relPath, rules: grouped['path-regex'] }));
70
70
  if (!quick && grouped['func-lines']) findings = findings.concat(checkFuncLines({ file, text, rules: grouped['func-lines'] }));
71
71
  // 此前 9 个 kind 编译后无人消费(死桶)
@@ -6,7 +6,7 @@
6
6
  * 避免「正则命中即报」造成误报。
7
7
  */
8
8
 
9
- import { makeCodeLineFilter, checkMagicNumberSmartAst } from '../ast/index.js';
9
+ import { makeCodeSpanFilter, checkMagicNumberSmartAst } from '../ast/index.js';
10
10
  import { RISK_BADGE, RISK_LABEL } from '../ast/io-risk.js';
11
11
  // 硬编码绝对路径精筛(paths 槽位 / astConfirmKind: "hardcoded-abs-path")——引擎侧唯一实现:
12
12
  // fs 可访问性判断 + 相对路径换算(正则做不到的两件事)。脚本调用本实现,不自带第二份 PATTERNS。
@@ -51,7 +51,7 @@ import { credentialValueLines, placeholderCredentialLines, shortFuncNameLines, s
51
51
 
52
52
  /** 检查文本是否符合 regex 型规则(regex / secret / credential-ref)。
53
53
  * @param {object} args { file, text, rules, source? , repoPath? } repoPath:仓库根(写目标命中 .gitignore 的精筛需要) */
54
- export function checkRegexRules({ file, text, rules, source = '新增行', repoPath = '' }) {
54
+ export function checkRegexRules({ file, text, rules, source = '新增行', repoPath = '', treeConfirm = null }) {
55
55
  const findings = [];
56
56
  const lines = text.split('\n');
57
57
  for (const rule of rules || []) {
@@ -78,7 +78,7 @@ export function checkRegexRules({ file, text, rules, source = '新增行', repoP
78
78
  if (patterns.some((p) => { p.lastIndex = 0; return p.test(line); })) candidates.push(i + 1);
79
79
  }
80
80
  }
81
- const codeFilter = rule.astConfirm ? makeCodeLineFilter(text, candidates, { file }) : null;
81
+ const codeFilter = rule.astConfirm ? makeCodeSpanFilter(text, candidates, { file }) : null;
82
82
  // readability/magic-number(唯一声明 astConfirm: magic-number 的规则)已合并进
83
83
  // magic-number-smart;本分支保留机制(自定义规则包可复用),当前无内置规则消费。
84
84
  const magicSmartLines = rule.astConfirm === 'magic-number' ? smartHitLines(text) : null;
@@ -137,7 +137,22 @@ export function checkRegexRules({ file, text, rules, source = '新增行', repoP
137
137
  if (hasKindAllow && !kindFilter.lines.has(i + 1)) continue; // 仅白名单行可报(token 级精筛)
138
138
  for (let j = 0; j < patterns.length; j++) {
139
139
  const p = patterns[j];
140
- if (line && p.test(line)) {
140
+ p.lastIndex = 0;
141
+ const m = line ? p.exec(line) : null;
142
+ if (m) {
143
+ // 列级/语法级精筛(**按规则 opt-in**:rule.astConfirmSpan === true)。
144
+ // ① 优先**语法树**:编排层已(异步)预解析本文件并传入同步确认函数 treeConfirm ✓
145
+ // —— verdict === false ⇒ 命中处是不透明构造(字符串/注释/模板)⇒ 丢弃;
146
+ // verdict === true ⇒ 真代码 ⇒ 放行(不再看 ②);
147
+ // verdict === null ⇒ 无法判定(无语法/解析失败)⇒ 回退 ②
148
+ // ② 回退 **token 级列级判定**(2.8.9 实现):命中列落在字符串/注释区间内 ⇒ 丢弃
149
+ // 为什么必须 opt-in、且绝不覆盖 kindFilter(allow):硬编码路径/凭据类规则的命中
150
+ // 本来就写在字符串里(实测:无条件开启会让 paths/hardcoded-absolute-path 从 5 条掉到 0 条 ✗)
151
+ if (rule.astConfirmSpan === true && !hasKindAllow) {
152
+ const verdict = typeof treeConfirm === 'function' ? treeConfirm(i + 1, m.index + 1) : null;
153
+ if (verdict === false) continue;
154
+ if (verdict !== true && codeFilter?.isCodeHit && !codeFilter.isCodeHit(i + 1, m.index + 1)) continue;
155
+ }
141
156
  // I/O 风险:message 用 AST 的分级详情(四级徽标 + 上下文 + 理由),
142
157
  // 否则只剩 yml 的 description,看不出这条是高还是低(正则路径特性)
143
158
  const ioHit = rule.astConfirmKind === 'io-risk' ? kindFilter?.detail?.get(i + 1) : null;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * 核心层 · AI 自设工作区路径(数组,多个)
3
+ *
4
+ * 背景:环境注入里的「当前工作目录 cwd」原先取自**会话文件**(agent.session.header.cwd)。
5
+ * 实测问题:会话 header 里存的可能是**陈旧路径**(本机实测注入出 `…/0.1.6-alpha.1/工作区/dsh-git-push`,
6
+ * 而真实工作区在 `…/VirtualDSM/DeepSeekHarness/工作区/dsh-git-push`)⇒ 注入反而误导 ✗。
7
+ *
8
+ * 设计:让 **AI 自己**登记真实工作区路径(可多个),注入时优先显示这份自设清单
9
+ * ⇒ AI 每轮看到的都是自己设的那份(这就是「自己提醒自己」的实际作用,不需要额外机制)。
10
+ *
11
+ * 存放:<配置目录>/workspace-paths.json(结构化列表用 JSON 承载,不走 env;配置目录见 credentialsDir())
12
+ * { "paths": ["<绝对路径>", …], "updatedAt": "ISO", "updatedBy": "ai" | "user" }
13
+ *
14
+ * 校验口径(宁缺毋滥,避免把错路径写进去再误导自己):
15
+ * · 只收**绝对路径**(相对路径没有稳定基准 ✗)
16
+ * · 必须**存在且是目录**
17
+ * · 去重(同一路径只留一次)+ 上限 20 条
18
+ * · 写入原子化(先写临时文件再 rename),坏 JSON 读取时降级为空清单
19
+ */
20
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs';
21
+ import { dirname, isAbsolute, join, resolve } from 'node:path';
22
+ import { credentialsDir } from './credentials.js';
23
+
24
+ /** 自设路径上限(注入要短,太多会挤占上下文)。 */
25
+ export const MAX_WORKSPACE_PATHS = 20;
26
+
27
+ /** 自设路径状态文件路径。 */
28
+ export function workspacePathsFile() {
29
+ return join(credentialsDir(), 'workspace-paths.json');
30
+ }
31
+
32
+ /**
33
+ * 读自设工作区路径。
34
+ * @returns {{paths: string[], updatedAt: string, updatedBy: string}} 读不到/坏 JSON ⇒ 空清单(不抛错)
35
+ */
36
+ export function loadWorkspacePaths() {
37
+ const empty = { paths: [], updatedAt: '', updatedBy: '' };
38
+ try {
39
+ const f = workspacePathsFile();
40
+ if (!existsSync(f)) return empty;
41
+ const j = JSON.parse(readFileSync(f, 'utf8'));
42
+ const paths = Array.isArray(j?.paths) ? j.paths.map((x) => String(x || '').trim()).filter(Boolean) : [];
43
+ return { paths, updatedAt: String(j?.updatedAt || ''), updatedBy: String(j?.updatedBy || '') };
44
+ } catch {
45
+ return empty;
46
+ }
47
+ }
48
+
49
+ /**
50
+ * 写自设工作区路径(带校验)。
51
+ * @param {string[]} paths 待写入的路径数组(绝对路径)
52
+ * @param {{by?: string}} [opts] by: 写入方标识('ai' / 'user'),默认 'ai'
53
+ * @returns {{ok: boolean, paths: string[], rejected: Array<{path: string, reason: string}>, file: string}}
54
+ */
55
+ export function saveWorkspacePaths(paths, { by = 'ai' } = {}) {
56
+ const rejected = [];
57
+ const kept = [];
58
+ for (const raw of Array.isArray(paths) ? paths : []) {
59
+ const p = String(raw || '').trim();
60
+ if (!p) continue;
61
+ if (!isAbsolute(p)) { rejected.push({ path: p, reason: '不是绝对路径' }); continue; }
62
+ const abs = resolve(p);
63
+ let ok = false;
64
+ try { ok = statSync(abs).isDirectory(); } catch { ok = false; }
65
+ if (!ok) { rejected.push({ path: p, reason: '不存在或不是目录' }); continue; }
66
+ if (!kept.includes(abs)) kept.push(abs);
67
+ }
68
+ const over = kept.splice(MAX_WORKSPACE_PATHS);
69
+ for (const p of over) rejected.push({ path: p, reason: `超过上限 ${MAX_WORKSPACE_PATHS} 条` });
70
+
71
+ const file = workspacePathsFile();
72
+ try {
73
+ mkdirSync(dirname(file), { recursive: true });
74
+ const tmp = `${file}.tmp-${process.pid}`;
75
+ writeFileSync(tmp, JSON.stringify({ paths: kept, updatedAt: new Date().toISOString(), updatedBy: String(by || 'ai') }, null, 2) + '\n', 'utf8');
76
+ renameSync(tmp, file); // 原子替换:避免读到半截 JSON
77
+ } catch (e) {
78
+ return { ok: false, paths: kept, rejected: [...rejected, { path: file, reason: `写入失败:${e?.message || e}` }], file };
79
+ }
80
+ return { ok: true, paths: kept, rejected, file };
81
+ }
82
+
83
+ /**
84
+ * 生成注入用的「AI 自设工作区」文本块(无自设时返回 '')。
85
+ *
86
+ * 措辞要点:① 明确这是 **AI 自己登记的**(不是宿主探测 ⇒ 不准确就是自己写错了)
87
+ * ② 给出修改入口(同一个 API),让下一轮的自己知道怎么改 ✓
88
+ * @param {string} [sep] 行分隔符(默认换行)
89
+ * @returns {string} 多行文本;无自设 ⇒ ''
90
+ */
91
+ export function workspacePathsInjectionText(sep = '\n') {
92
+ const { paths, updatedAt, updatedBy } = loadWorkspacePaths();
93
+ if (!paths.length) return '';
94
+ const L = [`【AI 自设工作区(${paths.length} 个 · 由 ${updatedBy || 'ai'} 于 ${String(updatedAt).slice(0, 16) || '未知时间'} 登记)】`];
95
+ paths.forEach((p, i) => L.push(`- ${i + 1}. ${p}`));
96
+ L.push('(这是**你自己**登记的清单,优先级高于会话 cwd;要增删改用 API:'
97
+ + "git_api({path:'workspace-paths', method:'POST', body:'{\"paths\":[\"<绝对路径>\", …]}'})"
98
+ + ',GET 同路径可读回当前值)');
99
+ return L.join(sep);
100
+ }
@@ -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,7 @@
9
9
  */
10
10
 
11
11
 
12
- export const VERSION = '2.8.6'; // 2.8.5:修 runNpm 不传 cwd —— npm pack/publish 会跑在**宿主进程的 cwd**(本机是 DSH 安装目录 /volume1/@appstore/DeepSeekHarness-NAS)而不是目标包目录。
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
13
  // 实测后果:该目录有 package.json ⇒ npm 去打包整棵 DSH 树、输出 2.1MB > spawnSync 默认 maxBuffer 1MB ⇒ ENOBUFS(npm_publish 的体检与真发全部失败);
14
14
  // 该目录没有 package.json 时报 ENOENT。现 publish 的两个调用点显式传 cwd=目标包目录,并给 runNpm 加 16MB maxBuffer。
15
15
  // 2.8.3:文案修正——「零改动 / 无新提交」明确为**正常成功路径**(注入用法、工具描述、README、skill 同批改),并修 job 输出自相矛盾(cleanSkipCommit 路径补 committed:false,不再显示「已提交,未推送」)
@@ -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.6",
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",
@@ -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` 才推 |