canship 0.3.1 → 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-zh-CN.md +110 -62
- package/README.md +117 -69
- package/dist/cli.js +1576 -223
- package/dist/index.d.ts +159 -0
- package/dist/index.js +4972 -0
- package/package.json +12 -1
- package/schemas/scan-report-v1.schema.json +26 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/** 扫描器的核心数据结构。 */
|
|
2
|
+
/** 严重度:P0 为高影响凭据或权限问题,P1 为访问控制问题,P2 为其他配置问题。 */
|
|
3
|
+
type Severity = 'P0' | 'P1' | 'P2';
|
|
4
|
+
/** 置信度:certain 表示确定证据,likely 表示需人工确认。 */
|
|
5
|
+
type Confidence = 'certain' | 'likely';
|
|
6
|
+
/** 静态证据位置,不包含源码摘录或运行时结论。 */
|
|
7
|
+
interface EvidenceStep {
|
|
8
|
+
kind: 'operation' | 'import' | 'admin-client' | 'auth-helper';
|
|
9
|
+
file: string;
|
|
10
|
+
line: number | null;
|
|
11
|
+
description: string;
|
|
12
|
+
}
|
|
13
|
+
/** 单条扫描结果。 */
|
|
14
|
+
interface Finding {
|
|
15
|
+
/** 对外展示的规则 ID。 */
|
|
16
|
+
ruleId: string;
|
|
17
|
+
severity: Severity;
|
|
18
|
+
confidence: Confidence;
|
|
19
|
+
/** 简明描述问题及影响。 */
|
|
20
|
+
title: string;
|
|
21
|
+
/** 相对文件路径;无具体文件时为空。 */
|
|
22
|
+
file: string | null;
|
|
23
|
+
/** 从 1 开始的行号;无法定位时为空。 */
|
|
24
|
+
line: number | null;
|
|
25
|
+
/** 展示摘录;最终输出必须完整脱敏。 */
|
|
26
|
+
excerpt: string | null;
|
|
27
|
+
/** 原始来源行或文件证据的摘要,独立于展示用的脱敏和截断。 */
|
|
28
|
+
sourceFingerprint?: string;
|
|
29
|
+
evidence?: EvidenceStep[];
|
|
30
|
+
/** 展示链达到长度上限,不影响已经完成的扫描。 */
|
|
31
|
+
evidenceTruncated?: boolean;
|
|
32
|
+
/** 影响说明,每个元素独立表示一个段落。 */
|
|
33
|
+
why: string[];
|
|
34
|
+
/** 可执行的代码修复步骤。 */
|
|
35
|
+
fix: string[];
|
|
36
|
+
/** 需人工执行的轮换、控制台配置或历史重写步骤。 */
|
|
37
|
+
humanOnly?: string[];
|
|
38
|
+
}
|
|
39
|
+
/** 文件未被读取的原因。 */
|
|
40
|
+
type SkipReason =
|
|
41
|
+
/** 超过文件大小限制。 */
|
|
42
|
+
'too-large'
|
|
43
|
+
/** 权限不足、设备错误或扫描期间文件变化。 */
|
|
44
|
+
| 'unreadable'
|
|
45
|
+
/** 目录无法列出,内容未知。 */
|
|
46
|
+
| 'directory-unreadable'
|
|
47
|
+
/** 扩展名可扫描但实际内容为二进制。 */
|
|
48
|
+
| 'binary'
|
|
49
|
+
/** 不跟随的符号链接。 */
|
|
50
|
+
| 'symlink'
|
|
51
|
+
/** Git 返回的不透明嵌套仓库或子模块。 */
|
|
52
|
+
| 'nested-repository';
|
|
53
|
+
/** 按对外规则 ID 或命名空间选择规则。 */
|
|
54
|
+
interface ScanOptions$1 {
|
|
55
|
+
/** 仅执行匹配规则;与 skip 互斥。 */
|
|
56
|
+
only?: string[];
|
|
57
|
+
/** 排除匹配规则。 */
|
|
58
|
+
skip?: string[];
|
|
59
|
+
/** 是否遵从被扫描项目中的忽略标记;默认遵从,扫描不可信项目时应关闭。 */
|
|
60
|
+
honorIgnoreMarkers?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** 规则筛选条件及过滤统计。 */
|
|
63
|
+
interface RuleSelection {
|
|
64
|
+
only: string[];
|
|
65
|
+
skip: string[];
|
|
66
|
+
/** 已执行规则中被过滤的结果数,不估算未执行规则。 */
|
|
67
|
+
removed: number;
|
|
68
|
+
}
|
|
69
|
+
/** 被逐行忽略标记抑制的结果位置。 */
|
|
70
|
+
interface IgnoredFinding {
|
|
71
|
+
file: string;
|
|
72
|
+
/** 结果所在行号,从 1 开始。 */
|
|
73
|
+
line: number;
|
|
74
|
+
ruleId: string;
|
|
75
|
+
}
|
|
76
|
+
/** 发现但未检查的文件或目录。 */
|
|
77
|
+
interface SkippedFile {
|
|
78
|
+
path: string;
|
|
79
|
+
reason: SkipReason;
|
|
80
|
+
/** 额外说明,如文件大小。 */
|
|
81
|
+
detail?: string;
|
|
82
|
+
}
|
|
83
|
+
/** 规则异常或达到资源上限。 */
|
|
84
|
+
interface ScanError {
|
|
85
|
+
/** 规则 ID,或遍历器标识。 */
|
|
86
|
+
ruleId: string;
|
|
87
|
+
/** 单文件规则处理的文件路径。 */
|
|
88
|
+
file: string | null;
|
|
89
|
+
message: string;
|
|
90
|
+
/** 区分执行异常与已知扫描缺口。 */
|
|
91
|
+
kind: 'crashed' | 'incomplete';
|
|
92
|
+
}
|
|
93
|
+
/** 变更视图的比较基准、隐藏数量及完整扫描统计。 */
|
|
94
|
+
interface ChangeView {
|
|
95
|
+
baseCommit: string;
|
|
96
|
+
mergeBase: string;
|
|
97
|
+
changedFiles: number;
|
|
98
|
+
hiddenFindings: number;
|
|
99
|
+
totalFindings: number;
|
|
100
|
+
totalBlocking: number;
|
|
101
|
+
totalLikely: number;
|
|
102
|
+
}
|
|
103
|
+
/** 扫描汇总;结果为空时仍需保留完整性信息。 */
|
|
104
|
+
interface ScanResult {
|
|
105
|
+
/** 仅筛选展示;统计和退出码仍基于完整扫描。 */
|
|
106
|
+
changeView?: ChangeView;
|
|
107
|
+
findings: Finding[];
|
|
108
|
+
/** 实际读取并扫描的文件数。 */
|
|
109
|
+
filesScanned: number;
|
|
110
|
+
/** 扫描耗时,单位为毫秒。 */
|
|
111
|
+
durationMs: number;
|
|
112
|
+
/** 规则异常及不完整记录。 */
|
|
113
|
+
errors: ScanError[];
|
|
114
|
+
/** 未检查的文件和目录。 */
|
|
115
|
+
skipped: SkippedFile[];
|
|
116
|
+
/** 整文件忽略标记排除的文件;必须显式披露。 */
|
|
117
|
+
ignored: string[];
|
|
118
|
+
/** 逐行忽略标记抑制的位置及规则。 */
|
|
119
|
+
ignoredFindings: IgnoredFinding[];
|
|
120
|
+
/** 本次规则筛选信息;未筛选时为空。 */
|
|
121
|
+
ruleSelection: RuleSelection | null;
|
|
122
|
+
/** 排除的第三方路径数。 */
|
|
123
|
+
vendored: number;
|
|
124
|
+
/** 是否存在扫描缺口;为真时不能推断整个项目无问题。 */
|
|
125
|
+
partial: boolean;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** 规则目录说明检测范围与证据边界,不执行扫描。 */
|
|
129
|
+
|
|
130
|
+
interface RuleDescription {
|
|
131
|
+
id: string;
|
|
132
|
+
name: string;
|
|
133
|
+
severity: Severity;
|
|
134
|
+
confidence: 'certain' | 'likely' | 'varies';
|
|
135
|
+
scope: string;
|
|
136
|
+
limitation: string;
|
|
137
|
+
reportsFindings: boolean;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
interface ScanOptions extends ScanOptions$1 {
|
|
141
|
+
/** 移除结果摘录;路径、标题及说明仍需在分享前审阅。 */
|
|
142
|
+
noExcerpts?: boolean;
|
|
143
|
+
}
|
|
144
|
+
interface ScanSummary {
|
|
145
|
+
findings: number;
|
|
146
|
+
blocking: number;
|
|
147
|
+
likely: number;
|
|
148
|
+
partial: boolean;
|
|
149
|
+
/** 与 CLI 默认策略一致;不自动设置 process.exitCode。 */
|
|
150
|
+
exitCode: 0 | 1 | 2 | 3;
|
|
151
|
+
}
|
|
152
|
+
/** 返回独立副本,避免调用方修改内部规则目录。 */
|
|
153
|
+
declare function listRules(): RuleDescription[];
|
|
154
|
+
/** 统计全部结果;结果退出码优先,完整性始终单独保留。 */
|
|
155
|
+
declare function summarize(result: ScanResult): ScanSummary;
|
|
156
|
+
/** 扫描指定目录,返回全部置信度结果;不自动应用基线或项目配置。 */
|
|
157
|
+
declare function scan(root: string, options?: ScanOptions): Promise<ScanResult>;
|
|
158
|
+
|
|
159
|
+
export { type ChangeView, type Confidence, type EvidenceStep, type Finding, type RuleDescription, type RuleSelection, type ScanError, type ScanOptions, type ScanResult, type ScanSummary, type Severity, type SkippedFile, listRules, scan, summarize };
|