canship 0.7.1 → 0.8.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/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
+ /** 稳定诊断代码独立于展示文本;跳过文件继续使用现有 reason 字段。 */
2
+
3
+ type DiagnosticCode = 'RULE_EXECUTION_FAILED' | 'ANALYSIS_INCOMPLETE' | 'GIT_CHECK_INCOMPLETE' | 'ROUTE_UNRESOLVED' | 'FINDINGS_LIMIT' | 'INVALID_ARGUMENT' | 'CONFIG_INVALID' | 'BASELINE_INVALID' | 'GIT_REFERENCE_INVALID' | 'SCAN_ROOT_UNAVAILABLE' | 'OUTPUT_WRITE_FAILED' | 'INTERNAL_ERROR' | 'SCAN_CANCELLED' | 'PROGRESS_CALLBACK_FAILED' | 'REPORT_COMPARISON_INVALID' | 'WORKSPACE_INVALID' | 'WORKSPACE_UNAVAILABLE' | 'WORKSPACE_SCAN_FAILED' | (string & {});
4
+
1
5
  /** 扫描器的核心数据结构。 */
2
6
  /** 严重度:P0 为高影响凭据或权限问题,P1 为访问控制问题,P2 为其他配置问题。 */
3
7
  type Severity = 'P0' | 'P1' | 'P2';
@@ -52,6 +56,12 @@ type SkipReason =
52
56
  | 'nested-repository';
53
57
  /** 按对外规则 ID 或命名空间选择规则。 */
54
58
  interface ScanOptions$1 {
59
+ /** 项目相对文件或目录路径,按字面值匹配。 */
60
+ exclude?: string[];
61
+ /** 在同步分析批次和规则边界检查取消,不中断正在执行的同步系统调用。 */
62
+ signal?: AbortSignal;
63
+ /** 只提供阶段和计数;回调失败会中止扫描。 */
64
+ onProgress?: (progress: Readonly<ScanProgress>) => void | Promise<void>;
55
65
  /** 仅执行匹配规则;与 skip 互斥。 */
56
66
  only?: string[];
57
67
  /** 排除匹配规则。 */
@@ -59,6 +69,13 @@ interface ScanOptions$1 {
59
69
  /** 是否遵从被扫描项目中的忽略标记;默认遵从,扫描不可信项目时应关闭。 */
60
70
  honorIgnoreMarkers?: boolean;
61
71
  }
72
+ interface ScanProgress {
73
+ phase: 'discovery' | 'files' | 'history' | 'project' | 'finalize' | 'complete';
74
+ filesCompleted: number;
75
+ filesTotal: number | null;
76
+ projectRulesCompleted: number;
77
+ projectRulesTotal: number | null;
78
+ }
62
79
  /** 规则筛选条件及过滤统计。 */
63
80
  interface RuleSelection {
64
81
  only: string[];
@@ -89,6 +106,8 @@ interface ScanError {
89
106
  message: string;
90
107
  /** 区分执行异常与已知扫描缺口。 */
91
108
  kind: 'crashed' | 'incomplete';
109
+ /** 稳定诊断代码;旧报告可能没有此字段。 */
110
+ code?: DiagnosticCode;
92
111
  }
93
112
  /** 变更视图的比较基准、隐藏数量及完整扫描统计。 */
94
113
  interface ChangeView {
@@ -102,6 +121,11 @@ interface ChangeView {
102
121
  }
103
122
  /** 扫描汇总;结果为空时仍需保留完整性信息。 */
104
123
  interface ScanResult {
124
+ /** 显式文件范围限制;matched 是匹配到的请求路径,不是文件数量。 */
125
+ exclusions?: {
126
+ requested: string[];
127
+ matched: string[];
128
+ };
105
129
  /** 仅筛选展示;统计和退出码仍基于完整扫描。 */
106
130
  changeView?: ChangeView;
107
131
  findings: Finding[];
@@ -125,6 +149,13 @@ interface ScanResult {
125
149
  partial: boolean;
126
150
  }
127
151
 
152
+ interface FixExample {
153
+ context: string;
154
+ before: string;
155
+ after: string;
156
+ limitation: string;
157
+ }
158
+
128
159
  /** 规则目录说明检测范围与证据边界,不执行扫描。 */
129
160
 
130
161
  interface RuleDescription {
@@ -135,25 +166,64 @@ interface RuleDescription {
135
166
  scope: string;
136
167
  limitation: string;
137
168
  reportsFindings: boolean;
169
+ example?: FixExample;
138
170
  }
139
171
 
140
- interface ScanOptions extends ScanOptions$1 {
141
- /** 移除结果摘录;路径、标题及说明仍需在分享前审阅。 */
142
- noExcerpts?: boolean;
143
- }
172
+ /** CLI 与公共 API 共享结果判定;展示过滤不改变完整扫描结论。 */
173
+
144
174
  interface ScanSummary {
145
175
  findings: number;
146
176
  blocking: number;
147
177
  likely: number;
148
178
  partial: boolean;
149
- /** 与 CLI 默认策略一致;不自动设置 process.exitCode。 */
150
179
  exitCode: 0 | 1 | 2 | 3;
151
180
  }
181
+ declare function summarize(result: ScanResult): ScanSummary;
182
+
183
+ /** 扫描控制不包含路径或源码;取消原因不进入诊断文本。 */
184
+
185
+ declare class ScanCancelledError extends Error {
186
+ readonly code = "SCAN_CANCELLED";
187
+ constructor();
188
+ }
189
+ declare class ScanProgressError extends Error {
190
+ readonly code = "PROGRESS_CALLBACK_FAILED";
191
+ constructor(cause: unknown);
192
+ }
193
+
194
+ /** 构建身份只包含公开版本与提交摘要,不读取运行机器或扫描项目的信息。 */
195
+ interface BuildInfo {
196
+ version: string;
197
+ channel: 'development' | 'prerelease' | 'release';
198
+ revision: string | null;
199
+ dirty: boolean | null;
200
+ }
201
+ declare function getBuildInfo(): BuildInfo;
202
+ /** 能力声明与边界测试配套;未来联网模式不得继承静态扫描的默认授权。 */
203
+ declare function getCapabilities(): {
204
+ staticScan: {
205
+ network: boolean;
206
+ projectCodeExecution: boolean;
207
+ projectWrites: boolean;
208
+ };
209
+ fileOutputs: string;
210
+ onlineValidation: boolean;
211
+ onlineValidationPolicy: {
212
+ cliOnly: boolean;
213
+ defaultEnabled: boolean;
214
+ confirmation: string;
215
+ credentials: boolean;
216
+ responseBodiesRetained: boolean;
217
+ };
218
+ };
219
+
220
+ interface ScanOptions extends ScanOptions$1 {
221
+ /** 移除结果摘录;路径、标题及说明仍需在分享前审阅。 */
222
+ noExcerpts?: boolean;
223
+ }
152
224
  /** 返回独立副本,避免调用方修改内部规则目录。 */
153
225
  declare function listRules(): RuleDescription[];
154
- /** 统计全部结果;结果退出码优先,完整性始终单独保留。 */
155
- declare function summarize(result: ScanResult): ScanSummary;
156
226
  /** 扫描指定目录,返回全部置信度结果;不自动应用基线或项目配置。 */
157
227
  declare function scan(root: string, options?: ScanOptions): Promise<ScanResult>;
158
228
 
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 };
229
+ export { type BuildInfo, type ChangeView, type Confidence, type DiagnosticCode, type EvidenceStep, type Finding, type RuleDescription, type RuleSelection, ScanCancelledError, type ScanError, type ScanOptions, type ScanProgress, ScanProgressError, type ScanResult, type ScanSummary, type Severity, type SkippedFile, getBuildInfo, getCapabilities, listRules, scan, summarize };