dsh-git-push 2.20.18 → 3.0.0
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 +3 -2
- package/cli-tool.mjs +2 -4
- package/cli.mjs +36 -2
- package/lib/app/apply.js +9 -9
- package/lib/app/command-registry.js +44 -20
- package/lib/app/handlers/meta.js +7 -142
- package/lib/app/handlers/npm.js +18 -1
- package/lib/app/handlers/preprocess.js +107 -0
- package/lib/app/handlers/repo-actions.js +2 -2
- package/lib/app/http-handlers.js +25 -12
- package/lib/app/index.js +2 -1
- package/lib/app/inject-text.js +3 -2
- package/lib/app/preprocess-client.js +136 -0
- package/lib/app/repo-ownership.js +1 -1
- package/lib/app/schema.js +3 -3
- package/lib/app/severity.js +14 -0
- package/lib/app/slash-commands.js +5 -164
- package/lib/app/tool-call.js +75 -140
- package/lib/app/tools.js +13 -6
- package/lib/cli/commands-preprocess.mjs +74 -0
- package/lib/cli/commands-tool.mjs +3 -2
- package/lib/cli/commands-vcs.mjs +4 -4
- package/lib/cli/shared.mjs +42 -13
- package/lib/client-parts/git/controller.js +2 -2
- package/lib/client.js +2 -2
- package/lib/commit-push/pre-commit-engine.js +57 -10
- package/lib/commit-push.js +125 -36
- package/lib/{exempt/index.js → git/exempt-markers.js} +8 -1
- package/lib/git/ignore.js +1 -1
- package/lib/git/repos.js +2 -2
- package/lib/git/sensitive.js +1 -1
- package/lib/npm/publish.js +20 -5
- package/lib/plugin/auto-push.js +2 -2
- package/lib/preprocess/providers.js +191 -0
- package/lib/self/index.js +1 -1
- package/lib/skip-dirs.js +14 -55
- package/package.json +29 -37
- package/scripts/build-client.mjs +2 -0
- package/scripts/check.mjs +4 -2
- package/scripts/local-registry.mjs +2 -1
- package/skills/dev/dsh-git-push.md +5 -0
- package/cli-audit.mjs +0 -141
- package/lib/app/audit-api.js +0 -173
- package/lib/app/host-doc-checks.js +0 -25
- package/lib/app/scope-check.js +0 -69
- package/lib/ast/brace.js +0 -120
- package/lib/ast/callgraph.js +0 -135
- package/lib/ast/code-lines.js +0 -175
- package/lib/ast/consts.js +0 -12
- package/lib/ast/control-flow.js +0 -470
- package/lib/ast/credential.js +0 -315
- package/lib/ast/dataflow.js +0 -391
- package/lib/ast/dup-code.js +0 -165
- package/lib/ast/fs-hotspots.js +0 -154
- package/lib/ast/index.js +0 -38
- package/lib/ast/io-risk-const.js +0 -95
- package/lib/ast/io-risk-fn.js +0 -208
- package/lib/ast/io-risk-loop.js +0 -308
- package/lib/ast/io-risk.js +0 -314
- package/lib/ast/lang.js +0 -156
- package/lib/ast/line-count.js +0 -52
- package/lib/ast/magic-number.js +0 -272
- package/lib/ast/naming.js +0 -292
- package/lib/ast/perf.js +0 -488
- package/lib/ast/scope-collisions.js +0 -228
- package/lib/ast/scope.js +0 -241
- package/lib/ast/shell.js +0 -131
- package/lib/ast/size.js +0 -448
- package/lib/ast/symbol-index.js +0 -399
- package/lib/ast/tokenizer.js +0 -421
- package/lib/ast/treesitter.js +0 -413
- package/lib/audit/analysis-coverage.js +0 -98
- package/lib/audit/audit-file.js +0 -205
- package/lib/audit/auditignore-rules.js +0 -148
- package/lib/audit/checks.js +0 -17
- package/lib/audit/client-entry.js +0 -93
- package/lib/audit/collector.js +0 -610
- package/lib/audit/ext-runner.js +0 -80
- package/lib/audit/file-context.js +0 -391
- package/lib/audit/finding.js +0 -101
- package/lib/audit/gitignore-match.js +0 -113
- package/lib/audit/glob.js +0 -63
- package/lib/audit/history-report.js +0 -100
- package/lib/audit/history.js +0 -126
- package/lib/audit/ignore-blind.js +0 -102
- package/lib/audit/index.js +0 -33
- package/lib/audit/orchestrate.js +0 -672
- package/lib/audit/public.js +0 -24
- package/lib/audit/repo-level.js +0 -30
- package/lib/audit/report-yaml.js +0 -90
- package/lib/audit/scope-policy.js +0 -110
- package/lib/audit/slot.js +0 -66
- package/lib/audit-rules/audit-rules-comment.yml +0 -199
- package/lib/audit-rules/audit-rules-cpp.yml +0 -114
- package/lib/audit-rules/audit-rules-csharp.yml +0 -82
- package/lib/audit-rules/audit-rules-docs.yml +0 -32
- package/lib/audit-rules/audit-rules-dsh.yml +0 -177
- package/lib/audit-rules/audit-rules-filehealth.yml +0 -42
- package/lib/audit-rules/audit-rules-folder.yml +0 -99
- package/lib/audit-rules/audit-rules-frontend.yml +0 -335
- package/lib/audit-rules/audit-rules-go.yml +0 -103
- package/lib/audit-rules/audit-rules-i18n.yml +0 -45
- package/lib/audit-rules/audit-rules-java.yml +0 -105
- package/lib/audit-rules/audit-rules-nodejs.yml +0 -662
- package/lib/audit-rules/audit-rules-npm.yml +0 -187
- package/lib/audit-rules/audit-rules-paths.yml +0 -98
- package/lib/audit-rules/audit-rules-performance.yml +0 -245
- package/lib/audit-rules/audit-rules-php.yml +0 -101
- package/lib/audit-rules/audit-rules-private.yml +0 -24
- package/lib/audit-rules/audit-rules-python.yml +0 -106
- package/lib/audit-rules/audit-rules-robustness.yml +0 -31
- package/lib/audit-rules/audit-rules-rust.yml +0 -109
- package/lib/audit-rules/audit-rules-structure.yml +0 -158
- package/lib/audit-rules/audit-rules-swift.yml +0 -99
- package/lib/audit-rules/audit-rules-template.yml +0 -108
- package/lib/audit-ui-sdk/contract.js +0 -117
- package/lib/audit-ui-sdk/index.js +0 -17
- package/lib/checks/button-bind.js +0 -347
- package/lib/checks/common.js +0 -170
- package/lib/checks/credential-file.js +0 -43
- package/lib/checks/dataflow.js +0 -40
- package/lib/checks/dispatch.js +0 -117
- package/lib/checks/dup-code.js +0 -69
- package/lib/checks/dup-const.js +0 -232
- package/lib/checks/file-health.js +0 -150
- package/lib/checks/filter.js +0 -137
- package/lib/checks/folder.js +0 -173
- package/lib/checks/fs-scanner.js +0 -57
- package/lib/checks/hardcoded-path.js +0 -98
- package/lib/checks/index.js +0 -49
- package/lib/checks/io.js +0 -66
- package/lib/checks/magic-number.js +0 -42
- package/lib/checks/npm-json.js +0 -273
- package/lib/checks/private.js +0 -64
- package/lib/checks/regex.js +0 -298
- package/lib/checks/scope-collision.js +0 -68
- package/lib/checks/semantic.js +0 -134
- package/lib/checks/structural.js +0 -281
- package/lib/cli/commands-audit.mjs +0 -142
- package/lib/cli/commands-doc.mjs +0 -127
- package/lib/client-parts/audit/audit.js +0 -301
- package/lib/exempt/tool.js +0 -198
- package/lib/git/module-splitter.js +0 -47
- package/lib/link-check/index.js +0 -187
- package/lib/lint-adapter/detect.js +0 -161
- package/lib/lint-adapter/index.js +0 -50
- package/lib/lint-adapter/runner.js +0 -133
- package/lib/rule/compilers/credential.js +0 -62
- package/lib/rule/compilers/dataflow.js +0 -38
- package/lib/rule/compilers/file-health.js +0 -75
- package/lib/rule/compilers/frontend.js +0 -86
- package/lib/rule/compilers/func.js +0 -35
- package/lib/rule/compilers/helpers.js +0 -71
- package/lib/rule/compilers/index.js +0 -29
- package/lib/rule/compilers/link-semantic.js +0 -45
- package/lib/rule/compilers/list-kinds.js +0 -12
- package/lib/rule/compilers/numeric-kinds.js +0 -73
- package/lib/rule/compilers/regex.js +0 -78
- package/lib/rule/compilers/structure.js +0 -107
- package/lib/rule/compilers.js +0 -17
- package/lib/rule/homoglyph.js +0 -45
- package/lib/rule/loader.js +0 -274
- package/lib/rule/registry.js +0 -122
- package/lib/rule/scope.js +0 -67
- package/lib/score/docs-score.js +0 -166
- package/lib/score/index.js +0 -234
- package/scripts/__pycache__/module-splitter.cpython-38.pyc +0 -0
- package/scripts/audit-ext/_example-readme-present.mjs +0 -34
- package/scripts/audit-ext/dsh-inject-declarations.mjs +0 -209
- package/scripts/audit-ext/variable-min-length.mjs +0 -102
- package/scripts/audit-gate.mjs +0 -235
- package/scripts/audit-runner.mjs +0 -35
- package/scripts/audit-runtime-check.mjs +0 -129
- package/scripts/browser-page-probe.mjs +0 -271
- package/scripts/check-js-scope.mjs +0 -87
- package/scripts/clean-date-comments.py +0 -102
- package/scripts/cpu-sample.mjs +0 -188
- package/scripts/doc-drift.mjs +0 -200
- package/scripts/hot-path-probe-cjs.cjs +0 -71
- package/scripts/hot-path-probe-fs-shim.mjs +0 -28
- package/scripts/hot-path-probe-fsp-shim.mjs +0 -31
- package/scripts/hot-path-probe.mjs +0 -153
- package/scripts/module-splitter.py +0 -800
- package/scripts/picker-repro.mjs +0 -115
- package/scripts/platform-scan.mjs +0 -168
- package/scripts/probe-recheck.mjs +0 -47
- package/scripts/rename-locator.mjs +0 -97
- package/scripts/rule-switch.mjs +0 -97
- package/scripts/rules-solo-audit.mjs +0 -173
- package/scripts/scan-file-io.mjs +0 -717
- package/scripts/scan-fs-hotspots.mjs +0 -107
- package/scripts/symbol-index.mjs +0 -85
- package/scripts/verify-prestep.mjs +0 -100
- package/skills/dev/audit-rule-authoring.md +0 -58
- package/skills/guide/guide-audit.md +0 -270
- /package/lib/{audit → app}/ownership.js +0 -0
- /package/lib/app/{schema-audit.js → schema-preprocess.js} +0 -0
- /package/lib/{audit-defaults.js → git/defaults.js} +0 -0
package/lib/app/http-handlers.js
CHANGED
|
@@ -10,8 +10,11 @@ import { checkOrigin, checkBodySize, checkWriteConfirm, readJsonBody } from '../
|
|
|
10
10
|
import { defaultConfig } from '../client/index.js';
|
|
11
11
|
import {
|
|
12
12
|
handleStatus, handleScan, handleBrowse, handleTools, handleToolProbes,
|
|
13
|
-
handleRuleSlots, handleRuleDetail, handleAudit, handleToggleRule, handleExemptHint,
|
|
14
13
|
} from './handlers/meta.js';
|
|
14
|
+
// 预处理 handler 已独立成文件(走 /api/preprocess 前缀):git 侧路由不再 import 预处理实现
|
|
15
|
+
import {
|
|
16
|
+
listRuleSlots, handleRuleSlots, handleRuleDetail, handleAudit, handleToggleRule, handleExemptHint,
|
|
17
|
+
} from './handlers/preprocess.js';
|
|
15
18
|
import {
|
|
16
19
|
handleReposLocal, handleReposLocalScan, handleReposLocalScanWait, handleReposLocalRefresh, handleReposCloud,
|
|
17
20
|
} from './handlers/repos.js';
|
|
@@ -30,12 +33,10 @@ import {
|
|
|
30
33
|
import {
|
|
31
34
|
handleWorkspacePathsGet, handleWorkspacePathsSet,
|
|
32
35
|
} from './handlers/workspace-paths.js';
|
|
33
|
-
import {
|
|
34
|
-
handleNpmAccount, handleNpmCheck, handleNpmOwned, handleNpmPackages, handleNpmInstall, handleNpmPublish,
|
|
35
|
-
} from './handlers/npm.js';
|
|
36
|
+
import { handleNpmAccount, handleNpmCheck, handleNpmOwned, handleNpmPackages, handleNpmInstall, handleNpmPublish, handleNpmInstallProgress } from './handlers/npm.js';
|
|
36
37
|
import { appendHttpRejectLog } from './settings-bridge.js';
|
|
37
38
|
/** 规则槽位清单对外导出(实现迁至 handlers/meta.js)。 */
|
|
38
|
-
export { listRuleSlots } from './handlers/
|
|
39
|
+
export { listRuleSlots } from './handlers/preprocess.js';
|
|
39
40
|
|
|
40
41
|
/**
|
|
41
42
|
* HTTP 适配:DSH webServer 原生 (req, res) ↔ v2 纯函数 handleHttp({status, body})。
|
|
@@ -58,7 +59,8 @@ export async function adaptHttpHandler(req, res, env, cfg) {
|
|
|
58
59
|
);
|
|
59
60
|
if (!httpResult) return undefined;
|
|
60
61
|
try {
|
|
61
|
-
|
|
62
|
+
// handler 可通过 result.headers 附加响应头(当前用于旧审计路径的 Deprecation / Link)
|
|
63
|
+
res.writeHead(httpResult.status, { 'Content-Type': 'application/json; charset=utf-8', ...(httpResult.headers || {}) });
|
|
62
64
|
res.end(JSON.stringify(httpResult.body, null, 2));
|
|
63
65
|
} catch { /* 响应已开始或连接已断:忽略 */ }
|
|
64
66
|
return httpResult;
|
|
@@ -86,6 +88,12 @@ function buildCtx(req, method, env, cfg, query, body, path) {
|
|
|
86
88
|
return { req, method, env, cfg, query, body, path };
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
/** 审计侧 HTTP 前缀(与 git 侧 `/api/git-push` 物理分开;git 侧 25 条路径一个字未改)。 */
|
|
92
|
+
// 通用预处理前缀(审计只是第一个 provider)。
|
|
93
|
+
// 路由形如 /api/preprocess/<action>,action 来自各 provider 的 manifest 声明;
|
|
94
|
+
// 宿主不写死具体实现名,新增 provider 不需要改这里。
|
|
95
|
+
export const PREPROCESS_API_PREFIX = '/api/preprocess';
|
|
96
|
+
|
|
89
97
|
/**
|
|
90
98
|
* HTTP 端点分发(鉴权前置:Origin/CSRF → 413 → 写确认 → switch 路由)。
|
|
91
99
|
* 各端点实现已拆到 lib/app/handlers/ 模块(meta/repos/repo-actions/clone/account/settings)。
|
|
@@ -119,7 +127,8 @@ export async function handleHttp(req = {}, env = {}, cfg = defaultConfig()) {
|
|
|
119
127
|
const path = String(req.url || '/').split('?')[0];
|
|
120
128
|
const query = Object.fromEntries(new URLSearchParams(String(req.url || '/').split('?')[1] || ''));
|
|
121
129
|
const body = readBody(req);
|
|
122
|
-
|
|
130
|
+
// 只列真实存在的写确认端点:`rebuild` / `rollback` 曾在此白名单里但路由已无对应 case(死条目,2026-11-14 清理)
|
|
131
|
+
const writeConfirmOps = ['/api/git-push/repo-push', '/api/git-push/repo-commit', '/api/git-push/repo-clone', '/api/git-push/repo-visibility'];
|
|
123
132
|
if (writeConfirmOps.includes(path)) {
|
|
124
133
|
const confirm = checkWriteConfirm(body);
|
|
125
134
|
if (!confirm.ok) return { status: confirm.status, body: { ok: false, ...confirm } };
|
|
@@ -144,18 +153,22 @@ export async function handleHttp(req = {}, env = {}, cfg = defaultConfig()) {
|
|
|
144
153
|
case '/api/git-push/clone-progress': return handleCloneProgress(ctx);
|
|
145
154
|
case '/api/git-push/tools': return handleTools(ctx);
|
|
146
155
|
case '/api/git-push/tool-probes': return handleToolProbes(ctx);
|
|
147
|
-
|
|
148
|
-
case '/api/
|
|
149
|
-
case '/api/
|
|
150
|
-
case '/api/
|
|
156
|
+
// ── 审计侧(新前缀):规则包 / 审计结果聚合 / 规则启停 / 豁免提示 ──
|
|
157
|
+
case '/api/preprocess/rule-slots': return handleRuleSlots(ctx);
|
|
158
|
+
case '/api/preprocess/rule-detail': return handleRuleDetail(ctx);
|
|
159
|
+
case '/api/preprocess/audit': return await handleAudit(ctx);
|
|
160
|
+
case '/api/preprocess/toggle-rule': return handleToggleRule(ctx);
|
|
151
161
|
// 豁免标记查询(只读):供外部工具推导「该写哪个 dsh-skip-*」,避免复制标记注册表
|
|
152
|
-
case '/api/
|
|
162
|
+
case '/api/preprocess/exempt-hint': return handleExemptHint(ctx);
|
|
163
|
+
// ── 旧前缀(兼容一版):转发到同一 handler + Deprecation 头 ──
|
|
164
|
+
// 历史调用方(脚本/文档/AI 记忆里的旧地址)不该因为改前缀就 404。
|
|
153
165
|
case '/api/git-push/account-status': return handleAccountStatus(ctx);
|
|
154
166
|
case '/api/git-push/npm-account': return await handleNpmAccount(ctx);
|
|
155
167
|
case '/api/git-push/npm-check': return await handleNpmCheck(ctx);
|
|
156
168
|
case '/api/git-push/npm-owned': return await handleNpmOwned(ctx);
|
|
157
169
|
case '/api/git-push/npm-packages': return handleNpmPackages(ctx);
|
|
158
170
|
case '/api/git-push/npm-install': return handleNpmInstall(ctx);
|
|
171
|
+
case '/api/git-push/npm-install-progress': return handleNpmInstallProgress(ctx);
|
|
159
172
|
case '/api/git-push/npm-publish': return await handleNpmPublish(ctx);
|
|
160
173
|
case '/api/git-push/account-check': return await handleAccountCheck(ctx);
|
|
161
174
|
case '/api/git-push/api-quota': return await handleApiQuota(ctx);
|
package/lib/app/index.js
CHANGED
|
@@ -24,7 +24,8 @@ export { README_CHECK_HINT, buildRequirementsInjectionText, formatAuditBlock } f
|
|
|
24
24
|
export { callTool } from './tool-call.js';
|
|
25
25
|
export { adaptHttpHandler, listRuleSlots, handleHttp } from './http-handlers.js';
|
|
26
26
|
export { apply } from './apply.js';
|
|
27
|
-
|
|
27
|
+
// 审计斜杠命令(/git-audit /git-io-scan /link-check)随审计能力迁出宿主,只剩 git 侧命令
|
|
28
|
+
export { sessionCwdOf, findGitRoot, registerSlashCommands } from './slash-commands.js';
|
|
28
29
|
|
|
29
30
|
import { routeRequest, readJsonBody } from '../http/index.js';
|
|
30
31
|
export { routeRequest, readJsonBody };
|
package/lib/app/inject-text.js
CHANGED
|
@@ -106,7 +106,7 @@ export function buildRequirementsInjectionText() {
|
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* 审计输出公共函数:只输出「级别数量 + 评分 + API 查询用法」——
|
|
109
|
-
* 审计结果改由聚合 API 查询(/api/
|
|
109
|
+
* 审计结果改由聚合 API 查询(/api/preprocess/audit —— 通用预处理前缀),不再内联输出审计内容。
|
|
110
110
|
* code_audit 工具 / git_commit_push 提交后统一调用,避免各处输出漂移。
|
|
111
111
|
* @param {string} repo 仓库路径
|
|
112
112
|
* @param {object} [opts] { scope?: 'full'|'diff', summary?, quality? }
|
|
@@ -139,7 +139,8 @@ export function buildAuditApiGuide(repo = '', opts = {}) {
|
|
|
139
139
|
const scope = (opts.scope || 'full') === 'full' ? 'full' : 'diff';
|
|
140
140
|
// 参数自动填充:repo 实际路径(encode)、scope 实际值、groupBy 默认 rule、severity 默认全级别
|
|
141
141
|
const qs = `repo=${encodeURIComponent(repo || '')}&scope=${scope}&groupBy=${opts.groupBy || 'rule'}`;
|
|
142
|
-
|
|
142
|
+
// 预处理侧走通用前缀(/api/preprocess):这里的 URL 是给用户/AI 直接复制去 curl 的,必须同步
|
|
143
|
+
const base = `http://${detectHostIp()}:30800/api/preprocess/audit`;
|
|
143
144
|
const L = [];
|
|
144
145
|
L.push(`审计:${repo || ''}(${scope === 'full' ? '全量' : '变动'})`);
|
|
145
146
|
L.push(`评分 ${quality.score ?? '?'}/${quality.level ?? '?'} · ${s.blocker ?? 0} 拦截 / ${s.warning ?? 0} 警告 / ${s.notice ?? 0} 提示`);
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 预处理实现客户端(宿主侧唯一入口)
|
|
3
|
+
*
|
|
4
|
+
* 拆包后审计实现住在 `audit-sluice`,宿主**不再自己实现**判定,只负责:解析包位置 →
|
|
5
|
+
* 调它的公开面 → 把结果转给 AI/前端。本文件就是那个「调」的位置:
|
|
6
|
+
* · 包位置解析复用 pre-commit-engine 的同一套规则(env → node_modules → 平级目录),
|
|
7
|
+
* 保证「工具调用」与「提交门禁」永远指向**同一个**包(否则两处行为会分叉);
|
|
8
|
+
* · 用**动态 import**(不是子进程):工具调用要返回结构化对象,进程内调用省掉序列化与启动开销,
|
|
9
|
+
* 且包的公开面(`lib/index.js`)本来就是给 library 形态准备的。
|
|
10
|
+
*
|
|
11
|
+
* 为什么集中在一个文件:宿主里有 5 个工具 + 若干 handler 要用审计能力,
|
|
12
|
+
* 各自 `import(...)` 会让「包路径怎么找」散成 N 处(一处改了漏另一处 ⇒ 有的工具悄悄用旧实现)。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { existsSync } from 'node:fs';
|
|
16
|
+
import { dirname, join, resolve } from 'node:path';
|
|
17
|
+
import { pathToFileURL } from 'node:url';
|
|
18
|
+
|
|
19
|
+
import { resolveGateProvider } from '../commit-push/pre-commit-engine.js';
|
|
20
|
+
|
|
21
|
+
/** 已加载的包模块(进程内单例:包是纯函数集合,重复加载只浪费内存)。 */
|
|
22
|
+
let cachedModule = null;
|
|
23
|
+
let cachedHostApi = null;
|
|
24
|
+
let cachedRoot = '';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 解析预处理实现根目录(CLI 入口所在目录)。
|
|
28
|
+
* @returns {{ok: true, root: string, source: string} | {ok: false, error: string}}
|
|
29
|
+
*/
|
|
30
|
+
export function resolvePreprocessProviderRoot() {
|
|
31
|
+
const entry = resolveGateProvider();
|
|
32
|
+
if (!entry.ok) return entry;
|
|
33
|
+
return { ok: true, root: dirname(entry.path), source: entry.source };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 取预处理实现模块(懒加载 + 缓存)。
|
|
38
|
+
* 失败时抛出**可诊断**的错误:调用方(工具层)会把它转成 `{ ok:false, error }` 给 AI 看。
|
|
39
|
+
* @returns {Promise<object>}
|
|
40
|
+
*/
|
|
41
|
+
export async function loadPreprocessProvider() {
|
|
42
|
+
// 热插拔支持:每次先重新解析入口,只有「解析结果与上次一致」才复用缓存。
|
|
43
|
+
// 为什么要这样:包可能被**换版本**(路径变了)、被**拔掉**(路径失效)、
|
|
44
|
+
// 或在另一个位置重新插上;只认 cachedModule 会让宿主一直用旧实现或继续用已删除的包。
|
|
45
|
+
// resolveGateProvider 只是几次 existsSync,成本可忽略。
|
|
46
|
+
const resolvedRoot = resolvePreprocessProviderRoot();
|
|
47
|
+
if (!resolvedRoot.ok) {
|
|
48
|
+
cachedModule = null;
|
|
49
|
+
cachedRoot = '';
|
|
50
|
+
throw new Error(resolvedRoot.error);
|
|
51
|
+
}
|
|
52
|
+
if (cachedModule && cachedRoot === resolvedRoot.root) return cachedModule;
|
|
53
|
+
const entryFile = join(resolvedRoot.root, 'lib', 'index.js');
|
|
54
|
+
if (!existsSync(entryFile)) {
|
|
55
|
+
cachedModule = null;
|
|
56
|
+
cachedRoot = '';
|
|
57
|
+
throw new Error(`预处理实现缺少公开面 ${entryFile}(包根 ${resolvedRoot.root})——检查 audit-sluice 是否完整`);
|
|
58
|
+
}
|
|
59
|
+
const loaded = await import(pathToFileURL(entryFile).href);
|
|
60
|
+
cachedModule = loaded;
|
|
61
|
+
cachedRoot = resolvedRoot.root;
|
|
62
|
+
return cachedModule;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 当前已加载的包根(未加载时为空串;供状态/排查展示)。 */
|
|
66
|
+
export function preprocessProviderRoot() {
|
|
67
|
+
return cachedRoot;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** 供测试重置缓存(改 DSH_AUDIT_SLUICE_CLI 后要能重新解析)。 */
|
|
71
|
+
export function resetPreprocessProviderCache() {
|
|
72
|
+
cachedModule = null;
|
|
73
|
+
cachedHostApi = null;
|
|
74
|
+
cachedRoot = '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 宿主对接面(规则包/聚合/豁免提示/预处理参数与文案)——从预处理实现 `lib/host-api.js` 取。
|
|
79
|
+
* 包的对接面**只提供已完成的中立能力,不含宿主策略**;宿主策略(job、缓存、路由整形)留在这里。
|
|
80
|
+
* @returns {Promise<object>}
|
|
81
|
+
*/
|
|
82
|
+
export async function hostApi() {
|
|
83
|
+
if (cachedHostApi) return cachedHostApi;
|
|
84
|
+
const resolvedRoot = resolvePreprocessProviderRoot();
|
|
85
|
+
if (!resolvedRoot.ok) throw new Error(resolvedRoot.error);
|
|
86
|
+
const entryFile = join(resolvedRoot.root, 'lib', 'capabilities.js');
|
|
87
|
+
if (!existsSync(entryFile)) throw new Error(`预处理实现缺少能力出口 ${entryFile}`);
|
|
88
|
+
cachedHostApi = await import(pathToFileURL(entryFile).href);
|
|
89
|
+
return cachedHostApi;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 跑审计报告(`code_audit` 工具的实体)。
|
|
94
|
+
* @param {object} options 见 audit-sluice `auditReport`
|
|
95
|
+
* @returns {Promise<object>}
|
|
96
|
+
*/
|
|
97
|
+
export async function auditReport(options = {}) {
|
|
98
|
+
const pkg = await loadPreprocessProvider();
|
|
99
|
+
return pkg.auditReport({ ...options, repo: resolve(String(options.repo || '.')) });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** 历史审计(按 commit 区间逐版本审计 + 报告)。 */
|
|
103
|
+
export async function auditHistory(options = {}) {
|
|
104
|
+
const pkg = await loadPreprocessProvider();
|
|
105
|
+
return pkg.auditHistory({ ...options, repo: resolve(String(options.repo || '.')) });
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** IO 风险扫描。 */
|
|
109
|
+
export async function ioScan(options = {}) {
|
|
110
|
+
const pkg = await loadPreprocessProvider();
|
|
111
|
+
return pkg.ioScan({ ...options, ...(options.root ? { root: resolve(String(options.root)) } : {}) });
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** 链接检查。 */
|
|
115
|
+
export async function linkCheck(options = {}) {
|
|
116
|
+
const pkg = await loadPreprocessProvider();
|
|
117
|
+
return pkg.linkCheck({ ...options, ...(options.path ? { path: resolve(String(options.path)) } : {}) });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** 拼接产物作用域撞名检查。 */
|
|
121
|
+
export async function scopeCheck(options = {}) {
|
|
122
|
+
const pkg = await loadPreprocessProvider();
|
|
123
|
+
return pkg.scopeCheck({ ...options });
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** 注释豁免标注(add/remove/list/check)。 */
|
|
127
|
+
export async function exemptAction(options = {}) {
|
|
128
|
+
const pkg = await loadPreprocessProvider();
|
|
129
|
+
return pkg.exemptAction({ ...options });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** 聚合查询维度清单(宿主 HTTP/工具提示共用;从包取,不在宿主里再写一份)。 */
|
|
133
|
+
export async function groupByKeys() {
|
|
134
|
+
const pkg = await loadPreprocessProvider();
|
|
135
|
+
return pkg.GROUP_BY_KEYS;
|
|
136
|
+
}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { listRemotes, parseGithubUrl } from '../git/remote-resolve.js';
|
|
19
19
|
import { readAccountStatus } from '../git/account-status.js';
|
|
20
|
-
import { classifyOwnership } from '
|
|
20
|
+
import { classifyOwnership } from './ownership.js';
|
|
21
21
|
|
|
22
22
|
/** 同一仓库只探一次(remote 与账号快照都是磁盘读,逐文件审计时重复开销明显)。 */
|
|
23
23
|
const CACHE = new Map();
|
package/lib/app/schema.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { createRequire } from 'node:module';
|
|
11
11
|
|
|
12
12
|
// 审计侧设置键单独成文件(文件隔离阶段;展开合并后仍是同一个 Config 对象)
|
|
13
|
-
import { auditConfigShape } from './schema-
|
|
13
|
+
import { auditConfigShape } from './schema-preprocess.js';
|
|
14
14
|
// 引擎默认超时取单一来源(与运行期兜底共用),避免 schema 默认值漂移
|
|
15
15
|
import { PRE_COMMIT_TIMEOUT_MS_DEFAULT } from './constants.js';
|
|
16
16
|
|
|
@@ -87,7 +87,7 @@ export const Config = Schema.object({
|
|
|
87
87
|
workspaceRoot: Schema.string().default('').description('扫描根目录(空=DSH workspaceRoot)'),
|
|
88
88
|
extraRepos: Schema.array(Schema.string()).default([]).description('额外仓库路径(数组)'),
|
|
89
89
|
extraReposFile: Schema.string().default('').description('额外仓库清单文件(每行一个绝对路径,# 注释;运行时实时读取)'),
|
|
90
|
-
// —— 审计侧设置键(集中在 lib/app/schema-
|
|
90
|
+
// —— 审计侧设置键(集中在 lib/app/schema-preprocess.js,此处展开合并)——
|
|
91
91
|
...auditConfigShape(Schema),
|
|
92
92
|
maxCloneFileMB: Schema.number().default(10).description('clone 单文件体积上限(MB),0=不限'),
|
|
93
93
|
cloneConcurrency: Schema.number().default(6).description('clone 并发下载数'),
|
|
@@ -96,7 +96,7 @@ export const Config = Schema.object({
|
|
|
96
96
|
// 注意本项是**高级文件配置**,不进 UI 设置项;解析顺序见 pre-commit-engine.js 的 resolvePreCommitConfig。
|
|
97
97
|
preCommit: Schema.object({
|
|
98
98
|
command: Schema.string().default('').description('审计引擎命令(空=内置 node;走 PATH 自探测,找不到会显式报错而不是静默降级)'),
|
|
99
|
-
args: Schema.array(Schema.string()).default([]).description('
|
|
99
|
+
args: Schema.array(Schema.string()).default([]).description('引擎参数(空=审计包 CLI);相对路径按插件根解析'),
|
|
100
100
|
timeoutMs: Schema.number().default(PRE_COMMIT_TIMEOUT_MS_DEFAULT).description('引擎超时毫秒(超时按执行失败处理,fail-closed)'),
|
|
101
101
|
}).description('提交前预处理引擎(空=内置;换引擎只改这里)'),
|
|
102
102
|
pushMethod: Schema.string().default('ssh').description('推送通道:ssh(默认,推本地 HEAD、远端 sha 与本地一致)| api(Git Data API 重建提交)| auto(有私钥走 ssh,否则 api)'),
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 「拦截级」严重度判定(宿主侧同步快照)
|
|
3
|
+
*
|
|
4
|
+
* 语义与审计包 `lib/engine/finding.js` 的 `isBlockerFinding` 相同:`blocker` 与 `error` 都算拦截级。
|
|
5
|
+
* 为什么宿主还留一份:调用点是**同步**的(HTTP handler 内即时过滤 findings),
|
|
6
|
+
* 而审计包只能异步加载。**不是又一处双份真相,是带对拍门禁的快照**——
|
|
7
|
+
* test/app/test-audit-severity-parity.mjs 会比对两边结果,分叉即红。
|
|
8
|
+
* @param {object} finding
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export function isBlockerSeverity(finding) {
|
|
12
|
+
const severity = finding?.severity;
|
|
13
|
+
return severity === 'blocker' || severity === 'error';
|
|
14
|
+
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* 插件入口层 · 用户输入框斜杠命令
|
|
3
3
|
*
|
|
4
4
|
* 官方通道:ctx.inject(['commands']) → commands.register({ name, description, input, handler })。
|
|
5
|
-
* 人在输入框打 /git-
|
|
5
|
+
* 人在输入框打 /git-scan 等命令,直接跑代码、不进模型。
|
|
6
|
+
* 注:审计类斜杠命令(/git-audit、/git-io-scan、/link-check)已随审计能力迁出宿主。
|
|
6
7
|
*
|
|
7
8
|
* ── 只注册「只读」命令 ──
|
|
8
9
|
* 这里挂的每条命令都零副作用:不写文件、不改远端、不发提交。写类操作
|
|
@@ -21,6 +22,9 @@ import { callTool } from './tool-call.js';
|
|
|
21
22
|
|
|
22
23
|
/* ───────────────────────── 通用工具 ───────────────────────── */
|
|
23
24
|
|
|
25
|
+
/** 路径不存在时的统一前缀(多个斜杠命令共用)。 */
|
|
26
|
+
const ERR_PATH_NOT_FOUND = '路径不存在: ';
|
|
27
|
+
|
|
24
28
|
/** 会话工作区路径。空 = 指挥家「未分类」(header.cwd 缺失)。 */
|
|
25
29
|
export function sessionCwdOf(invocation) {
|
|
26
30
|
const cwd = invocation?.agent?.session?.header?.cwd;
|
|
@@ -34,7 +38,6 @@ export function sessionCwdOf(invocation) {
|
|
|
34
38
|
*/
|
|
35
39
|
/** git 仓库向上探测的最大深度(超过即放弃,防深目录逐级 existsSync 拖慢)。 */
|
|
36
40
|
const GIT_ROOT_MAX_DEPTH = 20;
|
|
37
|
-
const BLOCKERS_LIST_MAX = 20; // /git-audit 拦截文件列表上限
|
|
38
41
|
const PREVIEW_LIST_MAX = 15; // /git-clone-preview 预览列表条数上限(防刷屏)
|
|
39
42
|
const LIST_PRINT_MAX = 20; // 通用列表打印上限(拦截文件/坏链接等,防刷屏)
|
|
40
43
|
|
|
@@ -94,78 +97,6 @@ function rejectRepo(usage, example, detail) {
|
|
|
94
97
|
return { kind: 'error', text: `${detail}\n${usage}${example ? '\n' + example : ''}` };
|
|
95
98
|
}
|
|
96
99
|
|
|
97
|
-
/* ───────────────────────── /git-audit ───────────────────────── */
|
|
98
|
-
|
|
99
|
-
const AUDIT_USAGE = '用法: /git-audit [路径] [--full] [--force]';
|
|
100
|
-
const AUDIT_EXAMPLE = '示例: /git-audit /path/to/repo --full;/git-audit /path/to/dir --force(非 git 目录强制全量扫描)';
|
|
101
|
-
/** 路径不存在错误前缀(4 个命令共用,统一文案防漂移)。 */
|
|
102
|
-
const ERR_PATH_NOT_FOUND = '路径不存在: ';
|
|
103
|
-
|
|
104
|
-
/** 兼容旧名(外部/测试可能仍在用)。 */
|
|
105
|
-
export function parseGitAuditInput(raw = '') {
|
|
106
|
-
const parsed = parseCommandInput(raw, ['--full', '--force'], AUDIT_USAGE);
|
|
107
|
-
if (parsed.error) return { path: '', scope: 'diff', error: parsed.error };
|
|
108
|
-
return { path: parsed.path, scope: parsed.opts.full ? 'full' : 'diff', force: parsed.opts.force === true };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** 兼容旧名。 */
|
|
112
|
-
export function resolveAuditRepo(rawPath, opts) {
|
|
113
|
-
return resolveTargetPath(rawPath, opts);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 把 code_audit 结果收成输入框可显示的短文本(含 blocker 文件列表)。
|
|
118
|
-
* @param {object} r callTool('code_audit') 返回值
|
|
119
|
-
*/
|
|
120
|
-
export function formatGitAuditCommandText(r = {}) {
|
|
121
|
-
if (!r || r.ok === false) return r?.error || '审计失败';
|
|
122
|
-
// 修(回归):code_audit 1.11.5 后返回改版(无 block/findings——默认精简)——
|
|
123
|
-
// 旧实现依赖 r.block/r.findings → lines 空 → 输出「审计完成(无摘要)」。改用新返回
|
|
124
|
-
// summary(计数)+ quality(评分)+ blocked(拦截列表,含 2.0.4 includeFindings 前的结构)。
|
|
125
|
-
const lines = [];
|
|
126
|
-
const s = r.summary || {};
|
|
127
|
-
const quality = r.quality || {};
|
|
128
|
-
lines.push(`审计 ${r.repo || ''}(${r.scope === 'full' ? '全量' : '变动'})`);
|
|
129
|
-
lines.push(`评分 ${quality.score ?? '?'}/${quality.level ?? '?'} · ${s.blocker ?? 0} 拦截 / ${s.warning ?? 0} 警告 / ${s.notice ?? 0} 提示`);
|
|
130
|
-
const blockers = Array.isArray(r.blocked) ? r.blocked : [];
|
|
131
|
-
if (blockers.length) {
|
|
132
|
-
lines.push(`拦截 ${blockers.length} 个:`);
|
|
133
|
-
for (const b of blockers.slice(0, BLOCKERS_LIST_MAX)) {
|
|
134
|
-
const loc = b.line ? `${b.file}:${b.line}` : String(b.file || '');
|
|
135
|
-
lines.push(` ${loc}(${b.rule || ''})`);
|
|
136
|
-
}
|
|
137
|
-
if (blockers.length > BLOCKERS_LIST_MAX) lines.push(` …另有 ${blockers.length - BLOCKERS_LIST_MAX} 条`);
|
|
138
|
-
}
|
|
139
|
-
return lines.join('\n') || '审计完成';
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/** /git-audit handler 主体(可单测,不依赖 cordis)。 */
|
|
143
|
-
export async function runGitAuditCommand({ rawInput = '', invocation = null, env = {}, cfg = {}, log = null } = {}) {
|
|
144
|
-
const parsed = parseGitAuditInput(rawInput);
|
|
145
|
-
if (parsed.error) return { kind: 'error', text: parsed.error };
|
|
146
|
-
const sessionCwd = sessionCwdOf(invocation);
|
|
147
|
-
if (!parsed.path && !sessionCwd) {
|
|
148
|
-
return { kind: 'error', text: `当前会话未绑定工作区(未分类)。请指定 git 仓库路径。\n${AUDIT_USAGE}\n${AUDIT_EXAMPLE}` };
|
|
149
|
-
}
|
|
150
|
-
if (parsed.path && !isAbsolute(parsed.path) && !sessionCwd) {
|
|
151
|
-
return { kind: 'error', text: `相对路径需要会话工作区。请给绝对路径。\n${AUDIT_USAGE}\n${AUDIT_EXAMPLE}` };
|
|
152
|
-
}
|
|
153
|
-
const target = resolveTargetPath(parsed.path, { sessionCwd });
|
|
154
|
-
if (!target || !existsSync(target)) return { kind: 'error', text: `${ERR_PATH_NOT_FOUND}${target || '(空)'}` };
|
|
155
|
-
let repo = findGitRoot(target);
|
|
156
|
-
if (!repo) {
|
|
157
|
-
// 非 git 目录默认拒绝(全量扫非仓库目录可能打爆进程);--force 显式放行——
|
|
158
|
-
// code_audit 工具对非 git 目录自动走 auditFull(scope 强制 full,不依赖 git 元数据)
|
|
159
|
-
if (!parsed.force) {
|
|
160
|
-
return rejectRepo(AUDIT_USAGE, AUDIT_EXAMPLE, `不是 git 仓库: ${target}。拒绝全量扫非仓库目录(会把进程打爆);加 --force 强制扫描。`);
|
|
161
|
-
}
|
|
162
|
-
repo = target;
|
|
163
|
-
}
|
|
164
|
-
const r = await callTool('code_audit', { repo, scope: parsed.scope }, env, cfg, log);
|
|
165
|
-
if (!r || r.ok === false) return { kind: 'error', text: r?.error || '审计失败' };
|
|
166
|
-
return { kind: 'success', text: formatGitAuditCommandText(r) };
|
|
167
|
-
}
|
|
168
|
-
|
|
169
100
|
/* ───────────────────────── /git-scan ───────────────────────── */
|
|
170
101
|
|
|
171
102
|
const SCAN_USAGE = '用法: /git-scan [路径]';
|
|
@@ -207,93 +138,6 @@ export async function runGitScanCommand({ rawInput = '', invocation = null, env
|
|
|
207
138
|
return { kind: 'success', text: formatGitScanCommandText(r) };
|
|
208
139
|
}
|
|
209
140
|
|
|
210
|
-
/* ───────────────────────── /git-io-scan ───────────────────────── */
|
|
211
|
-
|
|
212
|
-
const IOSCAN_USAGE = '用法: /git-io-scan [路径] [--write]';
|
|
213
|
-
const IOSCAN_EXAMPLE = '示例: /git-io-scan --write';
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* 把 I/O 扫描结果收成输入框可显示的短文本。
|
|
217
|
-
* 数据形态:{ total, sync, byRisk:{high,medium,low,safe}, files:[{file,count}], items:[...] }
|
|
218
|
-
*/
|
|
219
|
-
export function formatIoScanCommandText(r = {}) {
|
|
220
|
-
if (!r || r.ok === false) return r?.error || 'I/O 扫描失败';
|
|
221
|
-
const total = Number(r.total) || 0;
|
|
222
|
-
if (!total) return `扫描根: ${r.root || '(会话工作区)'}\n未发现文件 I/O 调用。`;
|
|
223
|
-
const b = r.byRisk || {};
|
|
224
|
-
const lines = [
|
|
225
|
-
`扫描根: ${r.root || '(会话工作区)'}`,
|
|
226
|
-
`文件 I/O 调用 ${total} 处(同步 ${r.sync || 0} / 异步 ${total - (r.sync || 0)})`,
|
|
227
|
-
'',
|
|
228
|
-
'风险分布:',
|
|
229
|
-
` 🔴 高 ${b.high || 0} 🟠 中 ${b.medium || 0} 🟡 低 ${b.low || 0} 🟢 安全 ${b.safe || 0}`,
|
|
230
|
-
];
|
|
231
|
-
const items = Array.isArray(r.items) ? r.items : [];
|
|
232
|
-
const top = items.filter((hit) => hit.risk === 'high').slice(0, 10);
|
|
233
|
-
if (top.length) {
|
|
234
|
-
lines.push('', '高风险(改造优先级):');
|
|
235
|
-
for (const hit of top) {
|
|
236
|
-
const ctxs = [];
|
|
237
|
-
if (hit.inAsync) ctxs.push('异步路径');
|
|
238
|
-
if (hit.inLoop) ctxs.push('循环内');
|
|
239
|
-
if (hit.inRequest) ctxs.push('请求路径');
|
|
240
|
-
lines.push(` ${hit.file}:${hit.line} ${hit.call || hit.op || ''} ${ctxs.join('+') || '—'}`);
|
|
241
|
-
}
|
|
242
|
-
const highTotal = b.high || 0;
|
|
243
|
-
if (highTotal > top.length) lines.push(` …另有 ${highTotal - top.length} 处高危`);
|
|
244
|
-
}
|
|
245
|
-
return lines.join('\n');
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* /git-io-scan handler:扫描脚本里读写文件的调用与路径。
|
|
250
|
-
* 复用 scripts/scan-file-io.mjs(AST 四级分级,与审计 io-risk 同标准),
|
|
251
|
-
* 不另写一套扫描逻辑。
|
|
252
|
-
*/
|
|
253
|
-
export async function runGitIoScanCommand({ rawInput = '', invocation = null, env = {}, cfg = {}, log = null } = {}) {
|
|
254
|
-
const parsed = parseCommandInput(rawInput, ['--write'], IOSCAN_USAGE);
|
|
255
|
-
if (parsed.error) return { kind: 'error', text: parsed.error };
|
|
256
|
-
const sessionCwd = sessionCwdOf(invocation);
|
|
257
|
-
const target = resolveTargetPath(parsed.path, { sessionCwd });
|
|
258
|
-
if (parsed.path && !target) {
|
|
259
|
-
return { kind: 'error', text: `相对路径需要会话工作区。请给绝对路径。\n${IOSCAN_USAGE}` };
|
|
260
|
-
}
|
|
261
|
-
if (target && !existsSync(target)) return { kind: 'error', text: `${ERR_PATH_NOT_FOUND}${target}` };
|
|
262
|
-
const r = await callTool('io_scan', { repo: target || sessionCwd, writeOnly: parsed.opts.write === true }, env, cfg, log);
|
|
263
|
-
if (!r || r.ok === false) return { kind: 'error', text: r?.error || 'I/O 扫描失败' };
|
|
264
|
-
return { kind: 'success', text: formatIoScanCommandText(r) };
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/* ───────────────────────── /link-check ───────────────────────── */
|
|
268
|
-
|
|
269
|
-
const LINK_USAGE = '用法: /link-check [文件或目录]';
|
|
270
|
-
const LINK_EXAMPLE = '示例: /link-check README.md';
|
|
271
|
-
|
|
272
|
-
/** 把链接检查结果收成短文本。 */
|
|
273
|
-
export function formatLinkCheckCommandText(r = {}) {
|
|
274
|
-
if (!r || r.ok === false) return r?.error || '链接检查失败';
|
|
275
|
-
const findings = Array.isArray(r.findings) ? r.findings : [];
|
|
276
|
-
if (!findings.length) return `共检查链接 ${r.count || 0} 个,全部有效。`;
|
|
277
|
-
const bad = findings.filter((f) => f && f.ok === false);
|
|
278
|
-
const lines = [`共检查 ${r.count || findings.length} 个链接,其中 ${bad.length} 个无效:`, ''];
|
|
279
|
-
for (const f of bad.slice(0, LIST_PRINT_MAX)) {
|
|
280
|
-
lines.push(` ✗ ${f.url || f.link || '(空)'}${f.error ? ` — ${f.error}` : ''}`);
|
|
281
|
-
}
|
|
282
|
-
if (bad.length > LIST_PRINT_MAX) lines.push(` …另有 ${bad.length - LIST_PRINT_MAX} 个`);
|
|
283
|
-
return lines.join('\n');
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export async function runLinkCheckCommand({ rawInput = '', invocation = null, env = {}, cfg = {}, log = null } = {}) {
|
|
287
|
-
const parsed = parseCommandInput(rawInput, [], LINK_USAGE);
|
|
288
|
-
if (parsed.error) return { kind: 'error', text: parsed.error };
|
|
289
|
-
const sessionCwd = sessionCwdOf(invocation);
|
|
290
|
-
const target = resolveTargetPath(parsed.path, { sessionCwd }) || env.workspaceRoot || '';
|
|
291
|
-
if (target && !existsSync(target)) return { kind: 'error', text: `${ERR_PATH_NOT_FOUND}${target}` };
|
|
292
|
-
const r = await callTool('link_check', { path: target }, env, cfg, log);
|
|
293
|
-
if (!r || r.ok === false) return { kind: 'error', text: r?.error || '链接检查失败' };
|
|
294
|
-
return { kind: 'success', text: formatLinkCheckCommandText(r) };
|
|
295
|
-
}
|
|
296
|
-
|
|
297
141
|
/* ───────────────────────── /git-account ───────────────────────── */
|
|
298
142
|
|
|
299
143
|
const ACCOUNT_USAGE = '用法: /git-account';
|
|
@@ -356,10 +200,7 @@ export async function runGitClonePreviewCommand({ rawInput = '', env = {}, cfg =
|
|
|
356
200
|
* keep: 便于测试断言注册集合,避免漏挂/多挂。
|
|
357
201
|
*/
|
|
358
202
|
export const SLASH_COMMANDS = [
|
|
359
|
-
{ name: 'git-audit', description: '审计当前会话工作区(未分类须写路径;--full 全量)', input: { hint: '[路径] [--full]' }, run: runGitAuditCommand },
|
|
360
203
|
{ name: 'git-scan', description: '列出各仓库分支/未提交/未推送(只读)', input: { hint: '[路径]' }, run: runGitScanCommand },
|
|
361
|
-
{ name: 'git-io-scan', description: '扫描脚本里读写文件的调用与路径,标四级风险(只读)', input: { hint: '[路径] [--write]' }, run: runGitIoScanCommand },
|
|
362
|
-
{ name: 'link-check', description: '检查文档内链接有效性(只读)', input: { hint: '[文件或目录]' }, run: runLinkCheckCommand },
|
|
363
204
|
{ name: 'git-account', description: '校验 GitHub 账号与凭据(只读)', input: { hint: '' }, run: runGitAccountCommand },
|
|
364
205
|
{ name: 'git-clone-preview', description: '预览 clone 将下载/跳过哪些文件,不落盘(只读)', input: { hint: '<owner/repo> [--branch 名]' }, run: runGitClonePreviewCommand },
|
|
365
206
|
];
|