@dependfix/engine 0.1.3 → 0.4.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 +11 -0
- package/dist/auth-provider.d.mts +82 -0
- package/dist/auth.d.mts +184 -0
- package/dist/auth.mjs +3 -0
- package/dist/auth2.mjs +361 -0
- package/dist/auth2.mjs.map +1 -0
- package/dist/index.d.mts +542 -168
- package/dist/index.mjs +1516 -403
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -6
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { i as FromPatParams, n as AuthProviderOptions, r as FromAppParams, t as AuthProvider } from "./auth-provider.mjs";
|
|
1
2
|
import { Octokit } from "@octokit/rest";
|
|
2
|
-
import { AlertClass, AlertSourceKind, AppError, FixAction, FixError, Logger, NormalizedSecurityAlert, RepositoryResult, RunResult, RunSummary, SeverityThreshold, createEmptyRunSummary } from "@dependfix/core";
|
|
3
|
+
import { AlertClass, AlertSeverity, AlertSourceKind, AppError, FixAction, FixError, Logger, NormalizedSecurityAlert, RepositoryResult, RunResult, RunSummary, SeverityThreshold, createEmptyRunSummary } from "@dependfix/core";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
//#region src/github/client.d.ts
|
|
5
|
-
interface RetryPolicyOptions {
|
|
6
|
+
export interface RetryPolicyOptions {
|
|
6
7
|
/** 最大重试次数(默认 3;0 = 不重试) */
|
|
7
8
|
maxRetries?: number;
|
|
8
9
|
/** 指数退避基数毫秒(默认 1000;测试时可调小) */
|
|
@@ -13,9 +14,25 @@ interface RetryPolicyOptions {
|
|
|
13
14
|
*/
|
|
14
15
|
maxBackoffMs?: number;
|
|
15
16
|
}
|
|
16
|
-
interface OctokitClientOptions {
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
export interface OctokitClientOptions {
|
|
18
|
+
/**
|
|
19
|
+
* 认证抽象层(M18.1 实施后唯一推荐入口)。
|
|
20
|
+
*
|
|
21
|
+
* 调用方应通过 `fromPat(token)` 或 `fromApp(params)` 构造;
|
|
22
|
+
* 优先使用此字段,新代码不得使用 deprecated 的 `token` 字段。
|
|
23
|
+
*
|
|
24
|
+
* @see {@link ../auth/auth-provider} AuthProvider 接口定义
|
|
25
|
+
* @see [C22 PAT 无感升级评估 §4.2 AuthProvider 接口设计](../../../../docs/design/governance/c22-pat-backward-compat.md)
|
|
26
|
+
*/
|
|
27
|
+
auth?: AuthProvider;
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated 使用 `auth` 替代。
|
|
30
|
+
*
|
|
31
|
+
* 保留作为低层入口;`token` 路径与 `auth: fromPat(token)` 行为等价
|
|
32
|
+
* (共享同一 retry policy 与限流重试 hook)。
|
|
33
|
+
* 计划在 M19+ 评估移除。
|
|
34
|
+
*/
|
|
35
|
+
token?: string;
|
|
19
36
|
/**
|
|
20
37
|
* API 基地址。
|
|
21
38
|
* 默认 `https://api.github.com`。
|
|
@@ -27,6 +44,10 @@ interface OctokitClientOptions {
|
|
|
27
44
|
* 默认 maxRetries=3。对 429、primary rate limit(403 + x-ratelimit-remaining: 0)、
|
|
28
45
|
* secondary rate limit(403/429 带 secondary/abuse/retry 特征)自动退避重试;
|
|
29
46
|
* 权限类 403 不重试。
|
|
47
|
+
*
|
|
48
|
+
* 行为由具体 AuthProvider 实现决定:
|
|
49
|
+
* - `PatAuthProvider` 委托给本函数(`createGitHubClient({ token, retry })`)—— retry 字段透传生效
|
|
50
|
+
* - `AppAuthProvider` 自管 retry(commit 4 实施)
|
|
30
51
|
*/
|
|
31
52
|
retry?: RetryPolicyOptions;
|
|
32
53
|
}
|
|
@@ -41,6 +62,11 @@ interface OctokitClientOptions {
|
|
|
41
62
|
*
|
|
42
63
|
* @example
|
|
43
64
|
* ```typescript
|
|
65
|
+
* // 推荐:使用 auth 抽象层(M18.1 实施后)
|
|
66
|
+
* import { fromPat } from '@dependfix/engine/auth'
|
|
67
|
+
* const octokit = createGitHubClient({ auth: fromPat('ghp_xxxx') })
|
|
68
|
+
*
|
|
69
|
+
* // 向后兼容:使用 token 字段(deprecated)
|
|
44
70
|
* const octokit = createGitHubClient({ token: 'ghp_xxxx' })
|
|
45
71
|
*
|
|
46
72
|
* // 仓库信息
|
|
@@ -53,7 +79,7 @@ interface OctokitClientOptions {
|
|
|
53
79
|
* )
|
|
54
80
|
* ```
|
|
55
81
|
*/
|
|
56
|
-
declare function createGitHubClient(options: OctokitClientOptions): Octokit;
|
|
82
|
+
export declare function createGitHubClient(options: OctokitClientOptions): Octokit;
|
|
57
83
|
/**
|
|
58
84
|
* 计算限流重试等待时间(纯函数,可单测)。
|
|
59
85
|
*
|
|
@@ -73,10 +99,52 @@ declare function createGitHubClient(options: OctokitClientOptions): Octokit;
|
|
|
73
99
|
* - 权限类 403(无限流特征)
|
|
74
100
|
* - 其他状态码
|
|
75
101
|
*/
|
|
76
|
-
declare function computeRetryDelayMs(error: unknown, attempt: number, baseDelayMs?: number, maxBackoffMs?: number): number | null;
|
|
102
|
+
export declare function computeRetryDelayMs(error: unknown, attempt: number, baseDelayMs?: number, maxBackoffMs?: number): number | null;
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/github/code-quality-fetcher.d.ts
|
|
105
|
+
export interface FetchCodeQualityFindingsParams {
|
|
106
|
+
/** 仓库所属组织或用户 */
|
|
107
|
+
owner: string;
|
|
108
|
+
/** 仓库名称 */
|
|
109
|
+
repo: string;
|
|
110
|
+
/**
|
|
111
|
+
* 告警状态过滤。
|
|
112
|
+
* 默认 `open`;GitHub 合法值 `open` / `resolved` / `dismissed`。
|
|
113
|
+
*/
|
|
114
|
+
state?: 'open' | 'resolved' | 'dismissed';
|
|
115
|
+
/** 每页数量,默认 100(GitHub API 最大值) */
|
|
116
|
+
perPage?: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 拉取指定仓库的 Code Quality findings 并映射为标准化模型。
|
|
120
|
+
*
|
|
121
|
+
* - 自动分页(cursor-based:before/after 走 `Link` header,与 GitHub 通用分页一致)
|
|
122
|
+
* - 仅处理 `state=open` 的 finding(可通过 `params.state` 覆盖)
|
|
123
|
+
* - severity:`rule.severity`(error/warning/note)经 `mapCodeQualitySeverity` 映射
|
|
124
|
+
* - Code Quality findings **不可自动修复**(`fixable: false`、`fixStrategy: null`),
|
|
125
|
+
* 首版统一归 C 类(`alertClass: 'report-only'`),不实现模板化修复
|
|
126
|
+
* - 异常通过 `mapGitHubError` 转为 `AppError`
|
|
127
|
+
* - 空仓库返回 `[]`,不抛异常
|
|
128
|
+
*
|
|
129
|
+
* @param client - 已认证的 Octokit 实例(来自 `createGitHubClient`)
|
|
130
|
+
* @param params - 仓库标识与过滤参数
|
|
131
|
+
* @returns 标准化告警列表
|
|
132
|
+
*/
|
|
133
|
+
export declare function fetchCodeQualityFindings(client: Octokit, params: FetchCodeQualityFindingsParams): Promise<NormalizedSecurityAlert[]>;
|
|
134
|
+
/**
|
|
135
|
+
* 映射 Code Quality severity:
|
|
136
|
+
* - `error` → `high`(语义对齐 code-scanning 映射:error 表示需立即关注)
|
|
137
|
+
* - `warning` → `medium`
|
|
138
|
+
* - `note` → `low`
|
|
139
|
+
* - 缺失或非法值 → `'unknown'`(不静默丢弃)
|
|
140
|
+
*
|
|
141
|
+
* 与 code-scanning 共用 `error/warning/note` 值域(GitHub CodeQL 规则同源),
|
|
142
|
+
* 映射口径与 `mapCodeScanningSeverity` 对齐(避免新源不一致)。
|
|
143
|
+
*/
|
|
144
|
+
export declare function mapCodeQualitySeverity(severity: string | null | undefined): AlertSeverity;
|
|
77
145
|
//#endregion
|
|
78
146
|
//#region src/github/code-scanning-fetcher.d.ts
|
|
79
|
-
interface FetchCodeScanningAlertsParams {
|
|
147
|
+
export interface FetchCodeScanningAlertsParams {
|
|
80
148
|
/** 仓库所属组织或用户 */
|
|
81
149
|
owner: string;
|
|
82
150
|
/** 仓库名称 */
|
|
@@ -105,10 +173,10 @@ interface FetchCodeScanningAlertsParams {
|
|
|
105
173
|
* @param params - 仓库标识与过滤参数
|
|
106
174
|
* @returns 标准化告警列表
|
|
107
175
|
*/
|
|
108
|
-
declare function fetchCodeScanningAlerts(client: Octokit, params: FetchCodeScanningAlertsParams): Promise<NormalizedSecurityAlert[]>;
|
|
176
|
+
export declare function fetchCodeScanningAlerts(client: Octokit, params: FetchCodeScanningAlertsParams): Promise<NormalizedSecurityAlert[]>;
|
|
109
177
|
//#endregion
|
|
110
178
|
//#region src/github/dependabot-fetcher.d.ts
|
|
111
|
-
interface FetchDependabotAlertsParams {
|
|
179
|
+
export interface FetchDependabotAlertsParams {
|
|
112
180
|
/** 仓库所属组织或用户 */
|
|
113
181
|
owner: string;
|
|
114
182
|
/** 仓库名称 */
|
|
@@ -135,11 +203,16 @@ interface FetchDependabotAlertsParams {
|
|
|
135
203
|
*
|
|
136
204
|
* @example
|
|
137
205
|
* ```typescript
|
|
138
|
-
*
|
|
206
|
+
* // 推荐:使用 auth 抽象层(M18.1 实施后)
|
|
207
|
+
* import { fromPat } from '@dependfix/engine/auth'
|
|
208
|
+
* const octokit = createGitHubClient({ auth: fromPat('ghp_xxxx') })
|
|
139
209
|
* const alerts = await fetchDependabotAlerts(octokit, { owner: 'foo', repo: 'bar' })
|
|
210
|
+
*
|
|
211
|
+
* // 向后兼容:使用 token 字段(deprecated)
|
|
212
|
+
* const octokit = createGitHubClient({ token: 'ghp_xxxx' })
|
|
140
213
|
* ```
|
|
141
214
|
*/
|
|
142
|
-
declare function fetchDependabotAlerts(client: Octokit, params: FetchDependabotAlertsParams): Promise<NormalizedSecurityAlert[]>;
|
|
215
|
+
export declare function fetchDependabotAlerts(client: Octokit, params: FetchDependabotAlertsParams): Promise<NormalizedSecurityAlert[]>;
|
|
143
216
|
//#endregion
|
|
144
217
|
//#region src/github/errors.d.ts
|
|
145
218
|
/**
|
|
@@ -148,10 +221,10 @@ declare function fetchDependabotAlerts(client: Octokit, params: FetchDependabotA
|
|
|
148
221
|
* @param error - 原始错误(`RequestError` 或网络异常)
|
|
149
222
|
* @param context - 调用上下文描述(如 `'fetch repo info for foo/bar'`),会附加到错误消息中
|
|
150
223
|
*/
|
|
151
|
-
declare function mapGitHubError(error: unknown, context: string): AppError;
|
|
224
|
+
export declare function mapGitHubError(error: unknown, context: string): AppError;
|
|
152
225
|
//#endregion
|
|
153
226
|
//#region src/github/pr-creator.d.ts
|
|
154
|
-
interface CreatePullRequestParams {
|
|
227
|
+
export interface CreatePullRequestParams {
|
|
155
228
|
/** 已认证的 Octokit 实例 */
|
|
156
229
|
octokit: Octokit;
|
|
157
230
|
/** 仓库 owner */
|
|
@@ -167,20 +240,20 @@ interface CreatePullRequestParams {
|
|
|
167
240
|
/** PR 内容(Markdown) */
|
|
168
241
|
body: string;
|
|
169
242
|
}
|
|
170
|
-
interface PullRequestResult {
|
|
243
|
+
export interface PullRequestResult {
|
|
171
244
|
/** PR 编号 */
|
|
172
245
|
number: number;
|
|
173
246
|
/** PR HTML URL */
|
|
174
247
|
htmlUrl: string;
|
|
175
248
|
}
|
|
176
|
-
interface FixBranchResult {
|
|
249
|
+
export interface FixBranchResult {
|
|
177
250
|
/** 分支名 */
|
|
178
251
|
branchName: string;
|
|
179
252
|
/** 是否为新创建 */
|
|
180
253
|
created: boolean;
|
|
181
254
|
}
|
|
182
255
|
/** dependfix 自动修复 PR 的公开信息(用于查重/取代判定) */
|
|
183
|
-
interface DependfixOpenPR {
|
|
256
|
+
export interface DependfixOpenPR {
|
|
184
257
|
/** PR 编号 */
|
|
185
258
|
number: number;
|
|
186
259
|
/** PR HTML URL */
|
|
@@ -203,15 +276,15 @@ interface DependfixOpenPR {
|
|
|
203
276
|
* 不用 diff hash 是因为 pnpm 版本等非确定性因素会使锁文件内容漂移,
|
|
204
277
|
* 导致"告警没变但指纹变"。
|
|
205
278
|
*/
|
|
206
|
-
declare function computeFixFingerprint(actions: FixAction[]): string;
|
|
279
|
+
export declare function computeFixFingerprint(actions: FixAction[]): string;
|
|
207
280
|
/**
|
|
208
281
|
* 从分支名提取内容指纹(`dependfix/auto-fix-{fp8}` → `{fp8}`)。
|
|
209
282
|
* 指纹格式为 8 位 hex;分支名不含 `-` 后的内容、前缀不匹配或格式不合法时返回 null
|
|
210
283
|
* (如旧版 runId 分支,会被 supersede)。
|
|
211
284
|
*/
|
|
212
|
-
declare function extractFingerprintFromBranch(branchName: string): string | null;
|
|
285
|
+
export declare function extractFingerprintFromBranch(branchName: string): string | null;
|
|
213
286
|
/** fix-and-pr 去重决策结果 */
|
|
214
|
-
interface FixAndPrPlan {
|
|
287
|
+
export interface FixAndPrPlan {
|
|
215
288
|
/** skip = 已有同内容 PR,不重复提交;create = 需要新建 PR */
|
|
216
289
|
action: 'skip' | 'create';
|
|
217
290
|
/** action=skip 时命中的同内容 PR */
|
|
@@ -224,7 +297,7 @@ interface FixAndPrPlan {
|
|
|
224
297
|
* - 存在同指纹 open PR → skip(仅需关闭其余异指纹 PR)
|
|
225
298
|
* - 否则 → create(关闭全部旧 PR,先建新后关旧由调用方保证)
|
|
226
299
|
*/
|
|
227
|
-
declare function computeFixAndPrPlan(existingPRs: DependfixOpenPR[], fingerprint: string): FixAndPrPlan;
|
|
300
|
+
export declare function computeFixAndPrPlan(existingPRs: DependfixOpenPR[], fingerprint: string): FixAndPrPlan;
|
|
228
301
|
/**
|
|
229
302
|
* 在工作目录创建修复分支。
|
|
230
303
|
*
|
|
@@ -233,18 +306,27 @@ declare function computeFixAndPrPlan(existingPRs: DependfixOpenPR[], fingerprint
|
|
|
233
306
|
*
|
|
234
307
|
* @returns 分支名和是否为新创建
|
|
235
308
|
*/
|
|
236
|
-
declare function createFixBranch(branchName: string, workDir: string): FixBranchResult;
|
|
309
|
+
export declare function createFixBranch(branchName: string, workDir: string): FixBranchResult;
|
|
237
310
|
/**
|
|
238
311
|
* 暂存所有变更并提交。
|
|
239
312
|
* 自动设置 git user.name / user.email(如未设置)。
|
|
240
313
|
* 使用 `execFileSync` 参数数组形式(不经 shell),保证多行 commit message
|
|
241
314
|
* 与 UTF-8 字符(如 →)在 Windows/Linux 双平台传递一致。
|
|
315
|
+
*
|
|
316
|
+
* W3 修复(M18.4 audit round 2):显式传 `-c user.name=X -c user.email=Y` 强制 commit author
|
|
317
|
+
* 使用传入值,不受 host 全局 `user.name`(如 CaoMeiYouRen)污染——`git commit` 走 lookup order
|
|
318
|
+
* (env → `-c` config → local → global → system),显式 `-c` 在 lookup order 中最高优先。
|
|
319
|
+
*
|
|
320
|
+
* @param author - 可选 commit author 信息;不传时使用 PAT 默认值(保持现有 PAT 路径行为零变化)。
|
|
321
|
+
* M18.2 之后 GitHub App 路径会传入动态生成的 `{app_id}+{bot_login}[bot]` author。
|
|
322
|
+
*
|
|
323
|
+
* @see [C22 PAT 无感升级评估 §5.1 兼容性](../../../../docs/design/governance/c22-pat-backward-compat.md)
|
|
242
324
|
*/
|
|
243
|
-
declare function stageAndCommit(message: string, workDir: string
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
declare function pushBranch(branchName: string, workDir: string): void;
|
|
325
|
+
export declare function stageAndCommit(message: string, workDir: string, author?: {
|
|
326
|
+
name: string;
|
|
327
|
+
email: string;
|
|
328
|
+
}): void;
|
|
329
|
+
export declare function pushBranch(branchName: string, workDir: string): void;
|
|
248
330
|
/**
|
|
249
331
|
* 查找目标仓库中所有 open 状态的 dependfix 自动修复 PR。
|
|
250
332
|
*
|
|
@@ -252,17 +334,35 @@ declare function pushBranch(branchName: string, workDir: string): void;
|
|
|
252
334
|
* 按 head 分支前缀 `dependfix/auto-fix-` 过滤。假设 PR 数量不多(单页 100 足够),
|
|
253
335
|
* 未来 PR 数量增大时可引入 label 索引(backlog 已登记演进项)。
|
|
254
336
|
*/
|
|
255
|
-
declare function findDependfixOpenPR(octokit: Octokit, owner: string, repo: string): Promise<DependfixOpenPR[]>;
|
|
337
|
+
export declare function findDependfixOpenPR(octokit: Octokit, owner: string, repo: string): Promise<DependfixOpenPR[]>;
|
|
256
338
|
/**
|
|
257
339
|
* 关闭 Pull Request(用于 supersede 旧 PR)。
|
|
258
340
|
*/
|
|
259
|
-
declare function closePullRequest(octokit: Octokit, owner: string, repo: string, pullNumber: number): Promise<void>;
|
|
341
|
+
export declare function closePullRequest(octokit: Octokit, owner: string, repo: string, pullNumber: number): Promise<void>;
|
|
342
|
+
/**
|
|
343
|
+
* 在 Pull Request 上添加评论。
|
|
344
|
+
*
|
|
345
|
+
* 使用 `issues.createComment` 端点(GitHub PR 评论复用 issue comment API),
|
|
346
|
+
* 需要 token 具备 `issues: write` 权限(比 `pull-requests: write` 宽)。
|
|
347
|
+
*
|
|
348
|
+
* 用于在新 PR 上评论指向被取代的旧 PR,避免用户手动排查重复 PR。
|
|
349
|
+
*/
|
|
350
|
+
export declare function commentOnPullRequest(octokit: Octokit, owner: string, repo: string, pullNumber: number, body: string): Promise<void>;
|
|
351
|
+
/**
|
|
352
|
+
* 在 Pull Request 上添加 label。
|
|
353
|
+
*
|
|
354
|
+
* 使用 `issues.addLabels` 端点(GitHub PR label 复用 issue label API),
|
|
355
|
+
* 需要 token 具备 `issues: write` 权限。
|
|
356
|
+
*
|
|
357
|
+
* 用于标记重复 PR(如 `duplicate` label),便于用户过滤和管理。
|
|
358
|
+
*/
|
|
359
|
+
export declare function addLabelToPullRequest(octokit: Octokit, owner: string, repo: string, pullNumber: number, labels: string[]): Promise<void>;
|
|
260
360
|
/**
|
|
261
361
|
* 通过 GitHub API 创建 Pull Request。
|
|
262
362
|
*/
|
|
263
|
-
declare function createPullRequest(params: CreatePullRequestParams): Promise<PullRequestResult>;
|
|
363
|
+
export declare function createPullRequest(params: CreatePullRequestParams): Promise<PullRequestResult>;
|
|
264
364
|
/** 分支清理状态(用于 cleanup-branches 清单分类) */
|
|
265
|
-
interface DependfixBranchStatus {
|
|
365
|
+
export interface DependfixBranchStatus {
|
|
266
366
|
/** 分支名 */
|
|
267
367
|
branch: string;
|
|
268
368
|
/** 关联 PR 编号(无 PR 记录时为 null) */
|
|
@@ -275,19 +375,19 @@ interface DependfixBranchStatus {
|
|
|
275
375
|
/**
|
|
276
376
|
* 列出远端所有 `dependfix/` 前缀分支(git.listMatchingRefs 精确前缀匹配)。
|
|
277
377
|
*/
|
|
278
|
-
declare function listDependfixBranches(octokit: Octokit, owner: string, repo: string): Promise<string[]>;
|
|
378
|
+
export declare function listDependfixBranches(octokit: Octokit, owner: string, repo: string): Promise<string[]>;
|
|
279
379
|
/**
|
|
280
380
|
* 查询分支对应的最近 PR 状态(pulls.list head 精确匹配,按最近更新取 1 条)。
|
|
281
381
|
*/
|
|
282
|
-
declare function getBranchPrStatus(octokit: Octokit, owner: string, repo: string, branch: string): Promise<DependfixBranchStatus>;
|
|
382
|
+
export declare function getBranchPrStatus(octokit: Octokit, owner: string, repo: string, branch: string): Promise<DependfixBranchStatus>;
|
|
283
383
|
/**
|
|
284
384
|
* 删除远端分支(git ref delete)。失败(分支保护、不存在)由调用方捕获处理。
|
|
285
385
|
*/
|
|
286
|
-
declare function deleteRemoteBranch(octokit: Octokit, owner: string, repo: string, branch: string): Promise<void>;
|
|
386
|
+
export declare function deleteRemoteBranch(octokit: Octokit, owner: string, repo: string, branch: string): Promise<void>;
|
|
287
387
|
/**
|
|
288
388
|
* 判定交互确认回答是否为"是"(y/yes,大小写不敏感;空输入默认拒绝)。
|
|
289
389
|
*/
|
|
290
|
-
declare function isConfirmAnswer(answer: string): boolean;
|
|
390
|
+
export declare function isConfirmAnswer(answer: string): boolean;
|
|
291
391
|
/**
|
|
292
392
|
* 从 RunResult 生成 PR body(Markdown)。
|
|
293
393
|
*
|
|
@@ -299,11 +399,11 @@ declare function isConfirmAnswer(answer: string): boolean;
|
|
|
299
399
|
*
|
|
300
400
|
* @param supersededNumbers 被本 PR 取代并已关闭的旧 PR 编号列表(用于 Supersedes 声明)
|
|
301
401
|
*/
|
|
302
|
-
declare function generatePRBody(result: RunResult, supersededNumbers?: number[]): string;
|
|
402
|
+
export declare function generatePRBody(result: RunResult, supersededNumbers?: number[]): string;
|
|
303
403
|
//#endregion
|
|
304
404
|
//#region src/github/repo-policy.d.ts
|
|
305
405
|
/** 单条 glob 模式长度上限(加固:防止超长模式引入匹配开销;受信配置 + 短输入) */
|
|
306
|
-
declare const MAX_GLOB_PATTERN_LENGTH = 200;
|
|
406
|
+
export declare const MAX_GLOB_PATTERN_LENGTH = 200;
|
|
307
407
|
/**
|
|
308
408
|
* 将仓库 glob 模式转正则(`owner/*`、`owner/pkg-*`)。
|
|
309
409
|
*
|
|
@@ -317,10 +417,10 @@ declare const MAX_GLOB_PATTERN_LENGTH = 200;
|
|
|
317
417
|
* 多通配符模式存在理论 O(n^k) 回溯面(`[^/]*` 单层字符类、输入 ≤ ~140 字符,风险低);
|
|
318
418
|
* 正则引擎演进时需专项 ReDoS 审计。
|
|
319
419
|
*/
|
|
320
|
-
declare function repoGlobToRegExp(pattern: string): RegExp;
|
|
420
|
+
export declare function repoGlobToRegExp(pattern: string): RegExp;
|
|
321
421
|
/** glob 模式匹配 `owner/repo`(完整匹配)。 */
|
|
322
|
-
declare function matchesRepoGlob(pattern: string, fullName: string): boolean;
|
|
323
|
-
interface RepoPolicy {
|
|
422
|
+
export declare function matchesRepoGlob(pattern: string, fullName: string): boolean;
|
|
423
|
+
export interface RepoPolicy {
|
|
324
424
|
/** 白名单 glob(仅作用于发现结果;显式列表不受影响) */
|
|
325
425
|
include?: string[];
|
|
326
426
|
/** 黑名单 glob(显式列表 + 发现结果均受约束;与 include 冲突时胜出) */
|
|
@@ -329,30 +429,30 @@ interface RepoPolicy {
|
|
|
329
429
|
topicsExclude?: string[];
|
|
330
430
|
}
|
|
331
431
|
/** 是否命中任一 exclude 模式(黑名单)。 */
|
|
332
|
-
declare function matchesRepoExclude(policy: RepoPolicy, fullName: string): boolean;
|
|
432
|
+
export declare function matchesRepoExclude(policy: RepoPolicy, fullName: string): boolean;
|
|
333
433
|
/** 是否通过 include 白名单(include 为空 = 不限制;非空 = 必须命中任一模式)。 */
|
|
334
|
-
declare function matchesRepoInclude(policy: RepoPolicy, fullName: string): boolean;
|
|
434
|
+
export declare function matchesRepoInclude(policy: RepoPolicy, fullName: string): boolean;
|
|
335
435
|
/** topic 黑名单:仓库 topics 含任一指定 topic 即排除(大小写归一化后比较)。 */
|
|
336
|
-
declare function matchesTopicsExclude(policy: RepoPolicy, topics: string[]): boolean;
|
|
436
|
+
export declare function matchesTopicsExclude(policy: RepoPolicy, topics: string[]): boolean;
|
|
337
437
|
/**
|
|
338
438
|
* 过滤显式仓库列表:仅受 exclude 约束(白名单 include 不适用于显式列表,
|
|
339
439
|
* 设计要点:显式优先,用户显式指定的仓库不应被 include 静默剔除)。
|
|
340
440
|
*/
|
|
341
|
-
declare function filterExplicitRepositories(policy: RepoPolicy, repositories: string[]): string[];
|
|
441
|
+
export declare function filterExplicitRepositories(policy: RepoPolicy, repositories: string[]): string[];
|
|
342
442
|
//#endregion
|
|
343
443
|
//#region src/github/repo-selector.d.ts
|
|
344
444
|
/**
|
|
345
445
|
* 从文件读取仓库列表(每行一个 `owner/repo`)。
|
|
346
446
|
* 空行和 `#` 开头的注释行会被跳过。
|
|
347
447
|
*/
|
|
348
|
-
declare function readReposFile(filePath: string): string[];
|
|
448
|
+
export declare function readReposFile(filePath: string): string[];
|
|
349
449
|
/**
|
|
350
450
|
* 合并 CLI 传入仓库列表与文件中的仓库列表,去重并校验。
|
|
351
451
|
*/
|
|
352
|
-
declare function resolveRepoList(cliRepos: string[], reposFilePath?: string): string[];
|
|
452
|
+
export declare function resolveRepoList(cliRepos: string[], reposFilePath?: string): string[];
|
|
353
453
|
//#endregion
|
|
354
454
|
//#region src/github/repository-discovery.d.ts
|
|
355
|
-
interface RepositoryDiscoveryOptions {
|
|
455
|
+
export interface RepositoryDiscoveryOptions {
|
|
356
456
|
/** 已认证的 Octokit 实例 */
|
|
357
457
|
client: Octokit;
|
|
358
458
|
/** owner / org 列表(分别拉取后合并) */
|
|
@@ -376,8 +476,14 @@ interface RepositoryDiscoveryOptions {
|
|
|
376
476
|
probeDependabot?: boolean;
|
|
377
477
|
/** dependabot.yml 探测并发上限(默认 5,避免一次性打爆 API) */
|
|
378
478
|
probeConcurrency?: number;
|
|
479
|
+
/**
|
|
480
|
+
* 发现规模上限:最多保留的仓库数(按 fullName 字典序排序后截断)。
|
|
481
|
+
* 默认 100;设为 0 或负数表示不限制。
|
|
482
|
+
* 大 org 场景下防止一次性全量发现导致 API 配额不可控消耗和超时。
|
|
483
|
+
*/
|
|
484
|
+
maxRepos?: number;
|
|
379
485
|
}
|
|
380
|
-
interface DiscoveredRepository {
|
|
486
|
+
export interface DiscoveredRepository {
|
|
381
487
|
/** `owner/repo` 格式 */
|
|
382
488
|
fullName: string;
|
|
383
489
|
defaultBranch: string;
|
|
@@ -393,24 +499,80 @@ interface DiscoveredRepository {
|
|
|
393
499
|
* 2. topic 过滤(`--repo-topics`,AND 语义)
|
|
394
500
|
* 3. 名单策略过滤(include / exclude / topicsExclude,探测前应用)
|
|
395
501
|
* 4. dependabot.yml 探测(仅候选仓库触达 contents API;404 视为不支持,不剔除)
|
|
502
|
+
* 5. 规模上限截断(`maxRepos`,按 fullName 字典序排序后截断)
|
|
396
503
|
*
|
|
397
504
|
* 结果按 `fullName` 字典序排序,保证同输入多次运行结果一致
|
|
398
505
|
* (runId / 指纹稳定性前提)。
|
|
399
506
|
*
|
|
400
507
|
* @throws AppError(mapGitHubError 转换;token 权限、网络等全局性问题 fail-fast)
|
|
401
508
|
*/
|
|
402
|
-
declare function discoverRepositories(options: RepositoryDiscoveryOptions): Promise<DiscoveredRepository[]>;
|
|
509
|
+
export declare function discoverRepositories(options: RepositoryDiscoveryOptions): Promise<DiscoveredRepository[]>;
|
|
403
510
|
/**
|
|
404
511
|
* 合并显式仓库列表与发现结果:
|
|
405
512
|
* - 显式优先:显式列表保持原顺序且在前
|
|
406
513
|
* - 发现结果仅补充未出现的项(去重;大小写不敏感——GitHub full_name 恒小写,
|
|
407
514
|
* 显式 `Owner/Repo` 与发现 `owner/repo` 视为同一仓库)
|
|
408
515
|
*/
|
|
409
|
-
declare function mergeRepositories(explicit: string[], discovered: string[]): string[];
|
|
516
|
+
export declare function mergeRepositories(explicit: string[], discovered: string[]): string[];
|
|
517
|
+
//#endregion
|
|
518
|
+
//#region src/github/token-scope.d.ts
|
|
519
|
+
/**
|
|
520
|
+
* 凭据权限面启动检查(安全治理:超权限 token 启动即警告)。
|
|
521
|
+
*
|
|
522
|
+
* 判定依据 GitHub API 的 `GET /user` 响应头:
|
|
523
|
+
* - `x-oauth-scopes`:classic PAT 的 scope 列表(`repo` 即全量仓库权限)
|
|
524
|
+
* - `x-accepted-github-permissions`:fine-grained PAT / 内置 GITHUB_TOKEN 的
|
|
525
|
+
* 已接受权限列表(`resource: access` 格式)
|
|
526
|
+
*
|
|
527
|
+
* 语义:最小权限 = fine-grained token(仅目标仓库的
|
|
528
|
+
* `contents`/`pull-requests` 写 + `security-events` 读 + `metadata` 读)。
|
|
529
|
+
* classic PAT 的 `repo` scope 是全量仓库权限,属于超权限——一旦被恶意
|
|
530
|
+
* 依赖脚本窃取即可接管所有可见仓库(威胁链 B 路径的最终防线是凭据权限面)。
|
|
531
|
+
* 检查为 best-effort:网络失败 / 无 token / 无法判定时静默跳过,不阻断运行。
|
|
532
|
+
*/
|
|
533
|
+
export interface TokenScopeWarning {
|
|
534
|
+
code: 'CLASSIC_REPO_SCOPE' | 'MISSING_SECURITY_EVENTS';
|
|
535
|
+
message: string;
|
|
536
|
+
}
|
|
537
|
+
export interface TokenScopeAnalysis {
|
|
538
|
+
/** classic PAT 的 scopes(x-oauth-scopes 解析结果) */
|
|
539
|
+
scopes?: string[];
|
|
540
|
+
/** fine-grained PAT 的 accepted permissions(x-accepted-github-permissions 解析结果) */
|
|
541
|
+
acceptedPermissions?: string[];
|
|
542
|
+
/** 需要提示用户的权限问题(空 = 无问题) */
|
|
543
|
+
warnings: TokenScopeWarning[];
|
|
544
|
+
}
|
|
545
|
+
export interface TokenScopeCheckResult extends TokenScopeAnalysis {
|
|
546
|
+
/** 探测是否成功(鉴权/网络失败为 false,调用方静默跳过) */
|
|
547
|
+
ok: boolean;
|
|
548
|
+
/** 认证用户登录名(探测成功时填充) */
|
|
549
|
+
login?: string;
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* 解析 GitHub token 权限面并输出警告(纯函数,可单测)。
|
|
553
|
+
*
|
|
554
|
+
* @param scopeHeader `GET /user` 响应的 `x-oauth-scopes` 头(classic PAT 才有值)
|
|
555
|
+
* @param acceptedHeader `GET /user` 响应的 `x-accepted-github-permissions` 头(fine-grained / 内置 token 才有值)
|
|
556
|
+
* @param options.codeScanningEnabled 是否开启 Code Scanning 源(开启时校验 security-events 权限)
|
|
557
|
+
*/
|
|
558
|
+
export declare function analyzeTokenScope(scopeHeader: string | undefined, acceptedHeader: string | undefined, options?: {
|
|
559
|
+
codeScanningEnabled?: boolean;
|
|
560
|
+
}): TokenScopeAnalysis;
|
|
561
|
+
/**
|
|
562
|
+
* 探测 token 权限面(网络调用,best-effort)。
|
|
563
|
+
* 任何失败(鉴权 401 / 网络错误 / 超时)均静默返回 `ok: false`,不抛错。
|
|
564
|
+
*/
|
|
565
|
+
export declare function checkTokenPermissions(client: Octokit, options?: {
|
|
566
|
+
codeScanningEnabled?: boolean;
|
|
567
|
+
}): Promise<TokenScopeCheckResult>;
|
|
410
568
|
//#endregion
|
|
411
569
|
//#region src/code-scanning/rule-classifier.d.ts
|
|
412
570
|
/**
|
|
413
|
-
* A
|
|
571
|
+
* A 类自动修复白名单默认集合(默认值常量;测试 disjointness 不变量用)。
|
|
572
|
+
*
|
|
573
|
+
* **与 active config 的关系**:本导出为默认常量(向后兼容历史测试与外部引用),
|
|
574
|
+
* 运行时 classifyRule 实际从 `getActiveRulesConfig().autoFixable` 读取。
|
|
575
|
+
* 若配置已被 setActiveRulesConfig 替换,本常量与运行时分类可能不一致(设计意图)。
|
|
414
576
|
*
|
|
415
577
|
* 选择标准(实现时评审确认):
|
|
416
578
|
* - 可模板化:修复动作可机械描述(删行 / 对齐 / 移除空白)
|
|
@@ -425,9 +587,9 @@ declare function mergeRepositories(explicit: string[], discovered: string[]): st
|
|
|
425
587
|
* 纯格式规则(eol-last 等)实际出现频率低;此处先建立机制,
|
|
426
588
|
* 规则命中与否不影响分层正确性。
|
|
427
589
|
*/
|
|
428
|
-
declare const AUTO_FIXABLE_RULES:
|
|
590
|
+
export declare const AUTO_FIXABLE_RULES: ReadonlySet<string>;
|
|
429
591
|
/**
|
|
430
|
-
* B
|
|
592
|
+
* B 类建议规则默认列表(默认值常量;测试 disjointness 不变量用)。
|
|
431
593
|
*
|
|
432
594
|
* 收录原则:
|
|
433
595
|
* - 安全敏感(注入 / XSS / 路径穿越 / 密码学等),修复需结合业务语义
|
|
@@ -440,25 +602,90 @@ declare const AUTO_FIXABLE_RULES: Set<string>;
|
|
|
440
602
|
* 其余语言(go/ruby/csharp/cpp 等)与未收录变体(如 js/reflected-xss)落 C 类兜底;
|
|
441
603
|
* 真实仓库 API 样本核对(rule id 格式与变体分布)登记为演进项。
|
|
442
604
|
*/
|
|
443
|
-
declare const SUGGESTED_RULES: Set<string>;
|
|
605
|
+
export declare const SUGGESTED_RULES: Set<string>;
|
|
444
606
|
/**
|
|
445
607
|
* 规则分类:
|
|
446
608
|
* - A 类白名单 → `'auto-fixable'`
|
|
447
609
|
* - B 类建议列表 → `'suggested'`
|
|
448
610
|
* - 其余(含空字符串)→ `'report-only'`(C 类,默认,不静默丢弃)
|
|
611
|
+
*
|
|
612
|
+
* 读取自当前生效配置(`getActiveRulesConfig()`);首次调用前需通过
|
|
613
|
+
* `setActiveRulesConfig` 替换或保持默认。
|
|
614
|
+
*/
|
|
615
|
+
export declare function classifyRule(ruleId: string | null | undefined): AlertClass;
|
|
616
|
+
/**
|
|
617
|
+
* B 类建议规则的人工修复方向(报告/PR body 建议区块展示)。
|
|
618
|
+
* 读取自当前生效配置(`getActiveRulesConfig().suggested`);未收录规则返回通用建议(C 类兜底,不静默)。
|
|
449
619
|
*/
|
|
450
|
-
declare function
|
|
451
|
-
|
|
452
|
-
|
|
620
|
+
export declare function suggestionFor(ruleId: string | null | undefined): string;
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/code-scanning/rule-config.d.ts
|
|
623
|
+
export type RuleClass = 'auto-fixable' | 'suggested' | 'report-only';
|
|
624
|
+
export interface RuleConfigEntry {
|
|
625
|
+
/** 规则 id(如 `js/sql-injection`,trim 后用于匹配;空串非法) */
|
|
626
|
+
id: string;
|
|
627
|
+
/** 分类 */
|
|
628
|
+
class: RuleClass;
|
|
629
|
+
/** B 类建议文本(A/C 类可省略) */
|
|
630
|
+
suggestion?: string;
|
|
631
|
+
}
|
|
632
|
+
export interface RulesConfigFile {
|
|
633
|
+
rules: RuleConfigEntry[];
|
|
634
|
+
}
|
|
635
|
+
/** 编译后的内部表示:高性能查找(A 类 Set / B 类 Map) */
|
|
636
|
+
export interface CompiledRulesConfig {
|
|
637
|
+
autoFixable: ReadonlySet<string>;
|
|
638
|
+
suggested: ReadonlyMap<string, string>;
|
|
639
|
+
}
|
|
640
|
+
/** 默认规则配置(编译后;与既有常量表等价,单点声明保持向后兼容) */
|
|
641
|
+
export declare const DEFAULT_RULES_CONFIG: CompiledRulesConfig;
|
|
642
|
+
/**
|
|
643
|
+
* 解析 JSON 配置输入为编译后配置。
|
|
644
|
+
*
|
|
645
|
+
* 校验规则(全部失败均降级返回 null,由调用方走默认):
|
|
646
|
+
* - 顶层必须是对象,含 `rules` 数组
|
|
647
|
+
* - 每个 entry 必须含非空 `id`(trim 后)、合法 `class`
|
|
648
|
+
* - 同 id 在多个 class 中出现 → 拒绝(disjointness 不变量)
|
|
649
|
+
* - suggested 必须含 `suggestion` 字段且非空
|
|
650
|
+
*
|
|
651
|
+
* @returns 解析成功 → 编译后配置;失败 → null(调用方降级)
|
|
652
|
+
*/
|
|
653
|
+
export declare function parseRulesConfig(input: unknown): CompiledRulesConfig | null;
|
|
654
|
+
/**
|
|
655
|
+
* 从 JSON 文件路径加载并编译。读取失败 / 解析失败 / 校验失败 → 返回 null(调用方降级)。
|
|
656
|
+
*/
|
|
657
|
+
export declare function loadRulesConfigFromFile(configPath: string): CompiledRulesConfig | null;
|
|
658
|
+
/** 环境变量名:Code Scanning 规则分类配置文件路径 */
|
|
659
|
+
export declare const RULE_CONFIG_ENV = "CODE_SCANNING_RULES_CONFIG_PATH";
|
|
660
|
+
/**
|
|
661
|
+
* 从 env 读取 `RULE_CONFIG_ENV` 并尝试加载。
|
|
662
|
+
*
|
|
663
|
+
* - env 未设或空 → 返回 null(调用方继续走默认)
|
|
664
|
+
* - 路径不存在 → 返回 null
|
|
665
|
+
* - 加载失败 → 返回 null(错误已写入 stderr)
|
|
666
|
+
*/
|
|
667
|
+
export declare function loadRulesConfigFromEnv(env: NodeJS.ProcessEnv): CompiledRulesConfig | null;
|
|
668
|
+
/** 获取当前生效的配置(classifyRule / suggestionFor 内部使用) */
|
|
669
|
+
export declare function getActiveRulesConfig(): CompiledRulesConfig;
|
|
670
|
+
/**
|
|
671
|
+
* 替换为自定义配置。
|
|
672
|
+
*
|
|
673
|
+
* **使用协议**:运行时模块初始化时(如 AppContext 装配)调用一次;
|
|
674
|
+
* 测试可临时覆盖后通过 `resetActiveRulesConfig` 恢复。频繁切换会破坏
|
|
675
|
+
* `code-scanning-fetcher` 的可预测行为(同一规则在不同 fetch 中分类不同)。
|
|
676
|
+
*/
|
|
677
|
+
export declare function setActiveRulesConfig(config: CompiledRulesConfig): void;
|
|
678
|
+
/** 重置为默认配置(测试 cleanup + 运行时 fallback) */
|
|
679
|
+
export declare function resetActiveRulesConfig(): void;
|
|
453
680
|
//#endregion
|
|
454
681
|
//#region src/code-scanning/templates.d.ts
|
|
455
|
-
interface TemplateApplyResult {
|
|
682
|
+
export interface TemplateApplyResult {
|
|
456
683
|
/** 修改后的文件内容 */
|
|
457
684
|
content: string;
|
|
458
685
|
/** 是否实际产生修改(false = 文件已合规,无需改动) */
|
|
459
686
|
changed: boolean;
|
|
460
687
|
}
|
|
461
|
-
interface CodeScanningFixTemplate {
|
|
688
|
+
export interface CodeScanningFixTemplate {
|
|
462
689
|
/** 对应规则 id(A 类白名单成员) */
|
|
463
690
|
ruleId: string;
|
|
464
691
|
/**
|
|
@@ -471,10 +698,10 @@ interface CodeScanningFixTemplate {
|
|
|
471
698
|
describe(filePath: string, changed: boolean, alert: NormalizedSecurityAlert): string;
|
|
472
699
|
}
|
|
473
700
|
/** 获取规则对应的修复模板;无模板返回 undefined(调用方回退建议模式)。 */
|
|
474
|
-
declare function getCodeScanningFixTemplate(ruleId: string): CodeScanningFixTemplate | undefined;
|
|
701
|
+
export declare function getCodeScanningFixTemplate(ruleId: string): CodeScanningFixTemplate | undefined;
|
|
475
702
|
//#endregion
|
|
476
703
|
//#region src/fixers/dependency/index.d.ts
|
|
477
|
-
interface UpgradeDependencyParams {
|
|
704
|
+
export interface UpgradeDependencyParams {
|
|
478
705
|
/** 包名(如 `'lodash'`, `'@babel/traverse'`) */
|
|
479
706
|
packageName: string;
|
|
480
707
|
/** 目标精确版本(如 `'4.17.21'`) */
|
|
@@ -489,7 +716,7 @@ interface UpgradeDependencyParams {
|
|
|
489
716
|
*/
|
|
490
717
|
manifestDir?: string;
|
|
491
718
|
}
|
|
492
|
-
interface DependencyFixResult {
|
|
719
|
+
export interface DependencyFixResult {
|
|
493
720
|
packageName: string;
|
|
494
721
|
/** 升级前版本声明(保留原始 range 格式,如 `^4.17.20`) */
|
|
495
722
|
fromVersion: string;
|
|
@@ -504,7 +731,7 @@ interface DependencyFixResult {
|
|
|
504
731
|
/** 成功但存在需要用户注意的附加信息(如 overrides 写入位置可能被 pnpm 忽略) */
|
|
505
732
|
warning?: string;
|
|
506
733
|
}
|
|
507
|
-
interface PackageJson {
|
|
734
|
+
export interface PackageJson {
|
|
508
735
|
name?: string;
|
|
509
736
|
dependencies?: Record<string, string>;
|
|
510
737
|
devDependencies?: Record<string, string>;
|
|
@@ -535,7 +762,7 @@ interface DependencyInfo {
|
|
|
535
762
|
* @param params - 包名、目标版本、工作目录、可选成员目录
|
|
536
763
|
* @returns 修复结果
|
|
537
764
|
*/
|
|
538
|
-
declare function upgradeDependency(params: UpgradeDependencyParams): Promise<DependencyFixResult>;
|
|
765
|
+
export declare function upgradeDependency(params: UpgradeDependencyParams): Promise<DependencyFixResult>;
|
|
539
766
|
/**
|
|
540
767
|
* 通过 pnpm `overrides` 升级间接(transitive)依赖。
|
|
541
768
|
*
|
|
@@ -550,7 +777,7 @@ declare function upgradeDependency(params: UpgradeDependencyParams): Promise<Dep
|
|
|
550
777
|
* @param params - 包名、目标版本、工作目录
|
|
551
778
|
* @returns 修复结果
|
|
552
779
|
*/
|
|
553
|
-
declare function overrideTransitiveDependency(params: UpgradeDependencyParams): Promise<DependencyFixResult>;
|
|
780
|
+
export declare function overrideTransitiveDependency(params: UpgradeDependencyParams): Promise<DependencyFixResult>;
|
|
554
781
|
/**
|
|
555
782
|
* 通过 pnpm `overrides` **批量**写入覆盖条目并执行 install(多版本共存 / 单 major 统一入口)。
|
|
556
783
|
*
|
|
@@ -573,7 +800,7 @@ declare function overrideTransitiveDependency(params: UpgradeDependencyParams):
|
|
|
573
800
|
* @param params - 包名、overrides 映射(`pkg@major` 或 `pkg` → `^target`)、工作目录
|
|
574
801
|
* @returns 修复结果(fromVersion 为空字符串,表示多实例无单一来源版本)
|
|
575
802
|
*/
|
|
576
|
-
declare function applyVersionedOverrides(params: {
|
|
803
|
+
export declare function applyVersionedOverrides(params: {
|
|
577
804
|
packageName: string;
|
|
578
805
|
versionedOverrides: Record<string, string>;
|
|
579
806
|
workDir: string;
|
|
@@ -587,7 +814,7 @@ declare function applyVersionedOverrides(params: {
|
|
|
587
814
|
* extractPrefix('4.17.20') // ''
|
|
588
815
|
* extractPrefix('*') // '^' (默认)
|
|
589
816
|
*/
|
|
590
|
-
declare function extractPrefix(version: string): string;
|
|
817
|
+
export declare function extractPrefix(version: string): string;
|
|
591
818
|
/**
|
|
592
819
|
* 检测版本声明是否包含包管理器协议前缀
|
|
593
820
|
* (`workspace:` / `catalog:` / `link:` / `file:` / `npm:` / `github:` /
|
|
@@ -607,7 +834,7 @@ declare function extractPrefix(version: string): string;
|
|
|
607
834
|
* isNonSemverDeclaration('gitlab:...') // true
|
|
608
835
|
* isNonSemverDeclaration('https://...tgz') // true
|
|
609
836
|
*/
|
|
610
|
-
declare function isNonSemverDeclaration(version: string): boolean;
|
|
837
|
+
export declare function isNonSemverDeclaration(version: string): boolean;
|
|
611
838
|
/**
|
|
612
839
|
* 从版本声明中提取主版本号(major)。
|
|
613
840
|
* 去除前缀后匹配第一个 semver 段。
|
|
@@ -618,7 +845,7 @@ declare function isNonSemverDeclaration(version: string): boolean;
|
|
|
618
845
|
* parseMajorVersion('1.2.3') // 1
|
|
619
846
|
* parseMajorVersion('*') // -1
|
|
620
847
|
*/
|
|
621
|
-
declare function parseMajorVersion(version: string): number;
|
|
848
|
+
export declare function parseMajorVersion(version: string): number;
|
|
622
849
|
/**
|
|
623
850
|
* 比较两个语义化版本(`x.y.z`,可选 pre-release 后缀)。
|
|
624
851
|
*
|
|
@@ -631,16 +858,16 @@ declare function parseMajorVersion(version: string): number;
|
|
|
631
858
|
* compareSemver('5.4.20', '6.4.3') // -1
|
|
632
859
|
* compareSemver('1.2.3', '1.2.3') // 0
|
|
633
860
|
*/
|
|
634
|
-
declare function compareSemver(a: string, b: string): number;
|
|
861
|
+
export declare function compareSemver(a: string, b: string): number;
|
|
635
862
|
/**
|
|
636
863
|
* 在 `package.json` 的 `dependencies` / `devDependencies` / `optionalDependencies` 中按顺序查找包。
|
|
637
864
|
*/
|
|
638
|
-
declare function findDependencyVersion(pkg: PackageJson, packageName: string): DependencyInfo | null;
|
|
865
|
+
export declare function findDependencyVersion(pkg: PackageJson, packageName: string): DependencyInfo | null;
|
|
639
866
|
/**
|
|
640
867
|
* 确保 `package.json` 中存在 `pnpm.overrides` 对象,若不存在则创建。
|
|
641
868
|
* 返回 `overrides` 对象的引用,调用方可直接写入。
|
|
642
869
|
*/
|
|
643
|
-
declare function ensurePnpmOverrides(pkg: PackageJson): Record<string, string>;
|
|
870
|
+
export declare function ensurePnpmOverrides(pkg: PackageJson): Record<string, string>;
|
|
644
871
|
/**
|
|
645
872
|
* 从 `pnpm-lock.yaml` 中读取指定包的**所有**锁定版本实例。
|
|
646
873
|
*
|
|
@@ -654,7 +881,7 @@ declare function ensurePnpmOverrides(pkg: PackageJson): Record<string, string>;
|
|
|
654
881
|
*
|
|
655
882
|
* @returns 去重后的版本列表(如 `['5.4.14', '8.2.0']`),未找到返回 `[]`
|
|
656
883
|
*/
|
|
657
|
-
declare function readLockfileVersions(lockfilePath: string, packageName: string): string[];
|
|
884
|
+
export declare function readLockfileVersions(lockfilePath: string, packageName: string): string[];
|
|
658
885
|
/**
|
|
659
886
|
* 从 `pnpm-lock.yaml` 中读取指定包的当前锁定版本。
|
|
660
887
|
*
|
|
@@ -663,7 +890,7 @@ declare function readLockfileVersions(lockfilePath: string, packageName: string)
|
|
|
663
890
|
*
|
|
664
891
|
* @returns 锁定版本字符串(如 `'5.0.0'`),未找到返回 `null`
|
|
665
892
|
*/
|
|
666
|
-
declare function readLockfileVersion(lockfilePath: string, packageName: string): string | null;
|
|
893
|
+
export declare function readLockfileVersion(lockfilePath: string, packageName: string): string | null;
|
|
667
894
|
/**
|
|
668
895
|
* 读取当前已生效的 pnpm overrides 映射(与写入位置保持一致):
|
|
669
896
|
* - 存在 `pnpm-workspace.yaml` → 读取其中 `overrides` 字段(pnpm v10+ 推荐位置)
|
|
@@ -675,13 +902,13 @@ declare function readLockfileVersion(lockfilePath: string, packageName: string):
|
|
|
675
902
|
*
|
|
676
903
|
* @returns 已有 overrides 映射(key → 版本声明);无配置或解析失败返回 {}
|
|
677
904
|
*/
|
|
678
|
-
declare function readExistingOverrides(workDir: string): Record<string, string>;
|
|
905
|
+
export declare function readExistingOverrides(workDir: string): Record<string, string>;
|
|
679
906
|
/**
|
|
680
907
|
* 探测当前 pnpm 大版本(pnpm v10+ 对无 `pnpm-workspace.yaml` 的项目
|
|
681
908
|
* 可能不读取 `package.json#pnpm.overrides`,写入会"假成功")。
|
|
682
909
|
* 探测失败(pnpm 不可用 / 输出异常)返回 null,调用方降级为不告警。
|
|
683
910
|
*/
|
|
684
|
-
declare function detectPnpmMajor(workDir: string): number | null;
|
|
911
|
+
export declare function detectPnpmMajor(workDir: string): number | null;
|
|
685
912
|
/**
|
|
686
913
|
* 跨线修复判定(2026-08-06 复盘 PR #28)。
|
|
687
914
|
*
|
|
@@ -695,12 +922,12 @@ declare function detectPnpmMajor(workDir: string): number | null;
|
|
|
695
922
|
* lockfile 中无该包实例(versions 为空)时返回 false——"无实例"场景由
|
|
696
923
|
* partitionSubmanifestAlerts 的常规跳过逻辑处理,避免重复计数。
|
|
697
924
|
*/
|
|
698
|
-
declare function isCrossMajorFixRequired(lockfilePath: string, alert: NormalizedSecurityAlert): boolean;
|
|
925
|
+
export declare function isCrossMajorFixRequired(lockfilePath: string, alert: NormalizedSecurityAlert): boolean;
|
|
699
926
|
//#endregion
|
|
700
927
|
//#region src/fixers/pnpm/index.d.ts
|
|
701
|
-
type LockfileFailureCategory = 'LOCKFILE_NOT_FOUND' | 'MANIFEST_MISMATCH' | 'LOCKFILE_VERSION_MISMATCH' | 'CORRUPTED_LOCKFILE' | 'CREDENTIAL_ERROR' | 'RESOLVE_ERROR' | 'UNKNOWN';
|
|
702
|
-
type RepairStrategy = 'REGENERATE' | 'FIX_ENTRIES' | 'PIN_TOOLCHAIN' | 'REINSTALL' | 'SKIP';
|
|
703
|
-
interface RepairLockfileParams {
|
|
928
|
+
export type LockfileFailureCategory = 'LOCKFILE_NOT_FOUND' | 'MANIFEST_MISMATCH' | 'LOCKFILE_VERSION_MISMATCH' | 'CORRUPTED_LOCKFILE' | 'CREDENTIAL_ERROR' | 'RESOLVE_ERROR' | 'MINIMUM_RELEASE_AGE' | 'UNKNOWN';
|
|
929
|
+
export type RepairStrategy = 'REGENERATE' | 'FIX_ENTRIES' | 'PIN_TOOLCHAIN' | 'REINSTALL' | 'SKIP';
|
|
930
|
+
export interface RepairLockfileParams {
|
|
704
931
|
/** 工作目录(必须包含 package.json 和 pnpm-lock.yaml) */
|
|
705
932
|
workDir: string;
|
|
706
933
|
/** 可选:期望的 pnpm 版本(优先于 packageManager 字段) */
|
|
@@ -708,7 +935,7 @@ interface RepairLockfileParams {
|
|
|
708
935
|
pnpmVersion?: string;
|
|
709
936
|
};
|
|
710
937
|
}
|
|
711
|
-
interface LockfileDiff {
|
|
938
|
+
export interface LockfileDiff {
|
|
712
939
|
/** lockfile 行数变化(正=增加) */
|
|
713
940
|
linesChanged: number;
|
|
714
941
|
/** packages 条数变化(正=增加) */
|
|
@@ -716,14 +943,14 @@ interface LockfileDiff {
|
|
|
716
943
|
/** 简要文字摘要 */
|
|
717
944
|
summary: string;
|
|
718
945
|
}
|
|
719
|
-
interface RepairAttempt {
|
|
946
|
+
export interface RepairAttempt {
|
|
720
947
|
strategy: RepairStrategy;
|
|
721
948
|
command: string;
|
|
722
949
|
success: boolean;
|
|
723
950
|
error?: string;
|
|
724
951
|
durationMs: number;
|
|
725
952
|
}
|
|
726
|
-
interface LockfileRepairResult {
|
|
953
|
+
export interface LockfileRepairResult {
|
|
727
954
|
success: boolean;
|
|
728
955
|
failureCategory?: LockfileFailureCategory;
|
|
729
956
|
failureDetail?: string;
|
|
@@ -744,21 +971,21 @@ interface ClassificationResult {
|
|
|
744
971
|
* 执行 `pnpm i --frozen-lockfile` 并解析失败分类。
|
|
745
972
|
* 成功时返回 { ok: true }。
|
|
746
973
|
*/
|
|
747
|
-
declare function classifyLockfileFailure(workDir: string): ClassificationResult;
|
|
974
|
+
export declare function classifyLockfileFailure(workDir: string): ClassificationResult;
|
|
748
975
|
/** 从 lockfile 内容提取 `lockfileVersion` 字段值(如 `9.0`);缺失返回 null。 */
|
|
749
|
-
declare function extractLockfileVersion(content: string): string | null;
|
|
976
|
+
export declare function extractLockfileVersion(content: string): string | null;
|
|
750
977
|
/**
|
|
751
978
|
* 比较修复前后 lockfile,返回行数与包数量变化摘要。
|
|
752
979
|
*/
|
|
753
|
-
declare function computeLockfileDiff(beforePath: string, afterPath: string): LockfileDiff;
|
|
980
|
+
export declare function computeLockfileDiff(beforePath: string, afterPath: string): LockfileDiff;
|
|
754
981
|
/** 校验 pnpm 版本格式是否合法(非法返回 false,调用方回退裸命令/报错)。 */
|
|
755
|
-
declare function isValidPnpmVersion(version: string | undefined | null): version is string;
|
|
982
|
+
export declare function isValidPnpmVersion(version: string | undefined | null): version is string;
|
|
756
983
|
/**
|
|
757
984
|
* 从 package.json 的 `packageManager` 字段解析 pnpm 版本。
|
|
758
985
|
* 优先级: toolchain.pnpmVersion > packageManager > null
|
|
759
986
|
* 非法 toolchain 版本 → 回退 packageManager;两者都非法/缺失 → null(裸命令兜底)。
|
|
760
987
|
*/
|
|
761
|
-
declare function resolvePnpmVersion(workDir: string, toolchain?: {
|
|
988
|
+
export declare function resolvePnpmVersion(workDir: string, toolchain?: {
|
|
762
989
|
pnpmVersion?: string;
|
|
763
990
|
}): string | null;
|
|
764
991
|
/**
|
|
@@ -774,10 +1001,10 @@ declare function resolvePnpmVersion(workDir: string, toolchain?: {
|
|
|
774
1001
|
* - 验证失败 → 继续下一个策略
|
|
775
1002
|
* 5. 所有策略失败 → 回滚 lockfile、返回失败结果
|
|
776
1003
|
*/
|
|
777
|
-
declare function repairLockfile(params: RepairLockfileParams): LockfileRepairResult;
|
|
1004
|
+
export declare function repairLockfile(params: RepairLockfileParams): LockfileRepairResult;
|
|
778
1005
|
//#endregion
|
|
779
1006
|
//#region src/fixers/code-scanning/index.d.ts
|
|
780
|
-
interface ApplyCodeScanningFixParams {
|
|
1007
|
+
export interface ApplyCodeScanningFixParams {
|
|
781
1008
|
/** 工作目录(告警 manifestPath 为相对路径,resolve 后读取) */
|
|
782
1009
|
workDir: string;
|
|
783
1010
|
alert: NormalizedSecurityAlert;
|
|
@@ -790,8 +1017,8 @@ interface ApplyCodeScanningFixParams {
|
|
|
790
1017
|
* 仅处理 `source === 'code-scanning'` 且 `alertClass === 'auto-fixable'` 的告警;
|
|
791
1018
|
* 其余返回 `null`(调用方不生成动作记录)。
|
|
792
1019
|
*/
|
|
793
|
-
declare function applyCodeScanningFix(params: ApplyCodeScanningFixParams): FixAction | null;
|
|
794
|
-
interface SourceFileSnapshot {
|
|
1020
|
+
export declare function applyCodeScanningFix(params: ApplyCodeScanningFixParams): FixAction | null;
|
|
1021
|
+
export interface SourceFileSnapshot {
|
|
795
1022
|
/** 相对路径(告警 manifestPath) */
|
|
796
1023
|
path: string;
|
|
797
1024
|
/** 快照时文件是否存在 */
|
|
@@ -803,12 +1030,12 @@ interface SourceFileSnapshot {
|
|
|
803
1030
|
* 快照单个源码文件(修复前调用;文件不存在时记录 existed:false)。
|
|
804
1031
|
* 路径越界返回 null;读取失败返回 null(调用方按失败处理,不中断主流程)。
|
|
805
1032
|
*/
|
|
806
|
-
declare function snapshotSourceFile(workDir: string, relativePath: string): SourceFileSnapshot | null;
|
|
1033
|
+
export declare function snapshotSourceFile(workDir: string, relativePath: string): SourceFileSnapshot | null;
|
|
807
1034
|
/**
|
|
808
1035
|
* 恢复源码文件(验证失败回滚;原不存在的文件将被删除)。
|
|
809
1036
|
* 返回是否恢复成功(写回/删除失败返回 false,调用方在 action.error 记录"可能残留")。
|
|
810
1037
|
*/
|
|
811
|
-
declare function restoreSourceFile(workDir: string, snapshot: SourceFileSnapshot): boolean;
|
|
1038
|
+
export declare function restoreSourceFile(workDir: string, snapshot: SourceFileSnapshot): boolean;
|
|
812
1039
|
/**
|
|
813
1040
|
* 将相对路径解析到工作目录内(防 `../` 与绝对路径逃逸;防符号链接逃逸)。
|
|
814
1041
|
* 返回 null 表示越界(调用方拒绝处理)。
|
|
@@ -819,25 +1046,25 @@ declare function restoreSourceFile(workDir: string, snapshot: SourceFileSnapshot
|
|
|
819
1046
|
* realpath 内;不存在 → 逐级向上对最近存在的父目录做 realpath 校验。
|
|
820
1047
|
* 返回**真实路径**(后续读写走真实路径,避免再次经过 symlink)。
|
|
821
1048
|
*/
|
|
822
|
-
declare function resolveWithinWorkDir(workDir: string, relativePath: string): string | null;
|
|
1049
|
+
export declare function resolveWithinWorkDir(workDir: string, relativePath: string): string | null;
|
|
823
1050
|
//#endregion
|
|
824
1051
|
//#region src/config/index.d.ts
|
|
825
|
-
declare const RUNTIME_MODES: readonly ["report-only", "fix", "fix-and-pr", "cleanup-branches"];
|
|
826
|
-
declare const SEVERITY_THRESHOLDS: readonly ["critical", "high", "medium", "all"];
|
|
827
|
-
declare const ALERT_SOURCES: readonly AlertSourceKind[];
|
|
1052
|
+
export declare const RUNTIME_MODES: readonly ["report-only", "fix", "fix-and-pr", "cleanup-branches"];
|
|
1053
|
+
export declare const SEVERITY_THRESHOLDS: readonly ["critical", "high", "medium", "all"];
|
|
1054
|
+
export declare const ALERT_SOURCES: readonly AlertSourceKind[];
|
|
828
1055
|
/**
|
|
829
1056
|
* 环境变量统一前缀(v0.2 起替代旧项目名遗留的 `AUTO_FIX_GITHUB_SECURITY_`)。
|
|
830
1057
|
* 所有环境变量读取必须经由 {@link readEnv},禁止散落硬编码,防止改名漏网。
|
|
831
1058
|
*/
|
|
832
|
-
declare const ENV_PREFIX = "DEPENDFIX_";
|
|
1059
|
+
export declare const ENV_PREFIX = "DEPENDFIX_";
|
|
833
1060
|
/**
|
|
834
1061
|
* 从统一前缀读取环境变量。
|
|
835
1062
|
* @param env 进程环境
|
|
836
1063
|
* @param name 变量名(不含前缀),如 `'MODE'` → `DEPENDFIX_MODE`
|
|
837
1064
|
*/
|
|
838
|
-
declare function readEnv(env: NodeJS.ProcessEnv, name: string): string | undefined;
|
|
839
|
-
type RuntimeMode = typeof RUNTIME_MODES[number];
|
|
840
|
-
interface RuntimeConfig {
|
|
1065
|
+
export declare function readEnv(env: NodeJS.ProcessEnv, name: string): string | undefined;
|
|
1066
|
+
export type RuntimeMode = typeof RUNTIME_MODES[number];
|
|
1067
|
+
export interface RuntimeConfig {
|
|
841
1068
|
mode: RuntimeMode;
|
|
842
1069
|
severityThreshold: SeverityThreshold;
|
|
843
1070
|
repositories: string[];
|
|
@@ -889,6 +1116,14 @@ interface RuntimeConfig {
|
|
|
889
1116
|
* 需要 token 具备 `security-events: read` 权限(GITHUB_TOKEN 默认具备)。
|
|
890
1117
|
*/
|
|
891
1118
|
codeScanningEnabled: boolean;
|
|
1119
|
+
/**
|
|
1120
|
+
* 是否同时拉取 Code Quality findings(与 Dependabot 并行源;可与 codeScanningEnabled 同开)。
|
|
1121
|
+
* 默认关闭(opt-in,向后兼容);开启后 GitHub 源下 Dependabot + Code Quality
|
|
1122
|
+
* 并行拉取、互不覆盖。Code Quality findings 不可自动修复(首版统一 C 类),
|
|
1123
|
+
* 仅做最小报告接入(不实现 CodeQL 完整语义解析)。
|
|
1124
|
+
* 需要 token 具备 fine-grained `Code quality: read`(classic PAT 需 `repo`/`public_repo`)。
|
|
1125
|
+
*/
|
|
1126
|
+
codeQualityEnabled: boolean;
|
|
892
1127
|
/**
|
|
893
1128
|
* 跨线告警(推荐版本跨大版本)显式授权自动升级(`--allow-major-upgrade`)。
|
|
894
1129
|
*
|
|
@@ -939,6 +1174,11 @@ interface RuntimeConfig {
|
|
|
939
1174
|
* (由策略链 REGENERATE/REINSTALL 兜底)。
|
|
940
1175
|
*/
|
|
941
1176
|
toolchainPnpmVersion?: string;
|
|
1177
|
+
/**
|
|
1178
|
+
* 发现规模上限(`--max-repos` / `DEPENDFIX_MAX_REPOS`):最多保留的仓库数。
|
|
1179
|
+
* 默认 100;设为 0 或负数表示不限制。大 org 场景下防止一次性全量发现。
|
|
1180
|
+
*/
|
|
1181
|
+
maxRepos: number;
|
|
942
1182
|
/**
|
|
943
1183
|
* AI 研判配置(`--ai` 系列参数 / `DEPENDFIX_AI_*` env)。
|
|
944
1184
|
* 默认关闭(opt-in);开启后依赖升级验证失败或 major 升级时触发
|
|
@@ -953,8 +1193,8 @@ interface RuntimeConfig {
|
|
|
953
1193
|
* - `major`:仅 major 升级时触发
|
|
954
1194
|
* - `both`(默认):验证失败 或 major 升级均触发
|
|
955
1195
|
*/
|
|
956
|
-
type AiTriggerKind = 'failure' | 'major' | 'both';
|
|
957
|
-
interface AiOptions {
|
|
1196
|
+
export type AiTriggerKind = 'failure' | 'major' | 'both';
|
|
1197
|
+
export interface AiOptions {
|
|
958
1198
|
/** AI 研判总开关(默认 false,opt-in;dry-run 下不触发) */
|
|
959
1199
|
enabled: boolean;
|
|
960
1200
|
/** 提供商:openai-compatible(默认,DeepSeek 等指定 baseUrl)/ anthropic */
|
|
@@ -979,7 +1219,7 @@ interface AiOptions {
|
|
|
979
1219
|
/** 触发范围(默认 both) */
|
|
980
1220
|
trigger: AiTriggerKind;
|
|
981
1221
|
}
|
|
982
|
-
interface CliConfigOverrides {
|
|
1222
|
+
export interface CliConfigOverrides {
|
|
983
1223
|
mode?: RuntimeMode;
|
|
984
1224
|
severityThreshold?: SeverityThreshold;
|
|
985
1225
|
repositories?: string[];
|
|
@@ -1007,6 +1247,8 @@ interface CliConfigOverrides {
|
|
|
1007
1247
|
alertSource?: AlertSourceKind;
|
|
1008
1248
|
/** 是否同时拉取 Code Scanning alerts(默认 false) */
|
|
1009
1249
|
codeScanningEnabled?: boolean;
|
|
1250
|
+
/** 是否同时拉取 Code Quality findings(默认 false) */
|
|
1251
|
+
codeQualityEnabled?: boolean;
|
|
1010
1252
|
/**
|
|
1011
1253
|
* 跨线告警显式授权自动升级(仅 CLI `--allow-major-upgrade` 入口,
|
|
1012
1254
|
* 无 env 通道;Action 不支持)。详见 RuntimeConfig.allowMajorUpgrade。
|
|
@@ -1025,6 +1267,11 @@ interface CliConfigOverrides {
|
|
|
1025
1267
|
upgradeGroups?: Record<string, string[]>;
|
|
1026
1268
|
/** lockfile 修复用的 pnpm 版本(工具链固定;缺省从 packageManager 解析) */
|
|
1027
1269
|
toolchainPnpmVersion?: string;
|
|
1270
|
+
/**
|
|
1271
|
+
* 发现规模上限(`--max-repos` / `DEPENDFIX_MAX_REPOS`):最多保留的仓库数。
|
|
1272
|
+
* 默认 100;设为 0 或负数表示不限制。大 org 场景下防止一次性全量发现。
|
|
1273
|
+
*/
|
|
1274
|
+
maxRepos?: number;
|
|
1028
1275
|
/** AI 研判总开关(`--ai`) */
|
|
1029
1276
|
aiEnabled?: boolean;
|
|
1030
1277
|
/** AI 提供商(`--ai-provider`:openai-compatible / anthropic) */
|
|
@@ -1049,15 +1296,15 @@ interface CliConfigOverrides {
|
|
|
1049
1296
|
*/
|
|
1050
1297
|
history?: string;
|
|
1051
1298
|
}
|
|
1052
|
-
interface ResolveRuntimeConfigOptions {
|
|
1299
|
+
export interface ResolveRuntimeConfigOptions {
|
|
1053
1300
|
env?: NodeJS.ProcessEnv;
|
|
1054
1301
|
cliOverrides?: CliConfigOverrides;
|
|
1055
1302
|
/** 工作目录,用于从 git remote 推断仓库名(默认 `process.cwd()`) */
|
|
1056
1303
|
workDir?: string;
|
|
1057
1304
|
}
|
|
1058
|
-
declare const DEFAULT_RUNTIME_CONFIG: Omit<RuntimeConfig, 'githubToken' | 'repositories' | 'dryRun' | 'createPullRequest' | 'commit' | 'cleanupBranches' | 'cleanupBranchesAuto'>;
|
|
1059
|
-
declare function readEnvConfig(env?: NodeJS.ProcessEnv): CliConfigOverrides;
|
|
1060
|
-
declare function resolveRuntimeConfig(options?: ResolveRuntimeConfigOptions): RuntimeConfig;
|
|
1305
|
+
export declare const DEFAULT_RUNTIME_CONFIG: Omit<RuntimeConfig, 'githubToken' | 'repositories' | 'dryRun' | 'createPullRequest' | 'commit' | 'cleanupBranches' | 'cleanupBranchesAuto'>;
|
|
1306
|
+
export declare function readEnvConfig(env?: NodeJS.ProcessEnv): CliConfigOverrides;
|
|
1307
|
+
export declare function resolveRuntimeConfig(options?: ResolveRuntimeConfigOptions): RuntimeConfig;
|
|
1061
1308
|
/**
|
|
1062
1309
|
* 从 git remote origin 推断 owner/repo。
|
|
1063
1310
|
*
|
|
@@ -1068,10 +1315,10 @@ declare function resolveRuntimeConfig(options?: ResolveRuntimeConfigOptions): Ru
|
|
|
1068
1315
|
*
|
|
1069
1316
|
* @returns `owner/repo` 或 `null`(非 GitHub / 无 origin)
|
|
1070
1317
|
*/
|
|
1071
|
-
declare function inferRepoFromGitRemote(workDir: string): string | null;
|
|
1318
|
+
export declare function inferRepoFromGitRemote(workDir: string): string | null;
|
|
1072
1319
|
//#endregion
|
|
1073
1320
|
//#region src/report/archiver.d.ts
|
|
1074
|
-
interface ArchiveRepoStats {
|
|
1321
|
+
export interface ArchiveRepoStats {
|
|
1075
1322
|
repository: string;
|
|
1076
1323
|
alertsCount: number;
|
|
1077
1324
|
fixable: number;
|
|
@@ -1081,7 +1328,7 @@ interface ArchiveRepoStats {
|
|
|
1081
1328
|
durationMs: number;
|
|
1082
1329
|
}
|
|
1083
1330
|
/** index.json 单条趋势记录(字段与 RunSummary/RepositoryResult 口径一致)。 */
|
|
1084
|
-
interface ArchiveRunEntry {
|
|
1331
|
+
export interface ArchiveRunEntry {
|
|
1085
1332
|
runId: string;
|
|
1086
1333
|
startedAt: string;
|
|
1087
1334
|
/** 本次运行总时长(finishedAt - startedAt,毫秒) */
|
|
@@ -1092,10 +1339,10 @@ interface ArchiveRunEntry {
|
|
|
1092
1339
|
/** 按仓库统计(趋势基础字段) */
|
|
1093
1340
|
repoStats: ArchiveRepoStats[];
|
|
1094
1341
|
}
|
|
1095
|
-
interface ArchiveIndex {
|
|
1342
|
+
export interface ArchiveIndex {
|
|
1096
1343
|
runs: ArchiveRunEntry[];
|
|
1097
1344
|
}
|
|
1098
|
-
interface ArchiveResult {
|
|
1345
|
+
export interface ArchiveResult {
|
|
1099
1346
|
/** 汇总 json 路径 */
|
|
1100
1347
|
summaryJsonPath: string;
|
|
1101
1348
|
/** 单仓库报告文件路径列表 */
|
|
@@ -1114,14 +1361,14 @@ interface ArchiveResult {
|
|
|
1114
1361
|
* 可靠性:index.json 采用临时文件 + 原子 rename 写入(并发/中断安全);
|
|
1115
1362
|
* 解析失败的损坏索引先备份为 `index.json.corrupt-{ts}.bak` 再重建,历史不静默丢失。
|
|
1116
1363
|
*/
|
|
1117
|
-
declare function writeArchive(runResult: RunResult, outputDir?: string): ArchiveResult;
|
|
1364
|
+
export declare function writeArchive(runResult: RunResult, outputDir?: string): ArchiveResult;
|
|
1118
1365
|
/** 读取归档索引(不存在时返回空索引;条目级字段兜底防旧版/手写索引形状异常)。 */
|
|
1119
|
-
declare function readArchiveIndex(outputDir?: string): ArchiveIndex;
|
|
1366
|
+
export declare function readArchiveIndex(outputDir?: string): ArchiveIndex;
|
|
1120
1367
|
/**
|
|
1121
1368
|
* 查询某仓库的历史运行摘要(倒序时间:最新在前)。
|
|
1122
1369
|
* 仅返回包含该仓库的运行;无结果返回 []。
|
|
1123
1370
|
*/
|
|
1124
|
-
declare function queryRepoHistory(repo: string, outputDir?: string): ArchiveRunEntry[];
|
|
1371
|
+
export declare function queryRepoHistory(repo: string, outputDir?: string): ArchiveRunEntry[];
|
|
1125
1372
|
//#endregion
|
|
1126
1373
|
//#region src/report/history.d.ts
|
|
1127
1374
|
/**
|
|
@@ -1133,14 +1380,14 @@ declare function queryRepoHistory(repo: string, outputDir?: string): ArchiveRunE
|
|
|
1133
1380
|
* 行格式:`YYYY-MM-DD HH:mm:ss 告警 N / 修复 N / 失败 N 时长 Xs runId=...`
|
|
1134
1381
|
* 无历史时返回提示行(非空,调用方直接打印)。
|
|
1135
1382
|
*/
|
|
1136
|
-
declare function formatHistory(entries: ArchiveRunEntry[], repo: string): string;
|
|
1383
|
+
export declare function formatHistory(entries: ArchiveRunEntry[], repo: string): string;
|
|
1137
1384
|
//#endregion
|
|
1138
1385
|
//#region src/multirepo/scheduler.d.ts
|
|
1139
1386
|
/** 并发上限(1-16,配置校验范围) */
|
|
1140
|
-
declare const MAX_CONCURRENCY_LIMIT = 16;
|
|
1387
|
+
export declare const MAX_CONCURRENCY_LIMIT = 16;
|
|
1141
1388
|
/** 默认并发(保守:行为与现状一致,逐仓库串行) */
|
|
1142
|
-
declare const DEFAULT_CONCURRENCY = 1;
|
|
1143
|
-
interface ConcurrencySchedulerOptions<T> {
|
|
1389
|
+
export declare const DEFAULT_CONCURRENCY = 1;
|
|
1390
|
+
export interface ConcurrencySchedulerOptions<T> {
|
|
1144
1391
|
items: T[];
|
|
1145
1392
|
/** 并发窗口(1-16) */
|
|
1146
1393
|
concurrency: number;
|
|
@@ -1162,9 +1409,16 @@ interface ConcurrencySchedulerOptions<T> {
|
|
|
1162
1409
|
* onError 兜底,保证"单仓库失败不中断整体")
|
|
1163
1410
|
* - 任务完成顺序不保证(并发下与输入顺序无关),但每个任务都会被调度
|
|
1164
1411
|
*/
|
|
1165
|
-
declare function runWithConcurrency<T>(options: ConcurrencySchedulerOptions<T>): Promise<void>;
|
|
1412
|
+
export declare function runWithConcurrency<T>(options: ConcurrencySchedulerOptions<T>): Promise<void>;
|
|
1166
1413
|
/** 校验并发值是否在 1-16 范围内(config 层调用,抛 AppError)。 */
|
|
1167
|
-
declare function isValidConcurrency(value: number): boolean;
|
|
1414
|
+
export declare function isValidConcurrency(value: number): boolean;
|
|
1415
|
+
//#endregion
|
|
1416
|
+
//#region src/app/branch-cleanup.d.ts
|
|
1417
|
+
/**
|
|
1418
|
+
* 关闭被取代的旧 PR 并回收其 head 分支(supersede 流程)。
|
|
1419
|
+
* 关闭失败记录错误;分支删除失败仅 warn(家务活 best-effort,不触发非零退出)。
|
|
1420
|
+
*/
|
|
1421
|
+
export declare function closeSupersededPRs(ctx: Pick<AppContext, 'logger' | 'allErrors'>, client: Octokit, owner: string, repo: string, supersedePRs: DependfixOpenPR[]): Promise<void>;
|
|
1168
1422
|
//#endregion
|
|
1169
1423
|
//#region src/ai/usage.d.ts
|
|
1170
1424
|
interface AiUsage {
|
|
@@ -1180,9 +1434,9 @@ interface AiUsage {
|
|
|
1180
1434
|
* 估算单次调用成本(USD)。
|
|
1181
1435
|
* 模型不在单价表返回 undefined(不估算,避免误导)。
|
|
1182
1436
|
*/
|
|
1183
|
-
declare function estimateCostUsd(model: string, inputTokens: number, outputTokens: number): number | undefined;
|
|
1437
|
+
export declare function estimateCostUsd(model: string, inputTokens: number, outputTokens: number): number | undefined;
|
|
1184
1438
|
/** 聚合多次 AI 调用的 token 消耗(run 级)。 */
|
|
1185
|
-
declare class AiUsageTracker {
|
|
1439
|
+
export declare class AiUsageTracker {
|
|
1186
1440
|
private calls;
|
|
1187
1441
|
private inputTokens;
|
|
1188
1442
|
private outputTokens;
|
|
@@ -1214,6 +1468,14 @@ interface AppContext {
|
|
|
1214
1468
|
startedAt: string;
|
|
1215
1469
|
finishedAt: string;
|
|
1216
1470
|
}
|
|
1471
|
+
/**
|
|
1472
|
+
* 按动作构成生成 PR 标题(收尾审查遗留修复:cs-only 修复不再误标 "N upgrades",
|
|
1473
|
+
* lockfile-only 不再出现 "0 upgrades")。
|
|
1474
|
+
* - 依赖升级 + code-scanning 修复分别计数;均为 0 时(lockfile-only)中性标题。
|
|
1475
|
+
* - ⚠️ 不变式:`upgrades = alertsFixed - codeFixes` 依赖 computeSummary 与
|
|
1476
|
+
* codeFixes 过滤条件一致(均 success && !noOp);任一侧口径变更必须同步。
|
|
1477
|
+
*/
|
|
1478
|
+
export declare function buildPrTitle(summary: Pick<RunSummary, 'alertsFixed'>, actions: FixAction[]): string;
|
|
1217
1479
|
//#endregion
|
|
1218
1480
|
//#region src/helpers/index.d.ts
|
|
1219
1481
|
/**
|
|
@@ -1226,7 +1488,7 @@ interface AppContext {
|
|
|
1226
1488
|
* @param alerts 已过滤出 fixable && recommendedVersion 非空的告警
|
|
1227
1489
|
* @returns 每包仅一条的代表告警
|
|
1228
1490
|
*/
|
|
1229
|
-
declare function dedupeFixableAlerts(alerts: NormalizedSecurityAlert[]): NormalizedSecurityAlert[];
|
|
1491
|
+
export declare function dedupeFixableAlerts(alerts: NormalizedSecurityAlert[]): NormalizedSecurityAlert[];
|
|
1230
1492
|
/**
|
|
1231
1493
|
* 读取修复涉及的关键文件快照(逐包回滚基线)。
|
|
1232
1494
|
*
|
|
@@ -1235,23 +1497,27 @@ declare function dedupeFixableAlerts(alerts: NormalizedSecurityAlert[]): Normali
|
|
|
1235
1497
|
* 用于成员级修复将成员 manifest 纳入回滚基线。
|
|
1236
1498
|
* 用于逐包升级验证失败时精确回滚该包产生的改动,而不影响此前已成功的包。
|
|
1237
1499
|
*/
|
|
1238
|
-
declare function snapshotTrackedFiles(workDir: string, extraPaths?: string[]): Record<string, string | null>;
|
|
1500
|
+
export declare function snapshotTrackedFiles(workDir: string, extraPaths?: string[]): Record<string, string | null>;
|
|
1239
1501
|
/**
|
|
1240
1502
|
* 恢复文件快照(逐包回滚)。原不存在的文件将被删除。
|
|
1241
1503
|
*/
|
|
1242
|
-
declare function restoreTrackedFiles(workDir: string, snapshot: Record<string, string | null>): void;
|
|
1504
|
+
export declare function restoreTrackedFiles(workDir: string, snapshot: Record<string, string | null>): void;
|
|
1243
1505
|
/**
|
|
1244
|
-
*
|
|
1506
|
+
* 快速验证(逐包):运行验证命令序列。
|
|
1507
|
+
*
|
|
1508
|
+
* 有自定义命令时执行完整序列(含 install + setup + lint + build),
|
|
1509
|
+
* 否则仅运行 `pnpm lint`(脚本存在时)。
|
|
1245
1510
|
*
|
|
1246
|
-
*
|
|
1247
|
-
* lint
|
|
1248
|
-
*
|
|
1511
|
+
* 设计决策(run 33946113272 复盘):旧版仅跑 `pnpm lint`,但 Nuxt 等框架
|
|
1512
|
+
* 项目 lint 依赖 `nuxt prepare` 生成的 `.nuxt/tsconfig.json`——无 prepare
|
|
1513
|
+
* 步骤会导致 ESLint OOM。自定义命令已含 prepare,走完整序列可避免此问题;
|
|
1514
|
+
* `pnpm install` 在 node_modules 已就绪时近乎空操作,性能影响可忽略。
|
|
1249
1515
|
*/
|
|
1250
|
-
declare function quickVerifyProject(ctx: Pick<AppContext, 'logger' | 'workDir'>, repo: string): Promise<boolean>;
|
|
1516
|
+
export declare function quickVerifyProject(ctx: Pick<AppContext, 'logger' | 'workDir' | 'customCommands'>, repo: string): Promise<boolean>;
|
|
1251
1517
|
/**
|
|
1252
1518
|
* 成员级可修复告警条目:告警 + 所属成员目录(相对 workDir,如 `packages/web`)。
|
|
1253
1519
|
*/
|
|
1254
|
-
interface MemberManifestAlert {
|
|
1520
|
+
export interface MemberManifestAlert {
|
|
1255
1521
|
alert: NormalizedSecurityAlert;
|
|
1256
1522
|
/** 成员目录(相对 workDir,如 `packages/web`) */
|
|
1257
1523
|
manifestDir: string;
|
|
@@ -1259,7 +1525,7 @@ interface MemberManifestAlert {
|
|
|
1259
1525
|
/**
|
|
1260
1526
|
* 告警分区结果:根 manifest / 成员 manifest(可自动修复)/ 其他(人工)。
|
|
1261
1527
|
*/
|
|
1262
|
-
interface SubmanifestPartition {
|
|
1528
|
+
export interface SubmanifestPartition {
|
|
1263
1529
|
root: NormalizedSecurityAlert[];
|
|
1264
1530
|
member: MemberManifestAlert[];
|
|
1265
1531
|
sub: NormalizedSecurityAlert[];
|
|
@@ -1291,7 +1557,7 @@ interface SubmanifestPartition {
|
|
|
1291
1557
|
* - 其余 → sub(单根模型无法安全修 / 多版本共存 / 降级风险 / 跨线 / 非成员路径,
|
|
1292
1558
|
* 需人工处理)
|
|
1293
1559
|
*/
|
|
1294
|
-
declare function partitionSubmanifestAlerts(alerts: NormalizedSecurityAlert[], workDir: string): SubmanifestPartition;
|
|
1560
|
+
export declare function partitionSubmanifestAlerts(alerts: NormalizedSecurityAlert[], workDir: string): SubmanifestPartition;
|
|
1295
1561
|
/**
|
|
1296
1562
|
* 判断包是否为**根** `package.json` 的直接依赖(仅查根声明的
|
|
1297
1563
|
* dependencies / devDependencies / optionalDependencies)。
|
|
@@ -1300,19 +1566,19 @@ declare function partitionSubmanifestAlerts(alerts: NormalizedSecurityAlert[], w
|
|
|
1300
1566
|
* 根 manifest,跨线升级准入必须与修复器能力对齐——仅成员声明的包(root 未声明)
|
|
1301
1567
|
* 进入跨线链路必然失败,维持人工处理。
|
|
1302
1568
|
*/
|
|
1303
|
-
declare function isRootDirectDependency(workDir: string, packageName: string): boolean;
|
|
1569
|
+
export declare function isRootDirectDependency(workDir: string, packageName: string): boolean;
|
|
1304
1570
|
//#endregion
|
|
1305
1571
|
//#region src/grouping/index.d.ts
|
|
1306
1572
|
/** 分组来源(决定分组优先级与命名语义) */
|
|
1307
|
-
type GroupSource = 'explicit' | 'dependabot' | 'types' | 'scope' | 'prefix' | 'single';
|
|
1308
|
-
interface DependencyGroup {
|
|
1573
|
+
export type GroupSource = 'explicit' | 'dependabot' | 'types' | 'scope' | 'prefix' | 'single';
|
|
1574
|
+
export interface DependencyGroup {
|
|
1309
1575
|
/** 组名(日志与统计用) */
|
|
1310
1576
|
name: string;
|
|
1311
1577
|
/** 组内包名(保持输入顺序) */
|
|
1312
1578
|
packages: string[];
|
|
1313
1579
|
source: GroupSource;
|
|
1314
1580
|
}
|
|
1315
|
-
interface GroupingResult {
|
|
1581
|
+
export interface GroupingResult {
|
|
1316
1582
|
/** 有序分组(处理顺序即升级执行顺序) */
|
|
1317
1583
|
groups: DependencyGroup[];
|
|
1318
1584
|
/**
|
|
@@ -1321,7 +1587,7 @@ interface GroupingResult {
|
|
|
1321
1587
|
*/
|
|
1322
1588
|
cleanupCandidates: string[];
|
|
1323
1589
|
}
|
|
1324
|
-
interface GroupingOptions {
|
|
1590
|
+
export interface GroupingOptions {
|
|
1325
1591
|
/** 工作目录(读取 package.json / pnpm-lock.yaml / .github/dependabot.yml) */
|
|
1326
1592
|
workDir: string;
|
|
1327
1593
|
/** 用户显式分组:组名 -> 包列表(最高优先级,覆盖自动分组) */
|
|
@@ -1352,7 +1618,7 @@ interface PackageJsonLike {
|
|
|
1352
1618
|
* 裸 `*`(全匹配)视为不匹配,防止误分组(设计稿 §3)。
|
|
1353
1619
|
* 中间通配(`foo*bar`)不支持。
|
|
1354
1620
|
*/
|
|
1355
|
-
declare function matchesPattern(packageName: string, pattern: string): boolean;
|
|
1621
|
+
export declare function matchesPattern(packageName: string, pattern: string): boolean;
|
|
1356
1622
|
/**
|
|
1357
1623
|
* 解析 `.github/dependabot.yml`(或 `.yaml` 变体)中 npm ecosystem 的 `groups` → patterns。
|
|
1358
1624
|
*
|
|
@@ -1360,7 +1626,7 @@ declare function matchesPattern(packageName: string, pattern: string): boolean;
|
|
|
1360
1626
|
* 解析为 dependabot 语法子集:仅 `groups.<name>.patterns`;`exclude-patterns` /
|
|
1361
1627
|
* `dependency-type` / `update-types` 忽略(设计稿 §3)。
|
|
1362
1628
|
*/
|
|
1363
|
-
declare function parseDependabotGroups(workDir: string): Record<string, string[]>;
|
|
1629
|
+
export declare function parseDependabotGroups(workDir: string): Record<string, string[]>;
|
|
1364
1630
|
/**
|
|
1365
1631
|
* 从 `@types/x` 提取主包名。
|
|
1366
1632
|
*
|
|
@@ -1371,14 +1637,14 @@ declare function parseDependabotGroups(workDir: string): Record<string, string[]
|
|
|
1371
1637
|
*
|
|
1372
1638
|
* 非 @types 包返回 `null`。
|
|
1373
1639
|
*/
|
|
1374
|
-
declare function extractMainPackage(packageName: string): string | null;
|
|
1640
|
+
export declare function extractMainPackage(packageName: string): string | null;
|
|
1375
1641
|
/**
|
|
1376
1642
|
* 判定 @types 的主包是否仍然存在(任一命中即存在):
|
|
1377
1643
|
* 1. package.json 直接依赖(dependencies / devDependencies / optionalDependencies)
|
|
1378
1644
|
* 2. pnpm.overrides(间接依赖修复场景)
|
|
1379
1645
|
* 3. lockfile 中存在(间接依赖场景)
|
|
1380
1646
|
*/
|
|
1381
|
-
declare function isMainPackagePresent(pkg: PackageJsonLike, lockfilePath: string, mainPackage: string): boolean;
|
|
1647
|
+
export declare function isMainPackagePresent(pkg: PackageJsonLike, lockfilePath: string, mainPackage: string): boolean;
|
|
1382
1648
|
/**
|
|
1383
1649
|
* 构建升级分组(主入口)。
|
|
1384
1650
|
*
|
|
@@ -1392,19 +1658,52 @@ declare function isMainPackagePresent(pkg: PackageJsonLike, lockfilePath: string
|
|
|
1392
1658
|
* 4. 非 @types 单包组
|
|
1393
1659
|
* 5. @types 归并(主包有告警并入其组)/ 独立组 / 清理候选(主包已不存在)
|
|
1394
1660
|
*/
|
|
1395
|
-
declare function buildUpgradeGroups(alerts: NormalizedSecurityAlert[], options: GroupingOptions): GroupingResult;
|
|
1661
|
+
export declare function buildUpgradeGroups(alerts: NormalizedSecurityAlert[], options: GroupingOptions): GroupingResult;
|
|
1662
|
+
//#endregion
|
|
1663
|
+
//#region src/runners/network-audit.d.ts
|
|
1664
|
+
/**
|
|
1665
|
+
* 执行期网络外联审计 + 出站白名单拦截(安全治理:恶意脚本外联回传/下载 payload 的事故溯源与阻断)。
|
|
1666
|
+
*
|
|
1667
|
+
* 捕获面(实证驱动,2026-08-14):
|
|
1668
|
+
* - **命令输出 URL 提取**(主):执行命令 stdout/stderr 中的 http(s) URL——
|
|
1669
|
+
* pnpm install 输出含完整 tarball URL(registry 域名 + 包名 + 版本),
|
|
1670
|
+
* 确定性捕获 pnpm/npm 的 registry 外联(pnpm 11 undici 直连不走代理 env,实证确认)
|
|
1671
|
+
* - **本地拦截代理**(辅):注入 HTTP(S)_PROXY 捕获尊重代理的工具(curl/wget/npm CLI/git http);
|
|
1672
|
+
* 仅当环境无既有代理时注入(覆盖用户代理会破坏其网络行为,稳定性优先);
|
|
1673
|
+
* **deny-by-default**:非白名单域名的 CONNECT/HTTP 请求直接 502 拒绝(不建上游连接),
|
|
1674
|
+
* 记录为违规外联(`violation`);白名单命中才放行(registry/GitHub 默认域 + 可配置扩展)
|
|
1675
|
+
* - 覆盖边界:undici 直连(node fetch/https.request 默认不读代理 env)不在连接级拦截范围——
|
|
1676
|
+
* 命令输出 URL 提取对这类外联提供冗余判定(攻击者绕过代理 env 也会被命中并归类违规)
|
|
1677
|
+
*
|
|
1678
|
+
* 无敏感信息:仅记录方法 + 目标(host/URL),不记录请求体与响应体。
|
|
1679
|
+
*/
|
|
1680
|
+
type NetworkAuditSource = 'proxy' | 'command-output';
|
|
1681
|
+
interface NetworkAuditEntry {
|
|
1682
|
+
/** 记录时间(ISO) */
|
|
1683
|
+
time: string;
|
|
1684
|
+
/** 来源:proxy = 审计代理捕获;command-output = 命令输出 URL 提取 */
|
|
1685
|
+
source: NetworkAuditSource;
|
|
1686
|
+
/** 请求方法(CONNECT / GET / POST / ...) */
|
|
1687
|
+
method: string;
|
|
1688
|
+
/** 外联目标(proxy:host:port;command-output:完整 URL) */
|
|
1689
|
+
target: string;
|
|
1690
|
+
/** deny-by-default 拦截的违规外联标记(白名单校验失败的外联为 true) */
|
|
1691
|
+
violation?: boolean;
|
|
1692
|
+
}
|
|
1396
1693
|
//#endregion
|
|
1397
1694
|
//#region src/runners/verification-runner.d.ts
|
|
1398
1695
|
/**
|
|
1399
1696
|
* 单条命令的执行结果
|
|
1400
1697
|
*/
|
|
1401
|
-
interface CommandResult {
|
|
1698
|
+
export interface CommandResult {
|
|
1402
1699
|
/** 执行的命令文本 */
|
|
1403
1700
|
command: string;
|
|
1404
|
-
/** 退出码(0 =
|
|
1701
|
+
/** 退出码(0 = 成功;-1 = 启动失败或超时被杀) */
|
|
1405
1702
|
exitCode: number;
|
|
1406
1703
|
/** 执行耗时(毫秒) */
|
|
1407
1704
|
durationMs: number;
|
|
1705
|
+
/** 是否因超时被中止(默认 false) */
|
|
1706
|
+
timedOut?: boolean;
|
|
1408
1707
|
/** stdout 摘要(截断到 200 行,已脱敏) */
|
|
1409
1708
|
stdout: string;
|
|
1410
1709
|
/** stderr 摘要(截断到 200 行,已脱敏) */
|
|
@@ -1413,7 +1712,7 @@ interface CommandResult {
|
|
|
1413
1712
|
/**
|
|
1414
1713
|
* 验证执行参数
|
|
1415
1714
|
*/
|
|
1416
|
-
interface VerificationParams {
|
|
1715
|
+
export interface VerificationParams {
|
|
1417
1716
|
/** 工作目录 */
|
|
1418
1717
|
workDir: string;
|
|
1419
1718
|
/**
|
|
@@ -1421,11 +1720,22 @@ interface VerificationParams {
|
|
|
1421
1720
|
* 默认: `pnpm install --frozen-lockfile` → `pnpm lint` → `pnpm build`
|
|
1422
1721
|
*/
|
|
1423
1722
|
commands?: string[];
|
|
1723
|
+
/**
|
|
1724
|
+
* 单命令超时(毫秒),超时中止该命令并终止其进程树。
|
|
1725
|
+
* 默认 10 分钟(恶意死循环脚本超时中止,防长时间占用)。
|
|
1726
|
+
*/
|
|
1727
|
+
commandTimeoutMs?: number;
|
|
1728
|
+
/**
|
|
1729
|
+
* 关闭执行期网络外联审计(默认开启)。
|
|
1730
|
+
* 审计记录命令输出中的外联 URL + 注入本地审计代理捕获尊重代理的工具外联;
|
|
1731
|
+
* 仅当环境无既有代理时注入(覆盖用户代理会破坏其网络行为)。
|
|
1732
|
+
*/
|
|
1733
|
+
networkAuditDisabled?: boolean;
|
|
1424
1734
|
}
|
|
1425
1735
|
/**
|
|
1426
1736
|
* 验证执行结果
|
|
1427
1737
|
*/
|
|
1428
|
-
interface VerificationResult {
|
|
1738
|
+
export interface VerificationResult {
|
|
1429
1739
|
/** 所有命令是否全部成功 */
|
|
1430
1740
|
success: boolean;
|
|
1431
1741
|
/** 每条命令的详细结果 */
|
|
@@ -1434,17 +1744,22 @@ interface VerificationResult {
|
|
|
1434
1744
|
failedCommand?: string;
|
|
1435
1745
|
/** 失败详情(仅 success=false 时填充) */
|
|
1436
1746
|
failure?: string;
|
|
1747
|
+
/** 执行期网络外联记录(审计开启时;空数组 = 无外联或未捕获到) */
|
|
1748
|
+
networkAudit?: NetworkAuditEntry[];
|
|
1749
|
+
/** 非白名单外联违规(deny-by-default 拦截记录;空数组 = 无违规或审计关闭) */
|
|
1750
|
+
networkViolations?: NetworkAuditEntry[];
|
|
1437
1751
|
}
|
|
1438
1752
|
/**
|
|
1439
1753
|
* 压缩验证命令输出为报告可读的摘要(首尾各取若干行,超长中间省略)。
|
|
1440
1754
|
* 完整输出由日志承载;报告保持紧凑,避免 error 字段失控膨胀。
|
|
1441
1755
|
*/
|
|
1442
|
-
declare function summarizeVerificationOutput(output: string): string;
|
|
1756
|
+
export declare function summarizeVerificationOutput(output: string): string;
|
|
1443
1757
|
/**
|
|
1444
1758
|
* 构造失败验证命令的 error 描述:`exit code N — <stdout/stderr 摘要>`。
|
|
1445
|
-
* 无输出时退化为裸 `exit code N
|
|
1759
|
+
* 无输出时退化为裸 `exit code N`;超时命令归类为 `timed out after Xms`。
|
|
1760
|
+
* stdout/stderr 已在 execCommand 中脱敏、截断 200 行。
|
|
1446
1761
|
*/
|
|
1447
|
-
declare function formatVerificationError(cr: CommandResult): string;
|
|
1762
|
+
export declare function formatVerificationError(cr: CommandResult): string;
|
|
1448
1763
|
/**
|
|
1449
1764
|
* 按顺序在工作目录执行命令序列,任一命令失败则停止。
|
|
1450
1765
|
*
|
|
@@ -1456,11 +1771,11 @@ declare function formatVerificationError(cr: CommandResult): string;
|
|
|
1456
1771
|
* }
|
|
1457
1772
|
* ```
|
|
1458
1773
|
*/
|
|
1459
|
-
declare function runVerification(params: VerificationParams): Promise<VerificationResult>;
|
|
1774
|
+
export declare function runVerification(params: VerificationParams): Promise<VerificationResult>;
|
|
1460
1775
|
/**
|
|
1461
1776
|
* 对外暴露以支持单独测试
|
|
1462
1777
|
*/
|
|
1463
|
-
declare function sanitizeOutput(output: string): string;
|
|
1778
|
+
export declare function sanitizeOutput(output: string): string;
|
|
1464
1779
|
//#endregion
|
|
1465
1780
|
//#region src/alerts/pnpm-audit-fetcher.d.ts
|
|
1466
1781
|
/**
|
|
@@ -1473,7 +1788,7 @@ declare function sanitizeOutput(output: string): string;
|
|
|
1473
1788
|
* - repository 由调用方注入(显式 --repo → git remote → local 兜底)
|
|
1474
1789
|
* - audit 自身失败(无 lockfile / pnpm 不可用 / JSON 解析失败)→ 硬失败,绝不静默空跑
|
|
1475
1790
|
*/
|
|
1476
|
-
interface FetchPnpmAuditAlertsParams {
|
|
1791
|
+
export interface FetchPnpmAuditAlertsParams {
|
|
1477
1792
|
/** 扫描工作目录(lockfile 所在目录) */
|
|
1478
1793
|
workDir: string;
|
|
1479
1794
|
/** 注入的仓库标识(owner/repo 或 local 兜底) */
|
|
@@ -1484,7 +1799,7 @@ interface FetchPnpmAuditAlertsParams {
|
|
|
1484
1799
|
*
|
|
1485
1800
|
* @throws AppError('AUDIT_FAILED') — pnpm 不可用 / 无 lockfile / JSON 解析失败
|
|
1486
1801
|
*/
|
|
1487
|
-
declare function fetchPnpmAuditAlerts(params: FetchPnpmAuditAlertsParams): Promise<NormalizedSecurityAlert[]>;
|
|
1802
|
+
export declare function fetchPnpmAuditAlerts(params: FetchPnpmAuditAlertsParams): Promise<NormalizedSecurityAlert[]>;
|
|
1488
1803
|
interface RiskRecord {
|
|
1489
1804
|
advisoryId: string;
|
|
1490
1805
|
packageName: string;
|
|
@@ -1492,18 +1807,26 @@ interface RiskRecord {
|
|
|
1492
1807
|
title: string;
|
|
1493
1808
|
htmlUrl: string;
|
|
1494
1809
|
patchedVersion: string | null;
|
|
1810
|
+
/** GitHub Advisory ID(pnpm audit `advisory.github_advisory_id`,GitHub Advisory Database 收录时) */
|
|
1811
|
+
ghsaId?: string;
|
|
1812
|
+
/** CVE ID 列表(pnpm audit `advisory.cves[]` 字符串数组) */
|
|
1813
|
+
cveIds?: string[];
|
|
1495
1814
|
}
|
|
1496
1815
|
/**
|
|
1497
1816
|
* 解析 pnpm audit 报告(legacy + modern 双格式),按
|
|
1498
1817
|
* `packageName:advisoryId:severity` 去重(保留首个,advisoryId 优先补全)。
|
|
1499
1818
|
*/
|
|
1500
|
-
declare function parseAuditReport(report: unknown): RiskRecord[];
|
|
1819
|
+
export declare function parseAuditReport(report: unknown): RiskRecord[];
|
|
1501
1820
|
/**
|
|
1502
|
-
* advisoryId
|
|
1821
|
+
* advisoryId 的稳定数字哈希(M20 之前使用,M20 后保留以维持向后兼容 `NormalizedSecurityAlert.id: number`)。
|
|
1822
|
+
*
|
|
1503
1823
|
* 取 sha256 前 4 字节完整 uint32(非设计稿的 `% 2^31`:uint32 语义更自然,
|
|
1504
1824
|
* 碰撞概率 ~2^-32/对,12 条告警场景生日界 ~1.6e-8,可忽略)。
|
|
1825
|
+
*
|
|
1826
|
+
* M20 弃用:唯一去重键改为 `upstreamId`,详见 [`normalizeUpstreamId`](../../../core/src/alerts/upstream-id.ts)。
|
|
1827
|
+
* 本函数保留仅为兼容现有 `NormalizedSecurityAlert.id: number` 字段,**不是**平台去重键。
|
|
1505
1828
|
*/
|
|
1506
|
-
declare function hashAdvisoryId(packageName: string, advisoryId: string): number;
|
|
1829
|
+
export declare function hashAdvisoryId(packageName: string, advisoryId: string): number;
|
|
1507
1830
|
//#endregion
|
|
1508
1831
|
//#region src/ai/provider.d.ts
|
|
1509
1832
|
interface AiConfig {
|
|
@@ -1611,10 +1934,10 @@ interface AssessmentContextInput {
|
|
|
1611
1934
|
* maskSecrets('call failed with key sk-abc12345xyz', ['sk-abc12345xyz'])
|
|
1612
1935
|
* // → 'call failed with key sk-a****yz'
|
|
1613
1936
|
*/
|
|
1614
|
-
declare function maskSecrets(text: string, secrets: string[]): string;
|
|
1937
|
+
export declare function maskSecrets(text: string, secrets: string[]): string;
|
|
1615
1938
|
//#endregion
|
|
1616
1939
|
//#region src/ai/index.d.ts
|
|
1617
|
-
interface AssessResult {
|
|
1940
|
+
export interface AssessResult {
|
|
1618
1941
|
/** 结构化研判(降级时为 null,走建议模式) */
|
|
1619
1942
|
assessment: AiAssessment | null;
|
|
1620
1943
|
/**
|
|
@@ -1627,7 +1950,7 @@ interface AssessResult {
|
|
|
1627
1950
|
/** 降级原因(脱敏后的错误消息;成功时为 undefined) */
|
|
1628
1951
|
error?: string;
|
|
1629
1952
|
}
|
|
1630
|
-
interface AssessOptions {
|
|
1953
|
+
export interface AssessOptions {
|
|
1631
1954
|
config: AiConfig;
|
|
1632
1955
|
context: AssessmentContextInput;
|
|
1633
1956
|
/** 注入请求函数(默认全局 fetch;测试用 vi.fn) */
|
|
@@ -1646,10 +1969,18 @@ interface AssessOptions {
|
|
|
1646
1969
|
*
|
|
1647
1970
|
* 降级语义:调用方走建议模式(报告输出人工建议),不静默、可审计。
|
|
1648
1971
|
*/
|
|
1649
|
-
declare function assessBreakingChange(options: AssessOptions): Promise<AssessResult>;
|
|
1972
|
+
export declare function assessBreakingChange(options: AssessOptions): Promise<AssessResult>;
|
|
1973
|
+
//#endregion
|
|
1974
|
+
//#region src/app/repo-alerts.d.ts
|
|
1975
|
+
/**
|
|
1976
|
+
* 获取仓库的默认分支。
|
|
1977
|
+
* pnpm-audit 模式 client 为 null → 返回 ''(报告显示 local)。
|
|
1978
|
+
* 失败时返回 `'unknown'`(不阻塞主流程)。
|
|
1979
|
+
*/
|
|
1980
|
+
export declare function fetchDefaultBranch(client: Octokit | null, owner: string, repo: string): Promise<string>;
|
|
1650
1981
|
//#endregion
|
|
1651
1982
|
//#region src/app/index.d.ts
|
|
1652
|
-
interface DependfixAppOptions {
|
|
1983
|
+
export interface DependfixAppOptions {
|
|
1653
1984
|
/** 已解析的运行时配置 */
|
|
1654
1985
|
config: RuntimeConfig;
|
|
1655
1986
|
/** 工作目录(默认 `process.cwd()`) */
|
|
@@ -1660,20 +1991,45 @@ interface DependfixAppOptions {
|
|
|
1660
1991
|
verbose?: boolean;
|
|
1661
1992
|
/** 自定义验证命令(覆盖默认命令链) */
|
|
1662
1993
|
commands?: string[];
|
|
1994
|
+
/**
|
|
1995
|
+
* 执行环境:`local`(CLI/MCP 等用户机器直接执行)| `container`(平台容器沙箱)。
|
|
1996
|
+
* 默认 `local`。容器内执行属于设计内隔离行为(非 root + 临时目录),
|
|
1997
|
+
* 不触发本地模式不可信代码风险警告。
|
|
1998
|
+
*/
|
|
1999
|
+
executionEnvironment?: 'local' | 'container';
|
|
2000
|
+
/**
|
|
2001
|
+
* 自定义 Logger(平台层注入 MemoryLogger 用于捕获执行日志)。
|
|
2002
|
+
* 未提供时使用内部 createLogger(输出到 console)。
|
|
2003
|
+
*/
|
|
2004
|
+
logger?: Logger;
|
|
1663
2005
|
}
|
|
1664
|
-
interface DependfixRunResult {
|
|
2006
|
+
export interface DependfixRunResult {
|
|
1665
2007
|
/** 结构化运行结果(用于报告生成) */
|
|
1666
2008
|
result: RunResult;
|
|
1667
2009
|
/** 进程退出码:0=全部成功, 1=部分失败, 2=全部失败 */
|
|
1668
2010
|
exitCode: number;
|
|
1669
2011
|
}
|
|
1670
|
-
|
|
2012
|
+
/**
|
|
2013
|
+
* 输出"部分源拉取失败"汇总(todo.md §M19.5 C8 per-source 错误隔离)。
|
|
2014
|
+
*
|
|
2015
|
+
* 触发条件(必须全部满足,避免与"全部源失败"语义重叠):
|
|
2016
|
+
* 1. allErrors 至少包含一个 `stage='fetch' + category='FETCH_FAILED'` 错误(per-source 失败)
|
|
2017
|
+
* 2. **至少一个仓库成功拉取了部分告警**(isAnyRepoSuccessful = true)——
|
|
2018
|
+
* 否则就是"全部源失败"语义,已由 processRepoForReport catch + logger.error 单独处理,
|
|
2019
|
+
* 本函数聚焦"warn + 保留成功源"场景的汇总输出,避免重复提示。
|
|
2020
|
+
*
|
|
2021
|
+
* 汇总按 source 分组('dependabot' / 'code-scanning' / 'code-quality' / 'pnpm-audit'),
|
|
2022
|
+
* 列出每个源失败的仓库数 + 示例错误消息,便于用户快速定位是 token 权限还是网络问题。
|
|
2023
|
+
*/
|
|
2024
|
+
export declare function logPartialSourceFailureSummary(allErrors: FixError[], logger: Logger, isAnyRepoSuccessful: boolean): void;
|
|
2025
|
+
export declare class DependfixApp {
|
|
1671
2026
|
private readonly config;
|
|
1672
2027
|
private readonly workDir;
|
|
1673
2028
|
private readonly reportOutputDir;
|
|
1674
2029
|
private readonly logger;
|
|
1675
2030
|
private readonly verbose;
|
|
1676
2031
|
private readonly customCommands?;
|
|
2032
|
+
private readonly executionEnvironment;
|
|
1677
2033
|
private readonly runId;
|
|
1678
2034
|
private readonly allAlerts;
|
|
1679
2035
|
private readonly allActions;
|
|
@@ -1691,6 +2047,14 @@ declare class DependfixApp {
|
|
|
1691
2047
|
private get ctx();
|
|
1692
2048
|
/** 执行完整的编排流程,返回结构化结果和退出码。 */
|
|
1693
2049
|
run(): Promise<DependfixRunResult>;
|
|
2050
|
+
/**
|
|
2051
|
+
* 启动安全自检(best-effort,任何失败不阻断运行):
|
|
2052
|
+
* - 本地模式风险提示:fix/fix-and-pr 会在用户机器直接执行目标仓库的
|
|
2053
|
+
* 依赖脚本(不可信代码);容器环境(平台沙箱)属于设计内隔离,跳过。
|
|
2054
|
+
* - token 权限面探测:超权限 token(classic repo scope)启动即警告,
|
|
2055
|
+
* Code Scanning 开启但缺 security-events 权限时提示。
|
|
2056
|
+
*/
|
|
2057
|
+
private runStartupSecurityChecks;
|
|
1694
2058
|
private executeMode;
|
|
1695
2059
|
private executeReportMode;
|
|
1696
2060
|
private processRepoForReport;
|
|
@@ -1714,6 +2078,16 @@ declare class DependfixApp {
|
|
|
1714
2078
|
* - dry-run 模式仅列清单并打印 "would delete",不执行删除
|
|
1715
2079
|
*/
|
|
1716
2080
|
private executeCleanupBranchesMode;
|
|
2081
|
+
/**
|
|
2082
|
+
* 重复 PR 处理:在新 PR 上添加评论指向被取代的旧 PR + 添加 `duplicate` label。
|
|
2083
|
+
*
|
|
2084
|
+
* 失败仅记录 warning(家务活 best-effort),不阻断主流程:
|
|
2085
|
+
* - 新 PR 已创建成功,用户已可访问
|
|
2086
|
+
* - 评论失败不影响 PR 本身的可用性
|
|
2087
|
+
* - 但需要 `issues: write` token scope(比 `pull-requests: write` 宽);
|
|
2088
|
+
* 若 token 权限不足,error 会被记录但不阻塞
|
|
2089
|
+
*/
|
|
2090
|
+
private handleDuplicatePRs;
|
|
1717
2091
|
/**
|
|
1718
2092
|
* 多仓库并发执行管线。
|
|
1719
2093
|
*
|
|
@@ -1739,5 +2113,5 @@ declare class DependfixApp {
|
|
|
1739
2113
|
private createClient;
|
|
1740
2114
|
}
|
|
1741
2115
|
//#endregion
|
|
1742
|
-
export {
|
|
2116
|
+
export type { AiAssessment, AiChatResult, AiConfig, AiFileChange, AiReplaceBlock, AiUsage, AlertClass, AlertSourceKind, AssessmentContextInput, AuthProvider, AuthProviderOptions, FromAppParams, FromPatParams, SeverityThreshold };
|
|
1743
2117
|
//# sourceMappingURL=index.d.mts.map
|