dsh-git-push 2.18.2 → 2.20.11
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/.gitignore +4 -0
- package/README.md +3 -0
- package/cli.mjs +16 -3
- package/lib/ARCHITECTURE.md +3 -0
- package/lib/app/audit-api.js +1 -1
- package/lib/app/command-registry.js +13 -1
- package/lib/app/inject-text.js +1 -0
- package/lib/app/scope-check.js +69 -0
- package/lib/app/tool-call.js +49 -2
- package/lib/ast/credential.js +130 -14
- package/lib/ast/dataflow.js +127 -10
- package/lib/ast/index.js +2 -0
- package/lib/ast/naming.js +9 -1
- package/lib/ast/scope-collisions.js +228 -0
- package/lib/ast/treesitter.js +142 -1
- package/lib/audit/history.js +1 -1
- package/lib/audit/orchestrate.js +93 -6
- package/lib/audit/scope-policy.js +110 -0
- package/lib/audit-rules/audit-rules-dsh.yml +16 -1
- package/lib/audit-rules/audit-rules-nodejs.yml +21 -6
- package/lib/checks/common.js +4 -4
- package/lib/checks/dispatch.js +5 -0
- package/lib/checks/index.js +2 -0
- package/lib/checks/regex.js +2 -2
- package/lib/checks/scope-collision.js +68 -0
- package/lib/cli/commands-audit.mjs +1 -1
- package/lib/commit-push.js +6 -1
- package/lib/exempt/index.js +5 -2
- package/lib/git/ignore.js +6 -4
- package/lib/git/init-compat.js +83 -4
- package/lib/git/push.js +25 -2
- package/lib/git/sensitive.js +30 -1
- package/lib/lint-adapter/detect.js +161 -0
- package/lib/lint-adapter/index.js +50 -0
- package/lib/lint-adapter/runner.js +133 -0
- package/lib/rule/compilers/structure.js +24 -0
- package/lib/score/index.js +36 -4
- package/lib/self/index.js +1 -1
- package/package.json +20 -1
- package/scripts/bump-version.mjs +20 -5
- package/scripts/check-js-scope.mjs +87 -0
- package/scripts/check.mjs +39 -1
- package/skills/dev/dsh-git-push.md +8 -2
package/lib/self/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
export const VERSION = '2.
|
|
12
|
+
export const VERSION = '2.20.11'; // 2.20.11:修 CI 真因——test-cifs-init 直接 execFileSync 读 `git config --global --get-all safe.directory`,而该键**不存在时退出码为 1**,execFileSync 抛错;CI 是全新 HOME(无该键)必炸,本地开发机早有该键所以一直绿。改用无键容错的 readGlobalSafeDirs()(无键即空列表)。以「全新 HOME」模拟 CI 条件验证 7/7 通过。历史:2.20.10:敏感文件扫描不再享「强制全仓」特权——改为与审计同一开关同一范围:审计关闭(audit=false)时不扫,审计开启时只扫「本次将提交的文件」(按 auditScanScope 的 diff 语义)。新增 scanSensitive 参数贯通 tool-call → commitAndPush → ensureGitignore;缺省 true 仅为兼容直接调用方(CLI/测试)。历史:2.20.9:修「有改动提交卡分钟级」——scanSensitiveFiles 递归读全仓每个文件内容,在 CIFS/SMB 上每文件一次网络往返;724 文件的仓库实测单文件改动卡满 15 分钟仍未返回(0 改动秒回,因为零改动整段跳过)。改为提交路径只扫「本次将提交的文件」(paths 精确模式用 pathList,否则解析 git status --porcelain 的变更集);实测同一仓库从 60 秒跑不完降到 26 毫秒。缺省不传 onlyPaths 时保持原全仓行为(兼容其它调用方)。历史:2.20.8:修 CI 假红——test-cifs-init 的幂等断言把 skipped 文案写死成「已登记」,但这是 CIFS 环境分支;CI 是本地盘、属主与进程同 uid,走的是「属主一致」分支,断言因此恒失败(run 57~61 全红而本地一直绿)。改为按环境分支匹配 /已登记|一致/,并在本地盘条件(/tmp + 同 uid)完整复刻验证通过。历史:2.20.7:修 dataflow/clear-then-access 第六类误报——reset() 被当清空方法。业务代码里 reset() 绝大多数是「恢复默认值/重置状态」,重置后对象仍有内容、读取安全(实测:某配置类 reset()->bool,测试断言 cfg.reset() 后 get("general.theme")=="dark" 取得有效默认值);同语料 13 条命中里 12 条源于此。已从 CLEAR_METHODS 移除,真正的容器清空用 clear()(保留)。历史:2.20.6:修 dataflow/clear-then-access 第五类系统性误报——Python 缩进式函数体从未被识别(区间收集只认 function 关键字与 ') {'),fnRanges 为空导致 mergeFnRanges 退化成「整个文件一个区间」,同文件内任意位置的 clear 与 access 都配成一对(实测 clear 在 invalidate()、访问在 build_index(),相距 177 行仍被报)。新增 collectPythonDefBodies 按缩进解析 def/async def 块并独立成体;闭包(嵌套 def 捕获外层变量)仍合并为一个体(是同一数据流,不该拆)。真实语料 13→1,剩余 1 条属 D3 边界内的合理提示(reset 后另有 _load_settings 重填,跨方法推断不做)。历史:2.20.5:修 dataflow/clear-then-access 四类系统性误报(真实语料实测 11 条命中里 8 条是误报)——①.empty() 被当清空(实为查询,从 CLEAR_METHODS 移除)②写目标 obj[k]=v 被当读访问(配对 ] 后跟 = 即按写回撤销)③类型注解位参与(PEP526 `x: list = []` 的 list 被当对象名、`-> list[str]` 被当访问;`:` 前须为标识符以区分 Python 函数定义冒号)④多目标解包错位(`a, b = [], {}` 把 [] 算给 b)。修复后同批文件 11→3 且剩余 3 条经人工核实均为真命中,真缺陷未被压制(正样本断言)。历史:2.20.4:树化迁移第二条 short-func-name——类方法/对象方法短名此前完全查不到(token 级只认 function 关键字),现走 method_definition 等定义节点判定;get/set 访问器显式排除(name 是属性名非函数名);初筛补方法形态 pattern(allow 精筛前 pattern 必须先命中候选,否则树化无效);TREE_FIRST_KINDS 登记 short-func-name。历史:2.20.3:修 CIFS/SMB 上「建仓成功但仓库对外不可用」——forceuid 挂载把目录属主映射成挂载用户(本机 杜渊/1026)而进程 uid 是套件用户(284371),git 2.55 对所有命令报 dubious ownership;插件内部带 -c safe.directory=* 感觉不到,交出去的仓库用户一敲 git 就挂。实测仓库级 [safe] directory 不生效(所有权检查先于读仓库 config),故新增 registerTrustedRepo/unregisterTrustedRepo 走 global 具体路径登记(只登记该目录,不用 *,同 uid 自动跳过),ensureUsableLocalRepo 三条路径(keep/create/repair)统一补齐。历史:2.20.2:修委托层自身灯下黑——tools/ruff 缺可执行位时旧行为静默返回空,与「项目没配 ruff」在报告里完全无法区分(部署副本迁移实测踩中:cp/同步不保 mode)。新增 detectLinterStatus 输出 unavailable(含具体成因与修复动作),并接进 linted;候选路径四律清单合并为 binCandidates 单一来源(原 resolveBin 与 resolveBinDetailed 各写一份,改一处漏一处会自相矛盾)。历史:2.20.1:新增外部 linter 委托层(方向 A 骨架,lib/lint-adapter/)——探测被审项目自带官方 linter([tool.ruff] 配置 + tools/·PATH 可执行自探测)→ 调用 ruff --output-format json → 适配成统一 finding(规则码→维度映射、路径转相对、来源标记 linter:ruff)。两条硬约束落地:①外部 finding severity 恒封顶 warning,**只进评分与报告、绝不进拦截门禁**(别人的规则集不裁决本仓能否提交);②探不到/崩溃/超时/坏输出一律降级空(含退出码≥2 不得被当成「外部判定无问题」的假阴性)。仅 full 范围委托;linted 委托状态进审计结果(防静默空转);lint-adapter 纳入层边界门禁 AUDIT_DIRS。历史:2.20.0:评分「零规则维度记 0」——本次生效规则集里一条规则都没绑定的维度(无检测能力)权重记 0 剔出分母,并回传 uncoveredDimensions 显式标注「测不到≠质量高」;编排层新增 computeDimRuleCounts,五个评分调用点统一接 dimRuleCounts,含全塌保护与向后兼容。历史:2.19.0:审计「有树走树」(方向 E1-E3)——凭据精筛 credential-value 改吃 tree-sitter 语法树(参数默认值/复合右值/三元不再误报、bytes/raw 前缀真凭据不再漏报、凭据名强弱分级+值置信度),建树触发与 astConfirmSpan 解耦(TREE_FIRST_KINDS),treeUsage 状态进审计结果(防静默回退)。历史:2.18.3:新增 scope_check 工具与 kind=scope-collision 审计规则(拼接产物作用域撞名)。
|
|
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,不再显示「已提交,未推送」)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-git-push",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.20.11",
|
|
4
4
|
"description": "DSH git 自动提交推送插件——统一函数入口架构(规则/审计/git/自身/侧边栏/评分/豁免/上下文/HTTP/测试十大总入口)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -97,5 +97,24 @@
|
|
|
97
97
|
"js-yaml": "4.1.0",
|
|
98
98
|
"tree-sitter-wasms": "0.1.13",
|
|
99
99
|
"web-tree-sitter": "0.25.10"
|
|
100
|
+
},
|
|
101
|
+
"dshScopeCheck": {
|
|
102
|
+
"note": "拼接产物作用域检查:files 里每个文件都查「同作用域重名 / 顶层声明 / 命名前缀」。查法:git-sluice scope-check(无参数即读本块 files);其它项目只要在自己的 package.json 写同名字段即可复用同一套判定",
|
|
103
|
+
"files": [
|
|
104
|
+
"lib/client.js"
|
|
105
|
+
],
|
|
106
|
+
"prefix": "dshgp_",
|
|
107
|
+
"allowlist": [
|
|
108
|
+
"module",
|
|
109
|
+
"exports",
|
|
110
|
+
"jsx",
|
|
111
|
+
"react",
|
|
112
|
+
"store",
|
|
113
|
+
"NS",
|
|
114
|
+
"SETTINGS_NS",
|
|
115
|
+
"inject",
|
|
116
|
+
"apply"
|
|
117
|
+
],
|
|
118
|
+
"topLevelMustBeEmpty": true
|
|
100
119
|
}
|
|
101
120
|
}
|
package/scripts/bump-version.mjs
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* node scripts/bump-version.mjs --message "…" --apply # 真写盘
|
|
16
16
|
* node scripts/bump-version.mjs --to 2.11.0 --message "…" --apply # 指定版本(默认 patch +1)
|
|
17
17
|
* node scripts/bump-version.mjs --message-file /tmp/msg.txt --apply
|
|
18
|
+
* node scripts/bump-version.mjs --message "…" --comment "VERSION 行用的短摘要(可选)" --apply
|
|
18
19
|
*
|
|
19
20
|
* 约定:
|
|
20
21
|
* · **默认 dry-run**——只打印将要改动的三处(旧值 → 新值),不落盘;确认无误再加 --apply。
|
|
@@ -36,13 +37,14 @@ const RELEASES = join(ROOT, 'docs', 'releases.json');
|
|
|
36
37
|
|
|
37
38
|
/** 解析命令行参数(只认 --flag value 与布尔 --apply)。 */
|
|
38
39
|
function parseArgs(argv) {
|
|
39
|
-
const out = { apply: false, to: '', message: '', messageFile: '' };
|
|
40
|
+
const out = { apply: false, to: '', message: '', messageFile: '', comment: '' };
|
|
40
41
|
for (let i = 0; i < argv.length; i++) {
|
|
41
42
|
const a = argv[i];
|
|
42
43
|
if (a === '--apply') { out.apply = true; continue; }
|
|
43
44
|
if (a === '--message' || a === '-m') { out.message = argv[++i] || ''; continue; }
|
|
44
45
|
if (a === '--message-file') { out.messageFile = argv[++i] || ''; continue; }
|
|
45
46
|
if (a === '--to') { out.to = argv[++i] || ''; continue; }
|
|
47
|
+
if (a === '--comment') { out.comment = argv[++i] || ''; continue; }
|
|
46
48
|
}
|
|
47
49
|
return out;
|
|
48
50
|
}
|
|
@@ -71,8 +73,14 @@ function readJson(p) {
|
|
|
71
73
|
* 拼新的 VERSION 行。
|
|
72
74
|
* 旧注释形如:`2.10.4:本次说明。历史:2.10.3:更早说明。` → 把「本次说明」降级进历史链,
|
|
73
75
|
* 只保留最近 2 条,避免每版都把整串历史再抄一遍(实测 2.9.x 之后该行已接近不可读)。
|
|
76
|
+
*
|
|
77
|
+
* ⚠️ **行注释必须单行**:`--message-file` 常带多段落,若原样写进 `//` 后面的注释,
|
|
78
|
+
* 换行会把文件撕成多行 → 整个 lib/self/index.js 语法错误(ESM 加载期就炸,
|
|
79
|
+
* `node cli.mjs` 直接 TypeError)。故此处按「首段首句」压成一行摘要,
|
|
80
|
+
* 正文完整内容仍原样进 docs/releases.json(那边是 JSON 字符串,换行合法)。
|
|
81
|
+
* 需要更长摘要时用 `--comment` 显式给。
|
|
74
82
|
*/
|
|
75
|
-
function buildVersionLine(oldLine, newVer, oldVer, message) {
|
|
83
|
+
function buildVersionLine(oldLine, newVer, oldVer, message, commentOverride = '') {
|
|
76
84
|
const m = /export const VERSION = '([^']+)';\s*\/\/(.*)$/.exec(oldLine);
|
|
77
85
|
const oldComment = m ? m[2].trim() : '';
|
|
78
86
|
// 旧版本的「本次说明」= 历史链之前的那一段
|
|
@@ -82,8 +90,12 @@ function buildVersionLine(oldLine, newVer, oldVer, message) {
|
|
|
82
90
|
// 历史链:新压入的旧版摘要 + 原有最近 1 条
|
|
83
91
|
const prev = oldMain ? [`${oldVer}:${oldMain}`] : [];
|
|
84
92
|
const kept = oldHist ? oldHist.split(/。\s*(?=[\d.]+:)/).slice(0, 1).map((s) => s.replace(/。$/, '')) : [];
|
|
85
|
-
const chain = [...prev, ...kept].join('。');
|
|
86
|
-
|
|
93
|
+
const chain = prev.length || kept.length ? [...prev, ...kept].join('。').replace(/。+/g, '。') : '';
|
|
94
|
+
// 本轮摘要:显式覆盖优先;否则取首段首句,超长截断
|
|
95
|
+
const oneLine = String(commentOverride || message).replace(/\s+/g, ' ').trim();
|
|
96
|
+
const firstSentence = oneLine.split(/。/)[0].trim();
|
|
97
|
+
const summary = firstSentence.length > 160 ? `${firstSentence.slice(0, 160)}…` : firstSentence;
|
|
98
|
+
const comment = `${newVer}:${summary}。` + (chain ? `历史:${chain}。` : '');
|
|
87
99
|
return `export const VERSION = '${newVer}'; // ${comment}`;
|
|
88
100
|
}
|
|
89
101
|
|
|
@@ -107,7 +119,10 @@ const selfLines = selfSrc.split('\n');
|
|
|
107
119
|
const vi = selfLines.findIndex((l) => /^export const VERSION = '/.test(l));
|
|
108
120
|
if (vi < 0) fail('lib/self/index.js 未找到 VERSION 行');
|
|
109
121
|
const oldLine = selfLines[vi];
|
|
110
|
-
const newLine = buildVersionLine(oldLine, target, cur, message);
|
|
122
|
+
const newLine = buildVersionLine(oldLine, target, cur, message, args.comment);
|
|
123
|
+
// 硬门禁:行注释一旦带换行就把整个 lib/self/index.js 撕成多行(ESM 加载期直接抛
|
|
124
|
+
// "Invalid or unexpected token",cli.mjs / 插件入口全部起不来)。宁可在写盘前失败。
|
|
125
|
+
if (/[\r\n]/.test(newLine)) fail('VERSION 行必须是单行(注释里的换行会破坏整个模块语法)');
|
|
111
126
|
|
|
112
127
|
// ── 预览(默认 dry-run)
|
|
113
128
|
console.log(`升版:${cur} → ${target}${args.apply ? '(--apply 真写盘)' : '(dry-run,未写盘)'}`);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* 拼接产物作用域撞名检查(独立 CLI;判定与策略逻辑在 lib/,与 `git-sluice scope-check` 同一份)。
|
|
4
|
+
*
|
|
5
|
+
* 用法:
|
|
6
|
+
* node scripts/check-js-scope.mjs <file.js> [...] [--prefix=dshgp_] [--allowlist=a,b] [--top=true|false] [--json]
|
|
7
|
+
* node scripts/check-js-scope.mjs --config package.json # 读该 package.json 的 dshScopeCheck.files
|
|
8
|
+
*
|
|
9
|
+
* 参数名与 `git-sluice scope-check` 对齐(allowlist,旧写法 --allow 仍认)。
|
|
10
|
+
* 约定按**文件所属项目**取:别人项目没声明 dshScopeCheck 时只查「同帧重名」,
|
|
11
|
+
* 不会拿本项目的 dshgp_ 前缀去要求它(实测:那会刷一屏与它无关的告警)。
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
14
|
+
import { dirname, join, resolve } from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
|
|
17
|
+
import { runScopeCheck } from '../lib/app/scope-check.js';
|
|
18
|
+
|
|
19
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
20
|
+
const argv = process.argv.slice(2);
|
|
21
|
+
const VALUE_FLAGS = new Set(['config', 'prefix', 'allowlist', 'allow', 'top']);
|
|
22
|
+
|
|
23
|
+
const { flags, positional } = (() => {
|
|
24
|
+
const out = { flags: new Map(), positional: [] };
|
|
25
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
26
|
+
const token = argv[i];
|
|
27
|
+
if (!token.startsWith('--')) { out.positional.push(token); continue; }
|
|
28
|
+
const body = token.slice(2);
|
|
29
|
+
if (body.includes('=')) {
|
|
30
|
+
const [k, ...rest] = body.split('=');
|
|
31
|
+
out.flags.set(k, rest.join('='));
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (VALUE_FLAGS.has(body) && i + 1 < argv.length && !argv[i + 1].startsWith('--')) {
|
|
35
|
+
out.flags.set(body, argv[i + 1]);
|
|
36
|
+
i += 1;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
out.flags.set(body, 'true');
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
})();
|
|
43
|
+
const wantJson = flags.has('json');
|
|
44
|
+
|
|
45
|
+
/** --config 指定的项目:只用它的 files 列表,**不**把它的 prefix 套给别的项目文件。 */
|
|
46
|
+
function filesFromConfig(path) {
|
|
47
|
+
if (!path || !existsSync(path)) return [];
|
|
48
|
+
try {
|
|
49
|
+
const cfg = JSON.parse(readFileSync(path, 'utf8'))?.dshScopeCheck;
|
|
50
|
+
const base = dirname(resolve(path));
|
|
51
|
+
return Array.isArray(cfg?.files) ? cfg.files.map((f) => resolve(base, f)) : [];
|
|
52
|
+
} catch { return []; }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const configPath = flags.get('config') || '';
|
|
56
|
+
const targets = positional.length ? positional.map((f) => resolve(f)) : filesFromConfig(configPath);
|
|
57
|
+
if (!targets.length) {
|
|
58
|
+
console.error('用法:node scripts/check-js-scope.mjs <file.js> [...] [--prefix=dshgp_] [--allowlist=a,b] [--json]');
|
|
59
|
+
console.error(' 或 node scripts/check-js-scope.mjs --config package.json(读 dshScopeCheck.files)');
|
|
60
|
+
process.exit(2);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const topFlag = flags.get('top');
|
|
64
|
+
const result = runScopeCheck({
|
|
65
|
+
files: targets,
|
|
66
|
+
prefix: flags.get('prefix') || '',
|
|
67
|
+
// allowlist 为主名(与 git-sluice scope-check 对齐),allow 是旧写法别名
|
|
68
|
+
allowlist: String(flags.get('allowlist') || flags.get('allow') || '').split(',').map((x) => x.trim()).filter(Boolean),
|
|
69
|
+
...(topFlag === 'true' || topFlag === 'false' ? { topLevelMustBeEmpty: topFlag === 'true' } : {}),
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (wantJson) {
|
|
73
|
+
console.log(JSON.stringify(result, null, 2));
|
|
74
|
+
} else {
|
|
75
|
+
// 输出头自证策略来源:避免「继承了本项目默认值」被误读成对方的约定
|
|
76
|
+
for (const src of result.policySources) console.log(`策略来源:${src}`);
|
|
77
|
+
for (const r of result.reports) {
|
|
78
|
+
const rel = r.file.replace(process.cwd() + '/', '');
|
|
79
|
+
if (r.ok) {
|
|
80
|
+
console.log(`✔ ${rel}:${r.declarations.length} 个声明,无同帧重名`);
|
|
81
|
+
} else {
|
|
82
|
+
console.error(`✗ ${rel}:`);
|
|
83
|
+
for (const v of r.violations) console.error(` - ${v}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
process.exit(result.ok ? 0 : 1);
|
package/scripts/check.mjs
CHANGED
|
@@ -83,6 +83,42 @@ try {
|
|
|
83
83
|
console.error(`✗ 分片构建校验失败:${e.message}`);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
// ── 拼接产物作用域门禁(2026-11-05)───────────────────────────────────
|
|
87
|
+
// 背景:lib/client-parts/*.js 是**平铺拼接**的片段,14 个分片最终落在**同一个 factory
|
|
88
|
+
// 函数作用域**里。JS 的 var/function 提升规则是「同名后者覆盖前者且不报错」——
|
|
89
|
+
// 一处重名就让某分片功能在运行时静默失效,且没有任何报错可查。
|
|
90
|
+
// 构建脚本头部早写了「顶层零声明 + dshgp_ 前缀」两条铁律,但此前**只是注释**:
|
|
91
|
+
// 新鲜度门禁只保证「产物 == 分片拼接」,保证不了「拼出来的不撞名」。
|
|
92
|
+
// 检查项(通用实现在 lib/ast/scope-collisions.js,项目差异走 package.json 的 dshScopeCheck):
|
|
93
|
+
// ① 同作用域重名(var/function 静默覆盖的触发条件,始终检查);
|
|
94
|
+
// ② 文件顶层零声明;③ 共享作用域命名前缀。
|
|
95
|
+
try {
|
|
96
|
+
const { analyzeScopeCollisions } = await import('../lib/ast/scope-collisions.js');
|
|
97
|
+
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
98
|
+
const cfg = pkg?.dshScopeCheck;
|
|
99
|
+
const files = Array.isArray(cfg?.files) && cfg.files.length ? cfg.files : [];
|
|
100
|
+
if (!files.length) {
|
|
101
|
+
console.log('✔ 拼接产物作用域:未配置 dshScopeCheck.files,跳过');
|
|
102
|
+
}
|
|
103
|
+
for (const rel of files) {
|
|
104
|
+
const abs = join(ROOT, rel);
|
|
105
|
+
const scope = analyzeScopeCollisions(readFileSync(abs, 'utf8'), {
|
|
106
|
+
prefix: String(cfg.prefix || ''),
|
|
107
|
+
allowlist: Array.isArray(cfg.allowlist) ? cfg.allowlist.map(String) : [],
|
|
108
|
+
topLevelMustBeEmpty: cfg.topLevelMustBeEmpty !== false,
|
|
109
|
+
});
|
|
110
|
+
if (scope.ok) {
|
|
111
|
+
console.log(`✔ ${rel} 作用域契约(顶层零声明 · 共享作用域 ${scope.declarations.filter((d) => d.frameId === scope.sharedFrameId).length} 个声明均合规 · 无同帧重名)`);
|
|
112
|
+
} else {
|
|
113
|
+
fail += 1;
|
|
114
|
+
for (const v of scope.violations) console.error(`✗ ${rel} 作用域:${v}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} catch (e) {
|
|
118
|
+
fail += 1;
|
|
119
|
+
console.error(`✗ 拼接产物作用域检查失败:${e.message}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
86
122
|
// ── 层边界门禁(2026-10-24)────────────────────────────────────────────
|
|
87
123
|
// 背景:审计引擎与提交推送**决定不拆成两个 npm 包**(拆包的持续成本——双包版本同步、
|
|
88
124
|
// 固定发布顺序、依赖范围——换不到真实收益:外部使用者要的是「提交前拦截」这个整体,
|
|
@@ -92,7 +128,9 @@ try {
|
|
|
92
128
|
// 不变量:
|
|
93
129
|
// ① 审计层任何文件都不得 import git/npm/commit-push 层(方向唯一:git → audit);
|
|
94
130
|
// ② 反向接缝数量有预算上限——允许存在(提交门禁必须调审计),但要能看见它在膨胀。
|
|
95
|
-
|
|
131
|
+
// lint-adapter(外部 linter 委托层)纳入审计层口径:编排层(audit)直接依赖它 ⇒ 它属于审计子图,
|
|
132
|
+
// 同样不得伸手 git 层(委托层只读项目文件 + 跑外部二进制,不需要凭据/git)。
|
|
133
|
+
const AUDIT_DIRS = new Set(['ast', 'audit', 'audit-rules', 'checks', 'exempt', 'rule', 'score', 'lint-adapter']);
|
|
96
134
|
const GIT_DIRS = new Set(['git', 'npm']);
|
|
97
135
|
const GIT_TOP = new Set(['commit-push.js']);
|
|
98
136
|
const AUDIT_TOP = new Set(['audit-defaults.js', 'skip-dirs.js']);
|
|
@@ -11,7 +11,7 @@ generatedBy: deepseek-official/deepseek-v4-flash · EIGHTfs 2026-10-02
|
|
|
11
11
|
> 定位:把「扫描仓库 → 审计门禁 → 一键 commit+push」固化为代码管道(零 token、确定性)。
|
|
12
12
|
> 本手册是使用说明;正常情况优先直接调用插件工具。
|
|
13
13
|
|
|
14
|
-
## 一、
|
|
14
|
+
## 一、21 个工具
|
|
15
15
|
|
|
16
16
|
| 工具 | 参数 | 说明 |
|
|
17
17
|
|---|---|---|
|
|
@@ -30,7 +30,12 @@ generatedBy: deepseek-official/deepseek-v4-flash · EIGHTfs 2026-10-02
|
|
|
30
30
|
| `git_cred_env` | — | 输出凭据环境变量前缀(SSH `GIT_SSH_COMMAND` / HTTPS `GIT_ASKPASS`,不含明文) |
|
|
31
31
|
| `git_gen_ssh_key` | `email`(必填), `force?` | 生成 SSH 密钥对(写入插件配置目录;私钥不出本机,公钥整行回传) |
|
|
32
32
|
| `git_sluice` | `args`(必填) | git 命令透传(凭据自动注入;返回 status + stdout/stderr 原文) |
|
|
33
|
-
| `git_api` | `path?`, `method?`, `query?`, `body?` | **直接调用本插件
|
|
33
|
+
| `git_api` | `path?`, `method?`, `query?`, `body?` | **直接调用本插件 36 条 HTTP API**(内部走 `handleHttp` 同一条代码路径,不另写实现);不传 `path` 则列出全部接口 |
|
|
34
|
+
| `npm_publish` | `dir?`, `dryRun?`(默认 true), `tag?`, `otp?`, `confirm?`, `skipSmoke?`, `localPreview?` | npm 发包(后台 job):默认只体检 + `npm publish --dry-run`;真发必须 `confirm=true` 且 `dryRun=false`;凭据由插件托管(无需 npm login) |
|
|
35
|
+
| `npm_unpublish` | `name`(必填), `version?`, `wholePackage?`, `dryRun?`(默认 true), `confirm?` | 撤包(不可逆):默认只预检(72h 窗口 / dist-tag 悬空 / 唯一版本冷却),真撤需 `dryRun=false` + `confirm=true` |
|
|
36
|
+
| `git_remote_rename` | `repo`(必填), `newName`(必填), `dryRun?`(默认 true), `updateRemotes?` | 远程仓库改名:默认只报告旧名出现位置,确认后 `dryRun=false` 才真改并同步本地 remote |
|
|
37
|
+
| `exempt` | `action`(必填), `repo?`, `path?`, `line?`, `scope?`, `rule?`, `marker?`, `reason?` | 注释豁免:按 `rule` 推导正确标记、写前校验真生效、`check` 识别死标记 |
|
|
38
|
+
| `scope_check` | `files?`, `repo?`, `prefix?`, `allowlist?`, `topLevelMustBeEmpty?` | 拼接产物作用域撞名(按真实作用域帧):同帧重名会**后者静默顶掉前者**;`files` 空=读项目 `dshScopeCheck.files`,前缀/顶层零声明按项目契约(没声明就只查同帧重名,不拿 `dshgp_` 要求别人) |
|
|
34
39
|
|
|
35
40
|
典型流程:`git_scan` 看改动 → `code_audit` 自查 → `git_commit_push`(审计通过才推)。
|
|
36
41
|
|
|
@@ -265,6 +270,7 @@ pnpm add github:EIGHTfs/dsh-git-push#<commit>
|
|
|
265
270
|
| `git_remote_create` | **`repo`**、`visibility?`(默认 private)、`dryRun?` | 同名存在则复用,否则创建并把 origin 指向 API 地址;`ensureRemoteRepo` |
|
|
266
271
|
| `git_set_visibility` | **`repo`**、**`visibility`** | `PATCH /repos/{owner}/{repo}` 的 private 字段;改 public 前须确认无凭据暴露;`setVisibility` |
|
|
267
272
|
| `link_check` | `path?`(缺省 workspaceRoot) | 分级扣分(404/403 −3、DNS −2、超时/5xx −1,flaky 域名 ×0.2);**只 warning 永不 blocker**;并发 10;`checkLinks`/`probeLinks` |
|
|
273
|
+
| `scope_check` | `files?`(逗号分隔,空=项目 `dshScopeCheck.files`)、`repo?`、`prefix?`、`allowlist?`、`topLevelMustBeEmpty?` | 按真实作用域帧查同帧重名;判定 `analyzeScopeCollisions`(`lib/ast/scope-collisions.js`)、契约 `readProjectScopePolicy`(`lib/audit/scope-policy.js`)、执行 `runScopeCheck`(`lib/app/scope-check.js`);违规时 CLI 退出码 1 |
|
|
268
274
|
|
|
269
275
|
**接线层**(`lib/plugin/index.js`,Host 侧四段真实 API):工具 `ctx.inject(['tools'])` → `register(defineTool(spec))`(`output.render` **必须返回块数组**);提示词注入 `inject(['systemPrompt'])` → `section({name, order, text})`;HTTP `inject(['webServer'])` → `register({kind:'prefix', path, handler})`;客户端**不在此注册**(由 package.json `dsh.client` + `exports["./client"]` 自动发现)。
|
|
270
276
|
|