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.
- package/README.md +22 -3
- package/assets/minihost.sh +35 -0
- package/assets/preview.html +36703 -0
- package/assets/start.sh +396 -0
- package/assets/tree-sitter/LICENSE +21 -0
- package/assets/tree-sitter/README.md +69 -0
- package/assets/tree-sitter/VERSIONS.txt +1 -0
- package/assets/tree-sitter/tree-sitter-javascript.wasm +0 -0
- package/assets/tree-sitter/tree-sitter-python.wasm +0 -0
- package/assets/tree-sitter/tree-sitter-typescript.wasm +0 -0
- package/assets/tree-sitter/tree-sitter.js +3980 -0
- package/assets/tree-sitter/tree-sitter.wasm +0 -0
- package/lib/app/apply.js +15 -2
- package/lib/app/audit-api.js +1 -1
- package/lib/app/command-registry.js +6 -2
- package/lib/app/handlers/workspace-paths.js +107 -0
- package/lib/app/http-handlers.js +19 -2
- package/lib/app/inject-text.js +1 -0
- package/lib/app/tool-call.js +38 -4
- package/lib/app/tools.js +5 -11
- package/lib/ast/code-lines.js +52 -0
- package/lib/ast/index.js +1 -1
- package/lib/ast/tokenizer.js +7 -2
- package/lib/ast/treesitter.js +208 -0
- package/lib/audit/audit-file.js +3 -3
- package/lib/audit/orchestrate.js +38 -0
- package/lib/audit-rules/audit-rules-nodejs.yml +2 -2
- package/lib/audit-rules/audit-rules-paths.yml +1 -1
- package/lib/audit-rules/audit-rules-performance.yml +12 -0
- package/lib/checks/dispatch.js +3 -3
- package/lib/checks/filter.js +7 -1
- package/lib/checks/regex.js +19 -4
- package/lib/commit-push.js +8 -4
- package/lib/core/workspace-paths.js +100 -0
- package/lib/git/push.js +9 -3
- package/lib/npm/publish.js +6 -2
- package/lib/npm/registry.js +23 -2
- package/lib/rule/registry.js +7 -0
- package/lib/self/index.js +4 -1
- package/lib/user-requirements.json +2 -1
- package/package.json +2 -1
- package/scripts/cpu-sample.mjs +188 -0
- package/scripts/sync-plugin-install.mjs +84 -21
- package/scripts/sync-plugin.mjs +14 -9
- package/skills/guide/guide-cli-scripts.md +1 -1
- package/skills/guide/guide-commit-push.md +33 -0
|
Binary file
|
package/lib/app/apply.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { VERSION } from '../self/index.js';
|
|
9
9
|
import { persistGithubToken, persistSshPub, credentialsDir } from '../git/index.js';
|
|
10
10
|
import { createEnvInjectionText, collectToolPaths, mapWorkspaceDirs } from '../context/index.js';
|
|
11
|
+
import { workspacePathsInjectionText } from '../core/workspace-paths.js';
|
|
11
12
|
import { defaultConfig, resolveConfig } from '../client/index.js';
|
|
12
13
|
import { loadDefineTool, registerTools, registerContext, registerHttp, registerPreStepInjection } from '../plugin/index.js';
|
|
13
14
|
// 【2026-10-02 · DSH 0.2.0-rc.2 适配】0.2.0 删除了 settings.register / settings.get 旧 API
|
|
@@ -98,7 +99,12 @@ export async function apply(ctx, config = {}) {
|
|
|
98
99
|
const envInjectText = (cwdOverride) => {
|
|
99
100
|
if (!cfg.injectSystemPrompt) return '';
|
|
100
101
|
const root = cwdOverride || env.workspaceRoot || process.cwd();
|
|
101
|
-
|
|
102
|
+
// AI 自设工作区(可多个)优先于会话 cwd:会话 header 里可能是**陈旧路径**(实测注入出
|
|
103
|
+
// 0.1.6-alpha.1 的旧工作区 ✗)⇒ 有自设就显示自设那份(这就是「AI 自己提醒自己」的实际作用 ✓)
|
|
104
|
+
const aiPaths = workspacePathsInjectionText();
|
|
105
|
+
// 缓存键必须带上自设清单:否则改完清单后注入不刷新 ✗(同一 root 会命中旧缓存)
|
|
106
|
+
const cacheKey = aiPaths ? `${root}\u0000${aiPaths}` : root;
|
|
107
|
+
if (envInjectCache instanceof Map && envInjectCache.has(cacheKey)) return envInjectCache.get(cacheKey);
|
|
102
108
|
let text = '';
|
|
103
109
|
try {
|
|
104
110
|
// 工具清单:lib/tool-probes.json 模板(只 key,跨平台裸名)→ which/where 实测
|
|
@@ -119,8 +125,15 @@ export async function apply(ctx, config = {}) {
|
|
|
119
125
|
log?.warn?.(`环境注入探测失败,降级静态清单:${e?.message || e}`);
|
|
120
126
|
text = createEnvInjectionText({ cwd: root, projectRoot: root });
|
|
121
127
|
}
|
|
128
|
+
// 自设工作区块放在**最前**:AI 每轮先看到自己登记的路径 ✓
|
|
129
|
+
// 同时把基座里的会话 cwd 行标注为「仅兜底」——它取自会话文件,实测可能是陈旧路径 ✗,
|
|
130
|
+
// 不标注就会与上方自设清单并存、继续误导(两处表达同一事实 ⇒ 必须区分主次)
|
|
131
|
+
if (aiPaths && text) {
|
|
132
|
+
text = text.replace(/^- 当前工作目录 cwd:/m, '- 会话 cwd(仅兜底,可能陈旧;以本段上方的「AI 自设工作区」为准):');
|
|
133
|
+
text = `${aiPaths}\n${text}`;
|
|
134
|
+
}
|
|
122
135
|
if (!(envInjectCache instanceof Map)) envInjectCache = new Map();
|
|
123
|
-
envInjectCache.set(
|
|
136
|
+
envInjectCache.set(cacheKey, text);
|
|
124
137
|
return text;
|
|
125
138
|
};
|
|
126
139
|
|
package/lib/app/audit-api.js
CHANGED
|
@@ -104,7 +104,7 @@ export async function runAuditApi(repo, params = {}, cfg = {}) {
|
|
|
104
104
|
scope,
|
|
105
105
|
rulesetDir: params.rulesetDir || '',
|
|
106
106
|
maxScanFiles: params.maxScanFiles ?? cfg.maxScanFiles ?? 0,
|
|
107
|
-
slots:
|
|
107
|
+
slots: undefined, // auditRuleOrder 是「加载顺序」不是白名单 ✗(详见 lib/commit-push.js 注释;禁用槽位用 auditDisabledSlots ✓)
|
|
108
108
|
disabledSlots: Array.isArray(cfg.auditDisabledSlots) ? cfg.auditDisabledSlots : [],
|
|
109
109
|
includeIgnored: params.includeIgnored === true,
|
|
110
110
|
};
|
|
@@ -26,7 +26,11 @@ export const TOOL_REGISTRY = [
|
|
|
26
26
|
name: 'git_commit_push', cli: 'commit', description: '一键提交并推送:一次调用 = 审计(blocker 拦截,可关)→ 有改动才 commit → 有可推内容才 push。零改动是**正常成功路径**:返回 ok:true + committed:false(job 状态 completed,不是失败);远端已最新则 ok:true + pushed:false;本地领先远端的已提交内容照样会推。message 必填(零改动时用不到);requirementsConfirmed=true(开发者要求全部核对达标)——**存在要求清单时任何调用都要带**(与有无改动、是否推送无关);push=false 只提交;dryRun 只模拟',
|
|
27
27
|
params: [
|
|
28
28
|
{ flag: 'repo', type: 'string', positional: 0, required: true, desc: '仓库绝对路径' },
|
|
29
|
-
{ flag: 'message', type: 'string',
|
|
29
|
+
{ flag: 'message', type: 'string', required: true, desc: 'commit message(字符串,必填):可写整条提交信息;要传结构化多条目请用 messageItems(它会作为要点与正文)' },
|
|
30
|
+
// ⚠️ 数组/对象形态**必须走独立参数**:宿主在进插件之前先按工具 JSON schema 校验参数,
|
|
31
|
+
// 而它对 message 这类标量参数只认 type:'string'(实测 anyOf 与「类型数组」两种写法
|
|
32
|
+
// 都被读成 string ✗,报 invalid arguments: "message" must be a string ⇒ 非字符串根本到不了插件 ✓)
|
|
33
|
+
{ flag: 'messageItems', type: 'array', desc: '结构化条目数组:元素为字符串,或 {what,type?,scope?,why?,verify?,refs?};仅 what 必填,type/scope/why/verify/refs 可空' },
|
|
30
34
|
{ flag: 'push', type: 'boolean', default: true, desc: '是否推送(默认 true)' },
|
|
31
35
|
{ flag: 'audit', type: 'boolean', desc: '提交前审计(默认取配置)' },
|
|
32
36
|
{ flag: 'dryRun', type: 'boolean', desc: 'dry-run 只模拟不写入' },
|
|
@@ -171,7 +175,7 @@ export const TOOL_REGISTRY = [
|
|
|
171
175
|
],
|
|
172
176
|
},
|
|
173
177
|
{
|
|
174
|
-
name: 'git_api', cli: 'api', description: '直接调用本插件的 HTTP API(
|
|
178
|
+
name: 'git_api', cli: 'api', description: '直接调用本插件的 HTTP API(35 条接口,与浏览器/CLI 同源实现:内部走 handleHttp 同一条代码路径)。path=接口名(去掉 /api/git-push/ 前缀,如 status / rule-slots / audit / settings-get);method 默认 GET;query=查询参数 JSON(如 {"mode":"full"});body=POST 请求体 JSON;不传 path 则列出全部可用接口。写类接口(settings-set / repo-push 等)内部调用按本机同源放行。',
|
|
175
179
|
params: [
|
|
176
180
|
{ flag: 'path', type: 'string', positional: 0, desc: '接口名(缺省 = 列出全部接口)' },
|
|
177
181
|
{ flag: 'method', type: 'string', desc: 'HTTP 方法(默认 GET;写操作传 POST)' },
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 处理层 · AI 自设工作区路径端点(workspace-paths)
|
|
3
|
+
*
|
|
4
|
+
* 一个端点两种方法(handleHttp 的 switch 按路径分发,方法在 ctx.method 里):
|
|
5
|
+
* · GET /api/git-push/workspace-paths
|
|
6
|
+
* 读回当前自设清单 + 注入文本预览(AI 用它自查「我登记的路径对不对」✓)
|
|
7
|
+
* · POST /api/git-push/workspace-paths
|
|
8
|
+
* 写自设清单。body 支持三种形态(都走同一套校验):
|
|
9
|
+
* { "paths": ["<绝对路径>", …] } 默认 set(整份替换)
|
|
10
|
+
* { "paths": [...], "mode": "add" } 追加(去重)
|
|
11
|
+
* { "paths": [...], "mode": "remove" } 移除
|
|
12
|
+
* { "path": "<绝对路径>", "mode": "add" } 单条简写
|
|
13
|
+
* 也支持 { "clear": true } 清空(回到「无自设 ⇒ 注入回退会话 cwd」)。
|
|
14
|
+
*
|
|
15
|
+
* 为什么要这个端点:环境注入里的 cwd 原先取自会话文件,实测会注入**陈旧路径**(本机注入出
|
|
16
|
+
* `…/0.1.6-alpha.1/工作区/…`,而真实工作区在别处)⇒ 让 AI 自己登记真实路径,注入优先显示它。
|
|
17
|
+
* 这正是「AI 自己提醒自己」的实现方式:注入里显示的就是 AI 自己写下的那份 ✓
|
|
18
|
+
*/
|
|
19
|
+
import {
|
|
20
|
+
loadWorkspacePaths, saveWorkspacePaths, workspacePathsInjectionText, workspacePathsFile, MAX_WORKSPACE_PATHS,
|
|
21
|
+
} from '../../core/workspace-paths.js';
|
|
22
|
+
|
|
23
|
+
/** 从 body 取待处理路径数组(paths 数组优先;兼容单条 path 字符串)。 */
|
|
24
|
+
function pathsFromBody(body) {
|
|
25
|
+
if (Array.isArray(body?.paths)) return body.paths.map((x) => String(x || ''));
|
|
26
|
+
if (typeof body?.path === 'string' && body.path.trim()) return [body.path];
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** GET /api/git-push/workspace-paths —— 读自设清单 + 注入预览。 */
|
|
31
|
+
export function handleWorkspacePathsGet() {
|
|
32
|
+
const cur = loadWorkspacePaths();
|
|
33
|
+
const text = workspacePathsInjectionText();
|
|
34
|
+
return {
|
|
35
|
+
status: 200,
|
|
36
|
+
body: {
|
|
37
|
+
ok: true,
|
|
38
|
+
paths: cur.paths,
|
|
39
|
+
count: cur.paths.length,
|
|
40
|
+
updatedAt: cur.updatedAt,
|
|
41
|
+
updatedBy: cur.updatedBy,
|
|
42
|
+
file: workspacePathsFile(),
|
|
43
|
+
maxPaths: MAX_WORKSPACE_PATHS,
|
|
44
|
+
injection: text, // 注入时会显示成什么样(AI 自查用 ✓)
|
|
45
|
+
injectionActive: !!text, // false = 无自设 ⇒ 注入回退会话 cwd
|
|
46
|
+
usage: "POST 同路径写入:body {\"paths\":[\"<绝对路径>\", …], \"mode\":\"set|add|remove\"};{\"clear\":true} 清空",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** POST /api/git-push/workspace-paths —— 写自设清单(set / add / remove / clear)。 */
|
|
52
|
+
export function handleWorkspacePathsSet(ctx) {
|
|
53
|
+
// body 容错:工具路径传的是**已解析对象**(tool-call 里 JSON.parse 后转字符串再交给 handleHttp),
|
|
54
|
+
// CLI 路径实测传进来的是**JSON 字符串**(`--body '{…}'` 原样)⇒ 两种都接受,
|
|
55
|
+
// 否则 CLI 调用会报「缺少 paths」而实际是 body 没被解析 ✗(2026-10-15 实测踩到)。
|
|
56
|
+
let body = ctx?.body;
|
|
57
|
+
if (typeof body === 'string') {
|
|
58
|
+
try { body = JSON.parse(body || '{}'); } catch { body = {}; }
|
|
59
|
+
}
|
|
60
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)) body = {};
|
|
61
|
+
const mode = String(body.mode || 'set').toLowerCase();
|
|
62
|
+
const cur = loadWorkspacePaths();
|
|
63
|
+
|
|
64
|
+
if (body.clear === true || mode === 'clear') {
|
|
65
|
+
const r = saveWorkspacePaths([], { by: 'ai' });
|
|
66
|
+
return { status: r.ok ? 200 : 500, body: { ok: r.ok, mode: 'clear', paths: r.paths, error: r.rejected[0]?.reason } };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const input = pathsFromBody(body);
|
|
70
|
+
if (!input.length) {
|
|
71
|
+
return { status: 400, body: { ok: false, error: '缺少 paths(数组)或 path(字符串);清空请传 {"clear":true}' } };
|
|
72
|
+
}
|
|
73
|
+
if (!['set', 'add', 'remove'].includes(mode)) {
|
|
74
|
+
return { status: 400, body: { ok: false, error: `不支持的 mode: ${mode}(仅 set/add/remove/clear)` } };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (mode === 'remove') {
|
|
78
|
+
// 移除按「字符串相等」比对(用户/AI 写进来的原样路径),避免因 resolve 差异删不掉
|
|
79
|
+
const want = new Set(input.map((x) => String(x).trim()).filter(Boolean));
|
|
80
|
+
const kept = cur.paths.filter((p) => !want.has(p));
|
|
81
|
+
const r = saveWorkspacePaths(kept, { by: 'ai' });
|
|
82
|
+
return {
|
|
83
|
+
status: r.ok ? 200 : 500,
|
|
84
|
+
body: { ok: r.ok, mode, removed: cur.paths.length - kept.length, paths: r.paths, error: r.rejected[0]?.reason },
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const next = mode === 'add' ? [...cur.paths, ...input] : input;
|
|
89
|
+
const r = saveWorkspacePaths(next, { by: 'ai' });
|
|
90
|
+
// 全部条目被拒(如全是相对路径/不存在的目录)⇒ 必须报错,不能"成功但空"✗
|
|
91
|
+
// —— 否则调用方会以为写进去了,下一轮注入却什么都没有(实测过的误判形态)
|
|
92
|
+
const allRejected = r.paths.length === 0 && input.length > 0;
|
|
93
|
+
const okFinal = r.ok && !allRejected;
|
|
94
|
+
return {
|
|
95
|
+
status: okFinal ? 200 : 400,
|
|
96
|
+
body: {
|
|
97
|
+
ok: okFinal,
|
|
98
|
+
mode,
|
|
99
|
+
paths: r.paths,
|
|
100
|
+
count: r.paths.length,
|
|
101
|
+
rejected: r.rejected, // 被拒的路径 + 原因(相对路径 / 不存在 / 超上限)
|
|
102
|
+
file: r.file,
|
|
103
|
+
injection: workspacePathsInjectionText(),
|
|
104
|
+
error: okFinal ? undefined : (r.rejected[0]?.reason || '写入失败'),
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
package/lib/app/http-handlers.js
CHANGED
|
@@ -27,6 +27,9 @@ import {
|
|
|
27
27
|
import {
|
|
28
28
|
handleSettingsGet, handleSettingsSet,
|
|
29
29
|
} from './handlers/settings.js';
|
|
30
|
+
import {
|
|
31
|
+
handleWorkspacePathsGet, handleWorkspacePathsSet,
|
|
32
|
+
} from './handlers/workspace-paths.js';
|
|
30
33
|
import {
|
|
31
34
|
handleNpmAccount, handleNpmCheck, handleNpmOwned, handleNpmPackages, handleNpmInstall, handleNpmPublish,
|
|
32
35
|
} from './handlers/npm.js';
|
|
@@ -56,10 +59,21 @@ export async function adaptHttpHandler(req, res, env, cfg) {
|
|
|
56
59
|
return httpResult;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
|
-
/** POST JSON
|
|
62
|
+
/** POST JSON 体:接受对象,**也接受 JSON 字符串**(内部调用传的是字符串)。 */
|
|
60
63
|
function readBody(req) {
|
|
61
64
|
const raw = req && req['body'];
|
|
62
|
-
|
|
65
|
+
if (raw && typeof raw === 'object' && !Array.isArray(raw)) return raw;
|
|
66
|
+
// 内部调用(git_api 工具 / CLI)把 body 以 **JSON 字符串** 传入(tool-call.js 里
|
|
67
|
+
// `body: bodyText`);原先一律当空对象 ⇒ **所有 POST 端点的 body 被静默丢弃** ✗
|
|
68
|
+
// (实测 2026-10-15:workspace-paths 的 POST 经工具/CLI 调用时 body 恒为空,
|
|
69
|
+
// 而浏览器路径走 adaptHttpHandler 的 readJsonBody ⇒ 正常 ✓ ⇒ 两条路径行为分叉)
|
|
70
|
+
if (typeof raw === 'string' && raw.trim()) {
|
|
71
|
+
try {
|
|
72
|
+
const j = JSON.parse(raw);
|
|
73
|
+
return (j && typeof j === 'object' && !Array.isArray(j)) ? j : {};
|
|
74
|
+
} catch { return {}; }
|
|
75
|
+
}
|
|
76
|
+
return {};
|
|
63
77
|
}
|
|
64
78
|
|
|
65
79
|
/** 统一构造 handler 上下文(各 handler 签名 handleXxx(ctx))。 */
|
|
@@ -125,6 +139,9 @@ export async function handleHttp(req = {}, env = {}, cfg = defaultConfig()) {
|
|
|
125
139
|
case '/api/git-push/gen-ssh-key': return handleGenSshKey(ctx);
|
|
126
140
|
case '/api/git-push/settings-get': return handleSettingsGet(ctx);
|
|
127
141
|
case '/api/git-push/settings-set': return await handleSettingsSet(ctx);
|
|
142
|
+
// AI 自设工作区路径:同一路径按 HTTP 方法分发(GET 读清单 / POST 写清单)
|
|
143
|
+
case '/api/git-push/workspace-paths':
|
|
144
|
+
return method === 'POST' ? handleWorkspacePathsSet(ctx) : handleWorkspacePathsGet(ctx);
|
|
128
145
|
default:
|
|
129
146
|
return { status: 404, body: { ok: false, code: 'NOT_FOUND', message: `无此端点: ${method} ${path}` } };
|
|
130
147
|
}
|
package/lib/app/inject-text.js
CHANGED
|
@@ -42,6 +42,7 @@ export const FUNCTION_USAGE_HINT = [
|
|
|
42
42
|
'【凭据由插件托管,不要到处找凭据】GitHub token 与 SSH 公钥存放在插件 config.json(git-push/config.json 的 githubToken、sshPub 键,0600);SSH 私钥仍为文件(git-push/id_rsa),由插件的推送/校验流程自动读取与选择通道(默认 SSH,token 401 回退 SSH)。',
|
|
43
43
|
'需要判断登录态 → 调 git_account_check;需要推送 → 调 git_commit_push。不要遍历用户目录找 token、不要把凭据抄进命令行或文档、不要在回复里明文输出凭据。',
|
|
44
44
|
'【调用纪律】提交类操作先 git_scan 确认目标仓库;提交前核对 README(功能表/版本记录/用法);审计拦截 blocker 时先修复再提交;用户未要求推送时不要 push。',
|
|
45
|
+
'· message 参数:**只能传字符串**(宿主在进插件前按工具 schema 校验,只认标量类型——数组/对象会被直接拒 ✗)。**推荐用法**:`message` 传标题字符串 + `messageItems` 传要点数组(元素为字符串,或 {what,type?,scope?,why?,verify?,refs?};仅 what 必填)⇒ 渲染成「标题 + 要点 + why/verify/refs 正文」✓。**该用它的信号**:① 一次提交含多个要点 ② 需要 why/verify 溯源;简单一句话就能说清时用字符串即可(不必强行结构化 ✗)',
|
|
45
46
|
'(这些纪律只在**会产生新提交/要推送**时才起作用;工作区没改动时直接调用 git_commit_push 也不会报错——不要因为「没东西可提交」就绕开插件手敲 git。)',
|
|
46
47
|
].join('\n');
|
|
47
48
|
|
package/lib/app/tool-call.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 与 HTTP 处理分开:两条入口(工具 / HTTP)的鉴权与返回形态完全不同。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
9
|
+
import { existsSync, readFileSync, appendFileSync } from 'node:fs';
|
|
10
10
|
import { MAX_MSG_PREVIEW } from './constants.js';
|
|
11
11
|
import { access } from 'node:fs/promises';
|
|
12
12
|
/** blocked 消息预览截断长度(工具返回精简——完整 message 走审计明细)。 */
|
|
@@ -57,6 +57,7 @@ async function pushWithPostSteps(args, env, cfg) {
|
|
|
57
57
|
const r = await commitAndPush({
|
|
58
58
|
repoPath: args.repo,
|
|
59
59
|
message: args.message,
|
|
60
|
+
messageItems: args.messageItems,
|
|
60
61
|
push: args.push !== false,
|
|
61
62
|
dryRun: args.dryRun === true,
|
|
62
63
|
customIgnorePatterns: args.ignorePatterns || '',
|
|
@@ -69,6 +70,30 @@ async function pushWithPostSteps(args, env, cfg) {
|
|
|
69
70
|
// 精确 add 路径(逗号分隔,相对 repo);空 = git add -A 全量
|
|
70
71
|
paths: String(args.paths || ''),
|
|
71
72
|
});
|
|
73
|
+
// ── 鼓励使用结构化提交信息(messageItems):提醒 + 采用率留痕 ──────────────────
|
|
74
|
+
// 为什么需要:默认路径(单串 message)更省事,结构化参数长期无人用 ⇒ 两件事互补:
|
|
75
|
+
// ① **该用时提醒**:调用方只传单串、且它偏长或含换行 ⇒ 结果里带 usageHint(随 job 结果 JSON 回到调用方)
|
|
76
|
+
// ② **采用率留痕**:每次调用追加一行 JSON 到 <DSH_HOME>/git-push/commit-usage.log ⇒ 用数据判断是否有效
|
|
77
|
+
// 判定信号 = 「多要点」或「需要 why/verify 溯源」;简单一句话提交用字符串完全正确 ✓(不强行结构化 ✗)
|
|
78
|
+
const msgStr = typeof args.message === 'string' ? args.message : '';
|
|
79
|
+
const itemList = Array.isArray(args.messageItems) ? args.messageItems : null;
|
|
80
|
+
const looksStructured = msgStr.includes('\n') || msgStr.length > 150;
|
|
81
|
+
if (r && !itemList && looksStructured) {
|
|
82
|
+
r.usageHint = '本次提交信息是**单串**且偏长;若含多个要点或需要 why/verify 溯源,建议改用 messageItems'
|
|
83
|
+
+ '(数组:元素为字符串或 {what,type?,scope?,why?,verify?,refs?},仅 what 必填)'
|
|
84
|
+
+ '——message 作标题、条目渲染成要点与正文 ✓';
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
if (process.env.DSH_HOME) {
|
|
88
|
+
appendFileSync(join(process.env.DSH_HOME, 'git-push', 'commit-usage.log'), JSON.stringify({
|
|
89
|
+
t: new Date().toISOString(),
|
|
90
|
+
structured: !!itemList,
|
|
91
|
+
items: itemList ? itemList.length : 0,
|
|
92
|
+
msgLen: msgStr.length,
|
|
93
|
+
repo: String(args.repo || '').slice(-60),
|
|
94
|
+
}) + '\n');
|
|
95
|
+
}
|
|
96
|
+
} catch { /* 留痕失败不影响提交 ✓ */ }
|
|
72
97
|
if (r?.ok && r?.pushed) {
|
|
73
98
|
try {
|
|
74
99
|
// 统一走 updateRepoIndex(mode='rebuild' 合并不全量覆盖),
|
|
@@ -120,6 +145,11 @@ export function pushJobOutcome(r = {}) {
|
|
|
120
145
|
const why = res.error || (res.blocked ? '推送被拦截' : '未完成');
|
|
121
146
|
return { status: 'failed', detail: res.blocked ? `未推送(被拦截):${why}` : `未完成:${why}` };
|
|
122
147
|
}
|
|
148
|
+
// dry-run:**什么都没写** ⇒ 文案必须自证「模拟」,不能说「已提交」✗(实测回执曾误报「已提交,未推送」)
|
|
149
|
+
if (res.dryRun === true) {
|
|
150
|
+
const st = Array.isArray(res.steps) && res.steps.length ? `(步骤:${res.steps.join(' → ')})` : '';
|
|
151
|
+
return { status: 'completed', detail: `dry-run 模拟完成:**未提交、未推送**${st}` };
|
|
152
|
+
}
|
|
123
153
|
const pushInfo = res.push || {};
|
|
124
154
|
if (res.pushed === true) {
|
|
125
155
|
if (pushInfo.verified === false) {
|
|
@@ -262,7 +292,11 @@ async function callNpmPublishJob(args = {}, jobs, exec, log, env = {}, cfg = {})
|
|
|
262
292
|
confirm: args.confirm === true,
|
|
263
293
|
});
|
|
264
294
|
const outcome = (r) => (r && r.ok
|
|
265
|
-
|
|
295
|
+
// 完成态必须用宿主认可的枚举值:`completed`(不是 `done` ✗)——
|
|
296
|
+
// 历史缺陷:这里写 `status:'done'`,宿主 job_output 的校验只认
|
|
297
|
+
// running|stopping|completed|killed|failed ⇒ 已完成的 job 一律读不出(报
|
|
298
|
+
// `"value.job.status" must be one of [...]`),表现为「等了很久,结果似乎没成功」✗。
|
|
299
|
+
? { status: 'completed', output: JSON.stringify(r) }
|
|
266
300
|
: { status: 'failed', detail: String((r && (r.error || r.blocked)) || 'npm publish 失败'), output: JSON.stringify(r || {}) });
|
|
267
301
|
if (!jobs || typeof jobs.start !== 'function') {
|
|
268
302
|
const r = await doPublish();
|
|
@@ -327,7 +361,7 @@ async function callCommitPush(args, env, cfg, log, jobs, exec) {
|
|
|
327
361
|
audit: args.audit,
|
|
328
362
|
// 不再透传 auditLevel——审计固定走完整流程(正则初筛 + AST 语义检查)
|
|
329
363
|
rulesetDir: args.ruleset,
|
|
330
|
-
slots:
|
|
364
|
+
slots: undefined, // auditRuleOrder 是「加载顺序」不是白名单 ✗(详见 lib/commit-push.js 注释;禁用槽位用 auditDisabledSlots ✓)
|
|
331
365
|
cfg,
|
|
332
366
|
});
|
|
333
367
|
if (!auditGate.ok) return auditGate; // { ok:false, blocked:true, audit }
|
|
@@ -374,7 +408,7 @@ function buildAuditOpts(args, cfg, scope) {
|
|
|
374
408
|
scope,
|
|
375
409
|
rulesetDir: args.ruleset || '',
|
|
376
410
|
maxScanFiles: cfg.maxScanFiles,
|
|
377
|
-
slots:
|
|
411
|
+
slots: undefined, // auditRuleOrder 是「加载顺序」不是白名单 ✗(详见 lib/commit-push.js 注释;禁用槽位用 auditDisabledSlots ✓)
|
|
378
412
|
disabledSlots: Array.isArray(cfg.auditDisabledSlots) ? cfg.auditDisabledSlots : [],
|
|
379
413
|
includeIgnored: args.includeIgnored === true,
|
|
380
414
|
// 分析覆盖率信息项(默认开;coverage:false 关闭——大仓库省一次读取+解析)
|
package/lib/app/tools.js
CHANGED
|
@@ -12,17 +12,11 @@ import { TOOL_REGISTRY } from './command-registry.js';
|
|
|
12
12
|
function paramsToParameters(params = []) {
|
|
13
13
|
const out = {};
|
|
14
14
|
for (const p of params) {
|
|
15
|
-
// 参数类型 → JSON schema
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
{ type: 'string' },
|
|
21
|
-
{ type: 'array', items: { anyOf: [{ type: 'string' }, { type: 'object' }] } },
|
|
22
|
-
{ type: 'object' },
|
|
23
|
-
],
|
|
24
|
-
description: p.desc || '',
|
|
25
|
-
};
|
|
15
|
+
// 参数类型 → JSON schema:**只产出宿主认的标量类型**(boolean / string / array)——
|
|
16
|
+
// 实测宿主校验不认 anyOf、也不认 JSON Schema 的「类型数组」写法(都按 string 处理 ✗,
|
|
17
|
+
// 报 invalid arguments: "x" must be a string)⇒ 复杂形态一律拆成独立参数 ✓
|
|
18
|
+
if (p.type === 'array') {
|
|
19
|
+
out[p.flag] = { type: 'array', description: p.desc || '' };
|
|
26
20
|
} else {
|
|
27
21
|
out[p.flag] = { type: p.type === 'boolean' ? 'boolean' : 'string', description: p.desc || '' };
|
|
28
22
|
}
|
package/lib/ast/code-lines.js
CHANGED
|
@@ -46,6 +46,58 @@ export function makeCodeLineFilter(text = '', candidateLines = [], opts = {}) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/* ───────────────────────── 列级精筛(行级判定的加强版) ───────────────────────── */
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 正则初筛 → **列级** token 精筛。
|
|
53
|
+
*
|
|
54
|
+
* 为什么需要:行级判定只能回答「这一行有没有代码 token」,回答不了
|
|
55
|
+
* 「正则命中的**那一处**是不是落在字符串/注释里」。实测遗留误报:
|
|
56
|
+
*
|
|
57
|
+
* const hang = await provider.execute(session, { script: 'while (true) {}' });
|
|
58
|
+
*
|
|
59
|
+
* 该行确实含 ident(script / provider 等)⇒ 行级判定放行 ⇒
|
|
60
|
+
* performance/busy-wait-loop 把字符串字面量里的 while(true) 当成真实死循环报出 ✗。
|
|
61
|
+
*
|
|
62
|
+
* 做法:在行级判定之上,用 tokenizer 的 str/tmpl/comment token 构造「不透明区间」,
|
|
63
|
+
* 命中列落在区间内 ⇒ 判为「不是代码」。
|
|
64
|
+
*
|
|
65
|
+
* @param {string} text 文件全文
|
|
66
|
+
* @param {number[]} candidateLines 候选行(1-based)
|
|
67
|
+
* @param {{file?:string}} [opts]
|
|
68
|
+
* @returns {{isCode:(line:number)=>boolean, isCodeHit:(line:number, col:number)=>boolean}}
|
|
69
|
+
* isCodeHit 的 col 为 **1-based 列**(正则 exec 的 index + 1);
|
|
70
|
+
* 列缺失/非法时**退化为行级判定**(宁可放行,不因拿不到列而误杀)。
|
|
71
|
+
*/
|
|
72
|
+
export function makeCodeSpanFilter(text = '', candidateLines = [], opts = {}) {
|
|
73
|
+
const base = makeCodeLineFilter(text, candidateLines, opts);
|
|
74
|
+
// 不透明区间只取**单行 token**:跨行 token(三引号/多行块注释)的 col 是续行内位置,
|
|
75
|
+
// 用它构造区间会算错。跨行场景本就由行级判定覆盖——续行不产 ident/num ⇒ 不算代码行。
|
|
76
|
+
const opaque = new Map(); // line → [[startCol, endColExclusive), ...]
|
|
77
|
+
for (const t of tokenize(text)) {
|
|
78
|
+
if (t.type !== 'str' && t.type !== 'tmpl' && t.type !== 'comment') continue;
|
|
79
|
+
const v = String(t.value);
|
|
80
|
+
if (v.includes('\n')) continue;
|
|
81
|
+
const col = Number(t.col);
|
|
82
|
+
if (!Number.isFinite(col) || col < 1) continue;
|
|
83
|
+
const arr = opaque.get(t.line) || [];
|
|
84
|
+
arr.push([col, col + v.length]);
|
|
85
|
+
opaque.set(t.line, arr);
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
isCode: base.isCode,
|
|
89
|
+
isCodeHit: (line, col) => {
|
|
90
|
+
if (!base.isCode(line)) return false;
|
|
91
|
+
const ranges = opaque.get(line);
|
|
92
|
+
if (!ranges || !ranges.length) return true;
|
|
93
|
+
const c = Number(col);
|
|
94
|
+
if (!Number.isFinite(c) || c < 1) return true; // 拿不到列 ⇒ 退化为行级判定
|
|
95
|
+
for (const [s, e] of ranges) if (c >= s && c < e) return false;
|
|
96
|
+
return true;
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
49
101
|
/**
|
|
50
102
|
* 是否散文体文档 —— **只按扩展名判定**。
|
|
51
103
|
*
|
package/lib/ast/index.js
CHANGED
|
@@ -22,7 +22,7 @@ export { checkSyncFs, checkEmptyCatchAst, checkComplexityAst, checkNestingDepthA
|
|
|
22
22
|
export { checkFuncLinesAst, checkFuncDensityAst, funcRangesAst, maxFunctionLength, checkFileLines, countCommentLines, checkRepeatedStringsAst, checkCommentDensityAst } from './size.js';
|
|
23
23
|
export { checkNameLengthAst, checkShortFunctionNameAst, checkSmallFileReadAst, checkConsoleLogJsonAst } from './naming.js';
|
|
24
24
|
export { javaKtFuncRanges, detectLang } from './lang.js';
|
|
25
|
-
export { makeCodeLineFilter, codeStringLiterals } from './code-lines.js';
|
|
25
|
+
export { makeCodeLineFilter, makeCodeSpanFilter, codeStringLiterals } from './code-lines.js';
|
|
26
26
|
export { shellCdDynamicLines, writeIntoGitignoredLines } from './shell.js';
|
|
27
27
|
export { checkMagicNumberSmartAst } from './magic-number.js';
|
|
28
28
|
export {
|
package/lib/ast/tokenizer.js
CHANGED
|
@@ -43,7 +43,7 @@ let TOKEN_CACHE_BYTES = 0;
|
|
|
43
43
|
* 返回的是**共享数组**——调用方只读,禁止原地修改(push/splice/sort)。
|
|
44
44
|
*
|
|
45
45
|
* @param {string} text 文件全文
|
|
46
|
-
* @returns {Array<{type:string, value:string, line:number}>}
|
|
46
|
+
* @returns {Array<{type:string, value:string, line:number, col:number}>}
|
|
47
47
|
* type: ident / punct / str / tmpl / comment / num / ws / other
|
|
48
48
|
*/
|
|
49
49
|
export function tokenize(text = '') {
|
|
@@ -103,7 +103,12 @@ function tokenizeUncached(text = '') {
|
|
|
103
103
|
const src = raw;
|
|
104
104
|
let i = 0;
|
|
105
105
|
const n = src.length;
|
|
106
|
-
|
|
106
|
+
// col = token 起始列(1-based,行内)。用途:**列级精筛** —— 行级判定只能回答
|
|
107
|
+
// 「这一行有没有代码」,回答不了「正则命中的那一处是不是落在字符串/注释里」
|
|
108
|
+
// (实测遗留误报:`{ script: 'while (true) {}' }` 里的 while(true) 被当真实死循环)。
|
|
109
|
+
// ⚠️ 跨行 token(三引号 / 多行块注释)的 col 是**续行内位置**、不是 token 真实起点 ⇒
|
|
110
|
+
// 消费方必须跳过 value 含换行的 token(见 lib/ast/code-lines.js 的区间构造)。
|
|
111
|
+
const push = (type, value) => tokens.push({ type, value, line, col: i + 1 });
|
|
107
112
|
while (i < n) {
|
|
108
113
|
const ch = src[i];
|
|
109
114
|
const next = src[i + 1];
|