@boringparts/lioni 0.0.0-stage → 0.4.2
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/LICENSE +21 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +959 -0
- package/dist/dist-BjI3h4o3.js +3797 -0
- package/dist/index.d.ts +724 -0
- package/dist/index.js +3862 -0
- package/dist/node-Bb9WsnGu.js +233 -0
- package/dist/node.d.ts +26 -0
- package/dist/node.js +108 -0
- package/dist/report-EsWS84c0.js +93 -0
- package/dist/yaml-DX1EEaWD.js +331 -0
- package/dist/yaml-Dn7jqV-s.d.ts +1027 -0
- package/package.json +72 -3
- package/README.md +0 -3
package/dist/cli.js
ADDED
|
@@ -0,0 +1,959 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { L as upsertQaSuppressionFromReport, f as previewUpdate, g as recordComparisonBaseline, i as readProjectSnapshot, l as update, o as runQa, t as DuplicateTranslationUnitKeyError } from "./dist-BjI3h4o3.js";
|
|
3
|
+
import { n as formatQualityReport, t as decideQualityReport } from "./report-EsWS84c0.js";
|
|
4
|
+
import { r as loadConfig, t as createFileComparisonBaselineStore } from "./node-Bb9WsnGu.js";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { isNodeBrokenPipe, nodeCliOutput } from "@ykdz/cli-contract/node";
|
|
7
|
+
import * as z$1 from "zod";
|
|
8
|
+
import { readFile } from "node:fs/promises";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { CliWriteError, defineCli, executeCli, helpCapability, parseCliInvocation, schemaCapability, text, versionCapability } from "@ykdz/cli-contract";
|
|
11
|
+
// src/cli-command-identity.ts
|
|
12
|
+
const commandNameSchema = z$1.string().regex(/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u, "命令名必须由小写 ASCII 字母、数字和单个连字符组成,并以字母开头。");
|
|
13
|
+
const manifestSchema = z$1.object({
|
|
14
|
+
bin: z$1.record(z$1.string(), z$1.literal("./dist/cli.js")).refine((bin) => Object.keys(bin).length === 1, "CLI 包必须恰好声明一个命令。"),
|
|
15
|
+
version: z$1.string().min(1).default("unpublished")
|
|
16
|
+
});
|
|
17
|
+
function validateCliCommandName(commandName, occupiedCommandNames = []) {
|
|
18
|
+
const parsed = commandNameSchema.safeParse(commandName);
|
|
19
|
+
if (!parsed.success) throw new TypeError(parsed.error.issues[0].message);
|
|
20
|
+
if (occupiedCommandNames.includes(commandName)) throw new Error(`CLI 命令名已被其他工作区包使用:${commandName}`);
|
|
21
|
+
return parsed.data;
|
|
22
|
+
}
|
|
23
|
+
function cliCommandIdentity(manifest, occupiedCommandNames = []) {
|
|
24
|
+
const parsed = manifestSchema.safeParse(manifest);
|
|
25
|
+
if (!parsed.success) throw new TypeError(parsed.error.issues.map(({ path, message }) => `${path.join(".")}: ${message}`).join(";"));
|
|
26
|
+
const [commandName] = Object.keys(parsed.data.bin);
|
|
27
|
+
return {
|
|
28
|
+
commandName: validateCliCommandName(commandName, occupiedCommandNames),
|
|
29
|
+
version: parsed.data.version
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// src/main.ts
|
|
33
|
+
const languageOption = {
|
|
34
|
+
kind: "repeatableOption",
|
|
35
|
+
longOption: "--language",
|
|
36
|
+
description: "本次执行的目标语言;可重复指定,省略时执行全部已配置语言"
|
|
37
|
+
};
|
|
38
|
+
const checkOption = {
|
|
39
|
+
kind: "repeatableOption",
|
|
40
|
+
longOption: "--check",
|
|
41
|
+
description: "本次要执行的检查项 ID;可重复指定"
|
|
42
|
+
};
|
|
43
|
+
const groupOption = {
|
|
44
|
+
kind: "repeatableOption",
|
|
45
|
+
longOption: "--group",
|
|
46
|
+
description: "本次要执行的项目分组;可重复指定"
|
|
47
|
+
};
|
|
48
|
+
const severityOption = {
|
|
49
|
+
kind: "repeatableOption",
|
|
50
|
+
longOption: "--severity",
|
|
51
|
+
description: "仅展示指定严重度的终端问题明细;可重复指定取并集,默认展开全部"
|
|
52
|
+
};
|
|
53
|
+
const maxPerCheckOption = {
|
|
54
|
+
kind: "valueOption",
|
|
55
|
+
longOption: "--max-per-check",
|
|
56
|
+
description: "每项检查在终端最多展示的匹配明细条数;仅显式指定时折叠"
|
|
57
|
+
};
|
|
58
|
+
const positiveIntegerOptionSchema = z$1.codec(z$1.string().regex(/^[1-9]\d*$/u), z$1.number().int().positive(), {
|
|
59
|
+
decode: (value) => Number(value),
|
|
60
|
+
encode: (value) => String(value)
|
|
61
|
+
});
|
|
62
|
+
const languagesSchema = z$1.optional(z$1.array(z$1.string()));
|
|
63
|
+
const scopedConfigSchema = z$1.object({
|
|
64
|
+
config: z$1.string(),
|
|
65
|
+
languages: languagesSchema
|
|
66
|
+
});
|
|
67
|
+
const qaConfigSchema = scopedConfigSchema.extend({
|
|
68
|
+
checks: z$1.optional(z$1.array(z$1.string())),
|
|
69
|
+
groups: z$1.optional(z$1.array(z$1.string())),
|
|
70
|
+
severity: z$1.optional(z$1.array(z$1.enum([
|
|
71
|
+
"error",
|
|
72
|
+
"warning",
|
|
73
|
+
"info"
|
|
74
|
+
]))),
|
|
75
|
+
maxPerCheck: z$1.optional(positiveIntegerOptionSchema)
|
|
76
|
+
});
|
|
77
|
+
function languageSelection(input) {
|
|
78
|
+
return input.languages === void 0 ? {} : { languages: input.languages };
|
|
79
|
+
}
|
|
80
|
+
function qualityCheckSelection(input) {
|
|
81
|
+
if (input.checks !== void 0) return { checkIds: input.checks };
|
|
82
|
+
if (input.groups !== void 0) return { groups: input.groups };
|
|
83
|
+
return {};
|
|
84
|
+
}
|
|
85
|
+
const enumerationSchema = z$1.enum([
|
|
86
|
+
"complete",
|
|
87
|
+
"partial",
|
|
88
|
+
"failed"
|
|
89
|
+
]);
|
|
90
|
+
const readStatusSchema = z$1.enum([
|
|
91
|
+
"complete",
|
|
92
|
+
"incomplete",
|
|
93
|
+
"failed",
|
|
94
|
+
"notRead"
|
|
95
|
+
]);
|
|
96
|
+
const sourceReadCoverageSchema = z$1.object({
|
|
97
|
+
status: readStatusSchema,
|
|
98
|
+
scopes: z$1.array(z$1.object({
|
|
99
|
+
range: z$1.unknown(),
|
|
100
|
+
enumeration: enumerationSchema,
|
|
101
|
+
recordCount: z$1.number(),
|
|
102
|
+
error: z$1.optional(z$1.string())
|
|
103
|
+
})),
|
|
104
|
+
error: z$1.optional(z$1.string())
|
|
105
|
+
});
|
|
106
|
+
const translationReadCoverageSchema = z$1.object({
|
|
107
|
+
language: z$1.string(),
|
|
108
|
+
status: readStatusSchema,
|
|
109
|
+
scopes: z$1.array(z$1.object({
|
|
110
|
+
range: z$1.unknown(),
|
|
111
|
+
covers: z$1.array(z$1.string()),
|
|
112
|
+
enumeration: enumerationSchema,
|
|
113
|
+
translationIndexes: z$1.array(z$1.number()),
|
|
114
|
+
error: z$1.optional(z$1.string())
|
|
115
|
+
})),
|
|
116
|
+
error: z$1.optional(z$1.string())
|
|
117
|
+
});
|
|
118
|
+
const projectSnapshotSchema = z$1.object({
|
|
119
|
+
version: z$1.string(),
|
|
120
|
+
source: z$1.object({
|
|
121
|
+
version: z$1.string(),
|
|
122
|
+
read: sourceReadCoverageSchema,
|
|
123
|
+
totalUnitCount: z$1.nullable(z$1.number()),
|
|
124
|
+
units: z$1.array(z$1.object({
|
|
125
|
+
key: z$1.string(),
|
|
126
|
+
unit: z$1.unknown(),
|
|
127
|
+
bodyAvailability: z$1.enum(["available", "unavailable"]),
|
|
128
|
+
scopeIndex: z$1.number()
|
|
129
|
+
}))
|
|
130
|
+
}),
|
|
131
|
+
translations: z$1.object({
|
|
132
|
+
reads: z$1.array(translationReadCoverageSchema),
|
|
133
|
+
records: z$1.array(z$1.discriminatedUnion("bodyAvailability", [z$1.strictObject({
|
|
134
|
+
index: z$1.number(),
|
|
135
|
+
language: z$1.string(),
|
|
136
|
+
scopeIndex: z$1.number(),
|
|
137
|
+
range: z$1.unknown(),
|
|
138
|
+
identity: z$1.strictObject({
|
|
139
|
+
language: z$1.string(),
|
|
140
|
+
key: z$1.string()
|
|
141
|
+
}),
|
|
142
|
+
record: z$1.unknown(),
|
|
143
|
+
content: z$1.unknown(),
|
|
144
|
+
bodyAvailability: z$1.literal("available")
|
|
145
|
+
}), z$1.strictObject({
|
|
146
|
+
index: z$1.number(),
|
|
147
|
+
language: z$1.string(),
|
|
148
|
+
scopeIndex: z$1.number(),
|
|
149
|
+
range: z$1.unknown(),
|
|
150
|
+
identity: z$1.strictObject({
|
|
151
|
+
language: z$1.string(),
|
|
152
|
+
key: z$1.string()
|
|
153
|
+
}),
|
|
154
|
+
record: z$1.unknown(),
|
|
155
|
+
bodyAvailability: z$1.literal("unavailable")
|
|
156
|
+
})]))
|
|
157
|
+
}),
|
|
158
|
+
associations: z$1.array(z$1.object({
|
|
159
|
+
sourceKey: z$1.string(),
|
|
160
|
+
language: z$1.string(),
|
|
161
|
+
status: z$1.enum([
|
|
162
|
+
"matched",
|
|
163
|
+
"missing",
|
|
164
|
+
"unavailable",
|
|
165
|
+
"unknown"
|
|
166
|
+
]),
|
|
167
|
+
coverageStatus: readStatusSchema,
|
|
168
|
+
scopeIndexes: z$1.array(z$1.number()),
|
|
169
|
+
translationIndexes: z$1.array(z$1.number())
|
|
170
|
+
}))
|
|
171
|
+
});
|
|
172
|
+
const qualityObjectSchema = z$1.looseObject({
|
|
173
|
+
kind: z$1.string(),
|
|
174
|
+
key: z$1.string(),
|
|
175
|
+
language: z$1.optional(z$1.string())
|
|
176
|
+
});
|
|
177
|
+
const qualityLocationSchema = z$1.looseObject({
|
|
178
|
+
language: z$1.nullable(z$1.string()),
|
|
179
|
+
range: z$1.unknown(),
|
|
180
|
+
key: z$1.optional(z$1.string())
|
|
181
|
+
});
|
|
182
|
+
const qualityEvidenceSchema = z$1.object({
|
|
183
|
+
role: z$1.string(),
|
|
184
|
+
object: qualityObjectSchema,
|
|
185
|
+
location: qualityLocationSchema,
|
|
186
|
+
value: z$1.unknown()
|
|
187
|
+
});
|
|
188
|
+
const qualityDiagnosticHandlingSchema = z$1.discriminatedUnion("status", [z$1.object({ status: z$1.literal("active") }), z$1.object({
|
|
189
|
+
status: z$1.literal("suppressed"),
|
|
190
|
+
suppressionId: z$1.string(),
|
|
191
|
+
reason: z$1.string()
|
|
192
|
+
})]);
|
|
193
|
+
const qualityDiagnosticSchema = z$1.object({
|
|
194
|
+
checkId: z$1.string(),
|
|
195
|
+
executionId: z$1.number(),
|
|
196
|
+
severity: z$1.enum([
|
|
197
|
+
"error",
|
|
198
|
+
"warning",
|
|
199
|
+
"info"
|
|
200
|
+
]),
|
|
201
|
+
object: qualityObjectSchema,
|
|
202
|
+
location: qualityLocationSchema,
|
|
203
|
+
message: z$1.string(),
|
|
204
|
+
evidence: z$1.array(qualityEvidenceSchema),
|
|
205
|
+
handling: qualityDiagnosticHandlingSchema
|
|
206
|
+
});
|
|
207
|
+
const qualityFingerprintSummarySchema = z$1.object({
|
|
208
|
+
version: z$1.string(),
|
|
209
|
+
inputFingerprint: z$1.string()
|
|
210
|
+
});
|
|
211
|
+
const qualityCheckExecutionSchema = z$1.object({
|
|
212
|
+
executionId: z$1.number(),
|
|
213
|
+
candidateIndex: z$1.optional(z$1.number()),
|
|
214
|
+
checkId: z$1.string(),
|
|
215
|
+
sourceKey: z$1.string(),
|
|
216
|
+
language: z$1.string(),
|
|
217
|
+
inputFingerprint: z$1.optional(z$1.string()),
|
|
218
|
+
fingerprintSummary: z$1.optional(qualityFingerprintSummarySchema)
|
|
219
|
+
});
|
|
220
|
+
const qualityCheckResultSchema = z$1.object({
|
|
221
|
+
checkId: z$1.string(),
|
|
222
|
+
version: z$1.string(),
|
|
223
|
+
diagnostics: z$1.array(qualityDiagnosticSchema),
|
|
224
|
+
coverage: z$1.object({
|
|
225
|
+
selected: z$1.number(),
|
|
226
|
+
evaluated: z$1.number()
|
|
227
|
+
}),
|
|
228
|
+
executions: z$1.array(qualityCheckExecutionSchema)
|
|
229
|
+
});
|
|
230
|
+
const qualityRunResultSchema = z$1.object({
|
|
231
|
+
version: z$1.string(),
|
|
232
|
+
candidates: z$1.array(z$1.object({
|
|
233
|
+
sourceKey: z$1.string(),
|
|
234
|
+
language: z$1.string(),
|
|
235
|
+
content: z$1.unknown()
|
|
236
|
+
})),
|
|
237
|
+
readCoverage: z$1.object({
|
|
238
|
+
source: sourceReadCoverageSchema,
|
|
239
|
+
translations: z$1.array(translationReadCoverageSchema),
|
|
240
|
+
associations: z$1.array(z$1.object({
|
|
241
|
+
sourceKey: z$1.string(),
|
|
242
|
+
language: z$1.string(),
|
|
243
|
+
status: z$1.enum([
|
|
244
|
+
"matched",
|
|
245
|
+
"missing",
|
|
246
|
+
"unavailable",
|
|
247
|
+
"unknown"
|
|
248
|
+
]),
|
|
249
|
+
coverageStatus: readStatusSchema,
|
|
250
|
+
scopeIndexes: z$1.array(z$1.number()),
|
|
251
|
+
translationIndexes: z$1.array(z$1.number()),
|
|
252
|
+
subjectSelected: z$1.boolean()
|
|
253
|
+
}))
|
|
254
|
+
}),
|
|
255
|
+
checkScope: z$1.object({
|
|
256
|
+
configuredCount: z$1.number(),
|
|
257
|
+
selectedIds: z$1.array(z$1.string()),
|
|
258
|
+
evaluatedCount: z$1.number()
|
|
259
|
+
}),
|
|
260
|
+
relationships: z$1.array(z$1.looseObject({
|
|
261
|
+
kind: z$1.string(),
|
|
262
|
+
key: z$1.string(),
|
|
263
|
+
members: z$1.array(z$1.object({
|
|
264
|
+
key: z$1.string(),
|
|
265
|
+
language: z$1.string()
|
|
266
|
+
}))
|
|
267
|
+
})),
|
|
268
|
+
suppressions: z$1.array(z$1.object({
|
|
269
|
+
id: z$1.string(),
|
|
270
|
+
reason: z$1.string(),
|
|
271
|
+
checkId: z$1.string(),
|
|
272
|
+
sourceKey: z$1.string(),
|
|
273
|
+
language: z$1.string(),
|
|
274
|
+
inputFingerprint: z$1.string(),
|
|
275
|
+
fingerprintSummary: qualityFingerprintSummarySchema
|
|
276
|
+
})),
|
|
277
|
+
progress: z$1.optional(z$1.array(z$1.object({
|
|
278
|
+
language: z$1.string(),
|
|
279
|
+
completed: z$1.number(),
|
|
280
|
+
total: z$1.number(),
|
|
281
|
+
percentage: z$1.optional(z$1.number())
|
|
282
|
+
}))),
|
|
283
|
+
diagnostics: z$1.array(qualityDiagnosticSchema),
|
|
284
|
+
checks: z$1.array(qualityCheckResultSchema)
|
|
285
|
+
});
|
|
286
|
+
const baselineRecordSchema = z$1.object({
|
|
287
|
+
outcome: z$1.enum(["saved", "unchanged"]),
|
|
288
|
+
path: z$1.string(),
|
|
289
|
+
sourceScopeCount: z$1.number(),
|
|
290
|
+
sourceUnitCount: z$1.number(),
|
|
291
|
+
translationScopeCount: z$1.number(),
|
|
292
|
+
translationRecordCount: z$1.number()
|
|
293
|
+
});
|
|
294
|
+
const updatePlanSchema = z$1.record(z$1.string(), z$1.unknown());
|
|
295
|
+
const updateResultSchema = z$1.object({
|
|
296
|
+
plan: z$1.record(z$1.string(), z$1.unknown()),
|
|
297
|
+
status: z$1.enum(["completed", "failed"]),
|
|
298
|
+
results: z$1.array(z$1.record(z$1.string(), z$1.unknown())).readonly(),
|
|
299
|
+
baseline: z$1.optional(z$1.object({
|
|
300
|
+
outcome: z$1.enum([
|
|
301
|
+
"saved",
|
|
302
|
+
"unchanged",
|
|
303
|
+
"notAdvanced",
|
|
304
|
+
"failed"
|
|
305
|
+
]),
|
|
306
|
+
message: z$1.optional(z$1.string())
|
|
307
|
+
})),
|
|
308
|
+
batchError: z$1.optional(z$1.object({
|
|
309
|
+
name: z$1.string(),
|
|
310
|
+
message: z$1.string()
|
|
311
|
+
}))
|
|
312
|
+
});
|
|
313
|
+
function readStatusText(status) {
|
|
314
|
+
return {
|
|
315
|
+
complete: "完整",
|
|
316
|
+
incomplete: "不完整",
|
|
317
|
+
failed: "失败",
|
|
318
|
+
notRead: "未读取"
|
|
319
|
+
}[status] ?? status;
|
|
320
|
+
}
|
|
321
|
+
function enumerationText(enumeration) {
|
|
322
|
+
return {
|
|
323
|
+
complete: "完整枚举",
|
|
324
|
+
partial: "部分枚举",
|
|
325
|
+
failed: "读取失败"
|
|
326
|
+
}[enumeration] ?? enumeration;
|
|
327
|
+
}
|
|
328
|
+
function rangeText(range) {
|
|
329
|
+
return JSON.stringify(range) ?? "null";
|
|
330
|
+
}
|
|
331
|
+
function presentQualityText(report, { input }) {
|
|
332
|
+
const lines = formatQualityReport(report, {
|
|
333
|
+
...input.severity === void 0 ? {} : { severities: input.severity },
|
|
334
|
+
...input.maxPerCheck === void 0 ? {} : { maxPerCheck: input.maxPerCheck }
|
|
335
|
+
}).split("\n");
|
|
336
|
+
return text.lines([lines[0] ?? "", ...lines.slice(1)]);
|
|
337
|
+
}
|
|
338
|
+
function comparisonStatusText(status) {
|
|
339
|
+
return {
|
|
340
|
+
historyMissing: "没有历史参照",
|
|
341
|
+
historyInsufficient: "历史依据不足",
|
|
342
|
+
currentInsufficient: "当前依据不足",
|
|
343
|
+
bothInsufficient: "两侧依据不足",
|
|
344
|
+
added: "新增",
|
|
345
|
+
removed: "移除",
|
|
346
|
+
modified: "已变化",
|
|
347
|
+
unchanged: "未变化"
|
|
348
|
+
}[status] ?? "状态未知";
|
|
349
|
+
}
|
|
350
|
+
const updateActionNames = {
|
|
351
|
+
write: "补入待译占位",
|
|
352
|
+
delete: "删除译文",
|
|
353
|
+
retain: "保留",
|
|
354
|
+
review: "待复核",
|
|
355
|
+
blocked: "暂不可执行"
|
|
356
|
+
};
|
|
357
|
+
function updatePlanText(value) {
|
|
358
|
+
const plan = value;
|
|
359
|
+
const decidedSourceKeys = new Set(plan.items.flatMap((item) => item.changes.source === void 0 ? [] : [item.changes.source.key]));
|
|
360
|
+
const decidedTranslationKeys = new Set(plan.items.flatMap((item) => item.changes.translations.map(({ identity }) => updateIdentityKey(identity))));
|
|
361
|
+
const unassignedSources = plan.comparisons.sourceChanges.filter(({ key, status }) => status !== "unchanged" && !decidedSourceKeys.has(key));
|
|
362
|
+
const unassignedTranslations = plan.comparisons.translationChanges.filter(({ identity, status }) => status !== "unchanged" && !decidedTranslationKeys.has(updateIdentityKey(identity)));
|
|
363
|
+
const unassignedCount = unassignedSources.length + unassignedTranslations.length;
|
|
364
|
+
if (plan.items.length === 0 && unassignedCount === 0) return text.lines(["没有变化,也没有需要处理的更新决定。"]);
|
|
365
|
+
return text.lines([
|
|
366
|
+
`更新预览:${plan.items.length} 项决定,${unassignedCount} 项变化未形成决定。`,
|
|
367
|
+
...plan.items.flatMap((item) => {
|
|
368
|
+
const subject = item.sourceKey === void 0 ? `${item.target?.key ?? "目标"}(${item.language})` : `${item.sourceKey} → ${item.language}`;
|
|
369
|
+
const lines = [`${item.action === "write" && item.changes.source?.status === "modified" ? "重置待译占位" : updateActionNames[item.action] ?? "更新"} ${subject}:${item.reason}`];
|
|
370
|
+
if (item.changes.source !== void 0) {
|
|
371
|
+
const { previous, current, status } = item.changes.source;
|
|
372
|
+
lines.push(` 原文(${comparisonStatusText(status)}):${displayJson(previous?.unit.source)} → ${displayJson(current?.unit.source)}`);
|
|
373
|
+
}
|
|
374
|
+
for (const change of item.changes.translations) {
|
|
375
|
+
const previous = change.previous?.bodyAvailability === "available" ? change.previous.content : change.previous === void 0 ? void 0 : "正文不可用";
|
|
376
|
+
const current = change.current?.bodyAvailability === "available" ? change.current.content : change.current === void 0 ? void 0 : "正文不可用";
|
|
377
|
+
lines.push(` 译文 ${change.identity.key}(${comparisonStatusText(change.status)}):${displayJson(previous)} → ${displayJson(current)}`);
|
|
378
|
+
}
|
|
379
|
+
if (item.after !== void 0) lines.push(` 待写正文:${displayJson(item.after.content)}`);
|
|
380
|
+
return lines;
|
|
381
|
+
}),
|
|
382
|
+
...unassignedCount === 0 ? [] : [
|
|
383
|
+
"未形成更新决定的变化:",
|
|
384
|
+
...unassignedSources.flatMap((change) => [` 原文 ${change.key}(${comparisonStatusText(change.status)}):${displayJson(change.previous?.unit.source)} → ${displayJson(change.current?.unit.source)}`, ` 原因:${unassignedChangeReason("原文", change.status)}`]),
|
|
385
|
+
...unassignedTranslations.flatMap((change) => {
|
|
386
|
+
const previous = change.previous?.bodyAvailability === "available" ? change.previous.content : change.previous === void 0 ? void 0 : "正文不可用";
|
|
387
|
+
const current = change.current?.bodyAvailability === "available" ? change.current.content : change.current === void 0 ? void 0 : "正文不可用";
|
|
388
|
+
return [` 译文 ${change.identity.key}(${comparisonStatusText(change.status)}):${displayJson(previous)} → ${displayJson(current)}`, ` 原因:${unassignedChangeReason("译文", change.status)}`];
|
|
389
|
+
})
|
|
390
|
+
]
|
|
391
|
+
]);
|
|
392
|
+
}
|
|
393
|
+
function unassignedChangeReason(subject, status) {
|
|
394
|
+
if (status === "removed") return `${subject}已从完整范围移除,当前没有对应记录可供处理。`;
|
|
395
|
+
if (status === "added") return `${subject}为本次新增,但没有对应的更新决定。`;
|
|
396
|
+
if (status === "modified") return `${subject}已变化,但没有对应的更新决定。`;
|
|
397
|
+
return `${subject}的变化没有关联到更新决定。`;
|
|
398
|
+
}
|
|
399
|
+
function updateIdentityKey(identity) {
|
|
400
|
+
return JSON.stringify([identity.language, identity.key]);
|
|
401
|
+
}
|
|
402
|
+
function updateResultText(value) {
|
|
403
|
+
const result = value;
|
|
404
|
+
const statusNames = {
|
|
405
|
+
written: "已写入",
|
|
406
|
+
writeUnconfirmed: "写入结果未确认",
|
|
407
|
+
conflict: "目标已变化,未写入",
|
|
408
|
+
notWritable: "当前无法写入",
|
|
409
|
+
writeFailed: "写入失败",
|
|
410
|
+
retained: "已保留",
|
|
411
|
+
review: "待复核",
|
|
412
|
+
blocked: "暂不可执行"
|
|
413
|
+
};
|
|
414
|
+
return text.lines([
|
|
415
|
+
`更新执行${result.status === "completed" ? "完成" : "未完整完成"}:${result.results.length} 项决定。`,
|
|
416
|
+
...result.results.map(({ index, action, status, reason }) => {
|
|
417
|
+
const item = result.plan.items[index];
|
|
418
|
+
const subject = item === void 0 ? `第 ${index + 1} 项` : item.sourceKey === void 0 ? `${item.target?.key ?? "目标"}(${item.language})` : `${item.sourceKey} → ${item.language}`;
|
|
419
|
+
return `${updateActionNames[action] ?? "更新"} ${subject}:${statusNames[status] ?? "未完成"}${reason === void 0 ? "" : `;${reason}`}`;
|
|
420
|
+
}),
|
|
421
|
+
...result.baseline === void 0 ? [] : [result.baseline.outcome === "saved" ? "比较基线已记录。" : result.baseline.outcome === "unchanged" ? "比较基线没有变化。" : result.baseline.message ?? "比较基线未推进。"],
|
|
422
|
+
...result.batchError === void 0 ? [] : [`批量写回抛出异常(逐项实际结果见上):${result.batchError.name}: ${result.batchError.message}`]
|
|
423
|
+
]);
|
|
424
|
+
}
|
|
425
|
+
function cliUpdateResult(result) {
|
|
426
|
+
if (!Object.hasOwn(result, "batchError")) return result;
|
|
427
|
+
const error = result.batchError;
|
|
428
|
+
return {
|
|
429
|
+
...result,
|
|
430
|
+
batchError: {
|
|
431
|
+
name: error instanceof Error ? error.name : "ThrownValue",
|
|
432
|
+
message: error instanceof Error ? error.message : String(error)
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function displayJson(value) {
|
|
437
|
+
return value === void 0 ? "无" : JSON.stringify(value) ?? "无";
|
|
438
|
+
}
|
|
439
|
+
function createCliContract(identity) {
|
|
440
|
+
const define = defineCli();
|
|
441
|
+
return define({
|
|
442
|
+
root: "cli",
|
|
443
|
+
help: helpCapability({
|
|
444
|
+
shortAlias: "-h",
|
|
445
|
+
headings: {
|
|
446
|
+
usage: "用法",
|
|
447
|
+
commands: "命令",
|
|
448
|
+
arguments: "参数",
|
|
449
|
+
options: "选项",
|
|
450
|
+
schema: "契约"
|
|
451
|
+
},
|
|
452
|
+
wording: {
|
|
453
|
+
commandPlaceholder: "命令",
|
|
454
|
+
choices: "候选:{choices}",
|
|
455
|
+
default: "默认:{value}",
|
|
456
|
+
present: "已指定 {field}",
|
|
457
|
+
forbiddenCombination: "{facts} 不可同时使用"
|
|
458
|
+
}
|
|
459
|
+
}),
|
|
460
|
+
version: versionCapability({
|
|
461
|
+
value: text.line(`${identity.commandName} ${identity.version}`),
|
|
462
|
+
shortAlias: "-V"
|
|
463
|
+
}),
|
|
464
|
+
schema: schemaCapability({ description: text.line("输出当前命令或子树的机器可读契约") }),
|
|
465
|
+
usageFailureExitCode: 2,
|
|
466
|
+
commands: {
|
|
467
|
+
cli: {
|
|
468
|
+
kind: "rootGroup",
|
|
469
|
+
name: identity.commandName,
|
|
470
|
+
description: "读取宿主提供的源译事实。"
|
|
471
|
+
},
|
|
472
|
+
...define.command("baseline")({
|
|
473
|
+
kind: "command",
|
|
474
|
+
parent: "cli",
|
|
475
|
+
name: "baseline",
|
|
476
|
+
description: "记录当前完整源译事实作为比较基线。",
|
|
477
|
+
fields: { config: {
|
|
478
|
+
kind: "positional",
|
|
479
|
+
description: "宿主配置文件路径"
|
|
480
|
+
} },
|
|
481
|
+
input: z$1.object({ config: z$1.string() }),
|
|
482
|
+
outputs: ({ atomic }) => {
|
|
483
|
+
const baselineExecution = atomic({
|
|
484
|
+
success: {
|
|
485
|
+
kind: "data",
|
|
486
|
+
variants: { recorded: {
|
|
487
|
+
description: "比较基线记录结果",
|
|
488
|
+
exitCode: 0,
|
|
489
|
+
schema: baselineRecordSchema
|
|
490
|
+
} }
|
|
491
|
+
},
|
|
492
|
+
failures: { recordFailed: {
|
|
493
|
+
description: "记录比较基线失败",
|
|
494
|
+
exitCode: 1,
|
|
495
|
+
schema: z$1.object({
|
|
496
|
+
path: z$1.string(),
|
|
497
|
+
message: z$1.string()
|
|
498
|
+
})
|
|
499
|
+
} },
|
|
500
|
+
async handler({ input, outcome }) {
|
|
501
|
+
const configPath = path.resolve(process.cwd(), input.config);
|
|
502
|
+
const baselinePath = path.join(path.dirname(configPath), "lioni.baseline.json");
|
|
503
|
+
try {
|
|
504
|
+
const result = await recordBaselineForConfig(await loadConfig(configPath), baselinePath);
|
|
505
|
+
const snapshot = result.baseline.snapshot;
|
|
506
|
+
return outcome.data.recorded({
|
|
507
|
+
outcome: result.outcome,
|
|
508
|
+
path: baselinePath,
|
|
509
|
+
sourceScopeCount: snapshot.source.read.scopes.length,
|
|
510
|
+
sourceUnitCount: snapshot.source.units.length,
|
|
511
|
+
translationScopeCount: snapshot.translations.reads.reduce((count, read) => count + read.scopes.length, 0),
|
|
512
|
+
translationRecordCount: snapshot.translations.records.length
|
|
513
|
+
});
|
|
514
|
+
} catch (error) {
|
|
515
|
+
return outcome.failure.recordFailed({
|
|
516
|
+
path: baselinePath,
|
|
517
|
+
message: error instanceof Error ? error.message : String(error)
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
return {
|
|
523
|
+
default: "structured",
|
|
524
|
+
modes: {
|
|
525
|
+
structured: baselineExecution.structured({ description: "输出结构化比较基线记录结果" }),
|
|
526
|
+
text: baselineExecution.text({
|
|
527
|
+
description: "输出终端可读的比较基线记录结果",
|
|
528
|
+
success: { recorded: (result) => text.lines([result.outcome === "saved" ? `比较基线已保存:${result.path}` : `比较基线没有变化:${result.path}`, `原文范围 ${result.sourceScopeCount} 个、原文单元 ${result.sourceUnitCount} 个;译文范围 ${result.translationScopeCount} 个、实际译文 ${result.translationRecordCount} 条。`]) },
|
|
529
|
+
failures: { recordFailed: ({ path: baselinePath, message }) => text.line(`记录比较基线失败(未保存 ${baselinePath}):${message}`) }
|
|
530
|
+
})
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
}),
|
|
535
|
+
...define.command("update")({
|
|
536
|
+
kind: "command",
|
|
537
|
+
parent: "cli",
|
|
538
|
+
name: "update",
|
|
539
|
+
description: "预览更新决定,或按决定写入译文资源。",
|
|
540
|
+
fields: {
|
|
541
|
+
config: {
|
|
542
|
+
kind: "positional",
|
|
543
|
+
description: "宿主配置文件路径"
|
|
544
|
+
},
|
|
545
|
+
languages: languageOption,
|
|
546
|
+
recordBaseline: {
|
|
547
|
+
kind: "flag",
|
|
548
|
+
longOption: "--record-baseline",
|
|
549
|
+
description: "完整更新确认后记录比较基线"
|
|
550
|
+
},
|
|
551
|
+
dryRun: {
|
|
552
|
+
kind: "flag",
|
|
553
|
+
longOption: "--dry-run",
|
|
554
|
+
description: "只预览更新决定"
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
input: z$1.object({
|
|
558
|
+
config: z$1.string(),
|
|
559
|
+
languages: languagesSchema,
|
|
560
|
+
recordBaseline: z$1.optional(z$1.boolean()),
|
|
561
|
+
dryRun: z$1.optional(z$1.boolean())
|
|
562
|
+
}),
|
|
563
|
+
outputs: ({ atomic }) => {
|
|
564
|
+
const updateExecution = atomic({
|
|
565
|
+
success: {
|
|
566
|
+
kind: "data",
|
|
567
|
+
variants: {
|
|
568
|
+
previewed: {
|
|
569
|
+
description: "更新预览",
|
|
570
|
+
exitCode: 0,
|
|
571
|
+
schema: updatePlanSchema
|
|
572
|
+
},
|
|
573
|
+
applied: {
|
|
574
|
+
description: "更新执行结果",
|
|
575
|
+
exitCode: 0,
|
|
576
|
+
schema: updateResultSchema
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
failures: {
|
|
581
|
+
previewFailed: {
|
|
582
|
+
description: "更新预览失败",
|
|
583
|
+
exitCode: 1,
|
|
584
|
+
schema: z$1.object({ message: z$1.string() })
|
|
585
|
+
},
|
|
586
|
+
applyFailed: {
|
|
587
|
+
description: "更新未完整执行",
|
|
588
|
+
exitCode: 1,
|
|
589
|
+
schema: updateResultSchema
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
async handler({ input, outcome }) {
|
|
593
|
+
const configPath = path.resolve(process.cwd(), input.config);
|
|
594
|
+
const baselinePath = path.join(path.dirname(configPath), "lioni.baseline.json");
|
|
595
|
+
try {
|
|
596
|
+
const config = await loadConfig(configPath);
|
|
597
|
+
if (input.dryRun === true) {
|
|
598
|
+
const plan = await previewUpdateForConfig(config, baselinePath, languageSelection(input));
|
|
599
|
+
return outcome.data.previewed(plan);
|
|
600
|
+
}
|
|
601
|
+
const result = await updateForConfig(config, baselinePath, updateSelection(input));
|
|
602
|
+
const cliResult = cliUpdateResult(result);
|
|
603
|
+
return result.status === "completed" ? outcome.data.applied(cliResult) : outcome.failure.applyFailed(cliResult);
|
|
604
|
+
} catch (error) {
|
|
605
|
+
return outcome.failure.previewFailed({ message: error instanceof Error ? error.message : String(error) });
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
return {
|
|
610
|
+
default: "structured",
|
|
611
|
+
modes: {
|
|
612
|
+
structured: updateExecution.structured({ description: "输出结构化更新预览或执行结果" }),
|
|
613
|
+
text: updateExecution.text({
|
|
614
|
+
description: "输出终端可读的更新预览或执行结果",
|
|
615
|
+
success: {
|
|
616
|
+
previewed: updatePlanText,
|
|
617
|
+
applied: updateResultText
|
|
618
|
+
},
|
|
619
|
+
failures: {
|
|
620
|
+
previewFailed: ({ message }) => text.line(`更新预览失败:${message}`),
|
|
621
|
+
applyFailed: updateResultText
|
|
622
|
+
}
|
|
623
|
+
})
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
}),
|
|
628
|
+
...define.command("inspect")({
|
|
629
|
+
kind: "command",
|
|
630
|
+
parent: "cli",
|
|
631
|
+
name: "inspect",
|
|
632
|
+
description: "查看原文、译文及对应关系,了解缺失、冲突和读取情况。",
|
|
633
|
+
fields: {
|
|
634
|
+
config: {
|
|
635
|
+
kind: "positional",
|
|
636
|
+
description: "宿主配置文件路径"
|
|
637
|
+
},
|
|
638
|
+
languages: languageOption
|
|
639
|
+
},
|
|
640
|
+
input: scopedConfigSchema,
|
|
641
|
+
outputs: ({ atomic }) => {
|
|
642
|
+
const inspectExecution = atomic({
|
|
643
|
+
success: {
|
|
644
|
+
kind: "data",
|
|
645
|
+
variants: { read: {
|
|
646
|
+
description: "源译事实",
|
|
647
|
+
exitCode: 0,
|
|
648
|
+
schema: projectSnapshotSchema
|
|
649
|
+
} }
|
|
650
|
+
},
|
|
651
|
+
failures: {
|
|
652
|
+
duplicateIdentity: {
|
|
653
|
+
description: "原文身份重复",
|
|
654
|
+
exitCode: 1,
|
|
655
|
+
schema: z$1.object({
|
|
656
|
+
key: z$1.string(),
|
|
657
|
+
firstIndex: z$1.number(),
|
|
658
|
+
duplicateIndex: z$1.number()
|
|
659
|
+
})
|
|
660
|
+
},
|
|
661
|
+
readFailed: {
|
|
662
|
+
description: "读取原文事实失败",
|
|
663
|
+
exitCode: 1,
|
|
664
|
+
schema: z$1.object({ message: z$1.string() })
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
async handler({ input, outcome }) {
|
|
668
|
+
try {
|
|
669
|
+
const config = await loadConfig(input.config);
|
|
670
|
+
const snapshot = await readProjectSnapshot(config, languageSelection(input));
|
|
671
|
+
return outcome.data.read(projectSnapshotSchema.parse(snapshot));
|
|
672
|
+
} catch (error) {
|
|
673
|
+
if (error instanceof DuplicateTranslationUnitKeyError) return outcome.failure.duplicateIdentity({
|
|
674
|
+
key: error.key,
|
|
675
|
+
firstIndex: error.firstIndex,
|
|
676
|
+
duplicateIndex: error.duplicateIndex
|
|
677
|
+
});
|
|
678
|
+
return outcome.failure.readFailed({ message: error instanceof Error ? error.message : String(error) });
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
return {
|
|
683
|
+
default: "structured",
|
|
684
|
+
modes: {
|
|
685
|
+
structured: inspectExecution.structured({ description: "输出结构化源译事实快照" }),
|
|
686
|
+
text: inspectExecution.text({
|
|
687
|
+
description: "输出终端可读的源译事实快照",
|
|
688
|
+
success: { read: (snapshot) => text.lines([
|
|
689
|
+
`源译事实(已知 ${snapshot.source.units.length} 个原文)`,
|
|
690
|
+
`事实版本:${snapshot.version}`,
|
|
691
|
+
`原文读取:${readStatusText(snapshot.source.read.status)};总数:${snapshot.source.totalUnitCount ?? "未知"}`,
|
|
692
|
+
...snapshot.source.read.scopes.map(({ range, enumeration, recordCount, error }) => `原文范围 ${rangeText(range)}:${enumerationText(enumeration)},发现 ${recordCount} 条${error === void 0 ? "" : `;${error}`}`),
|
|
693
|
+
...snapshot.source.units.flatMap(({ key, unit, bodyAvailability }) => [`- ${key}(正文${bodyAvailability === "available" ? "可用" : "不可用"})`, ` ${JSON.stringify(unit) ?? "null"}`]),
|
|
694
|
+
...snapshot.translations.reads.length === 0 ? ["目标语言:未配置"] : snapshot.translations.reads.flatMap(({ language, status, scopes, error }) => [`目标语言 ${language} 读取:${readStatusText(status)}${error === void 0 ? "" : `;${error}`}`, ...scopes.map(({ range, covers, enumeration, translationIndexes, error: scopeError }) => ` 范围 ${rangeText(range)}:${enumerationText(enumeration)};覆盖 ${covers.join(", ") || "无"};译文 ${translationIndexes.join(", ") || "无"}${scopeError === void 0 ? "" : `;${scopeError}`}`)]),
|
|
695
|
+
...snapshot.translations.records.map(({ index, language, record, bodyAvailability }) => `译文 #${index}(${language},正文${bodyAvailability === "available" ? "可用" : "不可用"}):${JSON.stringify(record) ?? "null"}`),
|
|
696
|
+
...snapshot.associations.map(({ sourceKey, language, status, coverageStatus, scopeIndexes, translationIndexes }) => `关联 ${sourceKey} → ${language}:${status}(覆盖${readStatusText(coverageStatus)},范围 ${scopeIndexes.join(", ") || "无"},译文 ${translationIndexes.join(", ") || "无"})`)
|
|
697
|
+
]) },
|
|
698
|
+
failures: {
|
|
699
|
+
duplicateIdentity: ({ key, firstIndex, duplicateIndex }) => text.line(`原文身份重复:${key}(第 ${firstIndex + 1} 与第 ${duplicateIndex + 1} 个单元)。`),
|
|
700
|
+
readFailed: ({ message }) => text.line(`读取原文事实失败:${message}`)
|
|
701
|
+
}
|
|
702
|
+
})
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
}),
|
|
707
|
+
suppressions: {
|
|
708
|
+
kind: "commandGroup",
|
|
709
|
+
parent: "cli",
|
|
710
|
+
name: "suppressions",
|
|
711
|
+
description: "从 QA 报告维护豁免记录。"
|
|
712
|
+
},
|
|
713
|
+
...define.command("suppressionsUpsert")({
|
|
714
|
+
kind: "command",
|
|
715
|
+
parent: "suppressions",
|
|
716
|
+
name: "upsert",
|
|
717
|
+
description: "从已有 QA 报告创建或更新一条豁免。",
|
|
718
|
+
fields: {
|
|
719
|
+
config: {
|
|
720
|
+
kind: "positional",
|
|
721
|
+
description: "宿主配置文件路径"
|
|
722
|
+
},
|
|
723
|
+
report: {
|
|
724
|
+
kind: "positional",
|
|
725
|
+
description: "SDK 或 CLI QA 报告 JSON 文件路径"
|
|
726
|
+
},
|
|
727
|
+
checkId: {
|
|
728
|
+
kind: "valueOption",
|
|
729
|
+
longOption: "--check-id",
|
|
730
|
+
description: "报告中的检查项身份"
|
|
731
|
+
},
|
|
732
|
+
executionId: {
|
|
733
|
+
kind: "valueOption",
|
|
734
|
+
longOption: "--execution-id",
|
|
735
|
+
description: "报告中的候选执行身份"
|
|
736
|
+
},
|
|
737
|
+
id: {
|
|
738
|
+
kind: "valueOption",
|
|
739
|
+
longOption: "--id",
|
|
740
|
+
description: "豁免身份"
|
|
741
|
+
},
|
|
742
|
+
reason: {
|
|
743
|
+
kind: "valueOption",
|
|
744
|
+
longOption: "--reason",
|
|
745
|
+
description: "豁免理由"
|
|
746
|
+
}
|
|
747
|
+
},
|
|
748
|
+
input: z$1.object({
|
|
749
|
+
config: z$1.string(),
|
|
750
|
+
report: z$1.string(),
|
|
751
|
+
checkId: z$1.string(),
|
|
752
|
+
executionId: z$1.string(),
|
|
753
|
+
id: z$1.string(),
|
|
754
|
+
reason: z$1.string()
|
|
755
|
+
}),
|
|
756
|
+
outputs: ({ atomic }) => {
|
|
757
|
+
const suppressionsExecution = atomic({
|
|
758
|
+
success: {
|
|
759
|
+
kind: "data",
|
|
760
|
+
variants: { upserted: {
|
|
761
|
+
description: "豁免已写入配置选定的存储",
|
|
762
|
+
exitCode: 0,
|
|
763
|
+
schema: z$1.object({
|
|
764
|
+
id: z$1.string(),
|
|
765
|
+
checkId: z$1.string(),
|
|
766
|
+
sourceKey: z$1.string(),
|
|
767
|
+
language: z$1.string(),
|
|
768
|
+
executionId: z$1.number()
|
|
769
|
+
})
|
|
770
|
+
} }
|
|
771
|
+
},
|
|
772
|
+
failures: { upsertFailed: {
|
|
773
|
+
description: "从 QA 报告创建或更新豁免失败",
|
|
774
|
+
exitCode: 1,
|
|
775
|
+
schema: z$1.object({
|
|
776
|
+
path: z$1.string(),
|
|
777
|
+
message: z$1.string()
|
|
778
|
+
})
|
|
779
|
+
} },
|
|
780
|
+
async handler({ input, outcome }) {
|
|
781
|
+
const reportPath = path.resolve(process.cwd(), input.report);
|
|
782
|
+
try {
|
|
783
|
+
const report = JSON.parse(await readFile(reportPath, "utf8"));
|
|
784
|
+
const configPath = path.resolve(process.cwd(), input.config);
|
|
785
|
+
const config = await loadConfig(configPath);
|
|
786
|
+
const executionId = Number(input.executionId);
|
|
787
|
+
const store = config.quality?.suppressionStore;
|
|
788
|
+
if (store === void 0) throw new TypeError("配置未提供 QA 豁免存储。");
|
|
789
|
+
const suppression = await upsertQaSuppressionFromReport({
|
|
790
|
+
report,
|
|
791
|
+
checkId: input.checkId,
|
|
792
|
+
executionId,
|
|
793
|
+
id: input.id,
|
|
794
|
+
reason: input.reason,
|
|
795
|
+
store
|
|
796
|
+
});
|
|
797
|
+
return outcome.data.upserted({
|
|
798
|
+
id: suppression.id,
|
|
799
|
+
checkId: suppression.checkId,
|
|
800
|
+
sourceKey: suppression.sourceKey,
|
|
801
|
+
language: suppression.language,
|
|
802
|
+
executionId
|
|
803
|
+
});
|
|
804
|
+
} catch (error) {
|
|
805
|
+
return outcome.failure.upsertFailed({
|
|
806
|
+
path: reportPath,
|
|
807
|
+
message: error instanceof Error ? error.message : String(error)
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
return {
|
|
813
|
+
default: "structured",
|
|
814
|
+
modes: {
|
|
815
|
+
structured: suppressionsExecution.structured({ description: "输出结构化豁免更新结果" }),
|
|
816
|
+
text: suppressionsExecution.text({
|
|
817
|
+
description: "输出终端可读的豁免更新结果",
|
|
818
|
+
success: { upserted: ({ id, checkId, sourceKey, language, executionId }) => text.line(`豁免 ${id} 已更新:${checkId} ${sourceKey} → ${language}(执行 ${executionId})。`) },
|
|
819
|
+
failures: { upsertFailed: ({ path: reportPath, message }) => text.line(`根据报告 ${reportPath} 更新 QA 豁免失败:${message}`) }
|
|
820
|
+
})
|
|
821
|
+
}
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
}),
|
|
825
|
+
...define.command("qa")({
|
|
826
|
+
kind: "command",
|
|
827
|
+
parent: "cli",
|
|
828
|
+
name: "qa",
|
|
829
|
+
description: "默认输出简洁中文质量报告;使用 --output structured 查看完整结构化结果。",
|
|
830
|
+
fields: {
|
|
831
|
+
config: {
|
|
832
|
+
kind: "positional",
|
|
833
|
+
description: "宿主配置文件路径"
|
|
834
|
+
},
|
|
835
|
+
languages: languageOption,
|
|
836
|
+
checks: checkOption,
|
|
837
|
+
groups: groupOption,
|
|
838
|
+
severity: severityOption,
|
|
839
|
+
maxPerCheck: maxPerCheckOption
|
|
840
|
+
},
|
|
841
|
+
input: qaConfigSchema,
|
|
842
|
+
usageConstraints: [{
|
|
843
|
+
kind: "forbiddenCombination",
|
|
844
|
+
all: [{
|
|
845
|
+
kind: "present",
|
|
846
|
+
field: "checks"
|
|
847
|
+
}, {
|
|
848
|
+
kind: "present",
|
|
849
|
+
field: "groups"
|
|
850
|
+
}]
|
|
851
|
+
}],
|
|
852
|
+
outputs: ({ atomic }) => {
|
|
853
|
+
const qaExecution = atomic({
|
|
854
|
+
success: {
|
|
855
|
+
kind: "data",
|
|
856
|
+
variants: {
|
|
857
|
+
checked: {
|
|
858
|
+
description: "质量检查通过",
|
|
859
|
+
exitCode: 0,
|
|
860
|
+
schema: qualityRunResultSchema
|
|
861
|
+
},
|
|
862
|
+
notPassed: {
|
|
863
|
+
description: "质量检查未通过",
|
|
864
|
+
exitCode: 1,
|
|
865
|
+
schema: qualityRunResultSchema
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
},
|
|
869
|
+
failures: { checkFailed: {
|
|
870
|
+
description: "读取事实或执行质量检查失败",
|
|
871
|
+
exitCode: 1,
|
|
872
|
+
schema: z$1.object({ message: z$1.string() })
|
|
873
|
+
} },
|
|
874
|
+
async handler({ input, outcome }) {
|
|
875
|
+
try {
|
|
876
|
+
const config = await loadConfig(input.config);
|
|
877
|
+
const result = await runQa(config, {
|
|
878
|
+
...languageSelection(input),
|
|
879
|
+
...qualityCheckSelection(input)
|
|
880
|
+
});
|
|
881
|
+
const validated = qualityRunResultSchema.parse(result);
|
|
882
|
+
return decideQualityReport(result).passed ? outcome.data.checked(validated) : outcome.data.notPassed(validated);
|
|
883
|
+
} catch (error) {
|
|
884
|
+
return outcome.failure.checkFailed({ message: error instanceof Error ? error.message : String(error) });
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
});
|
|
888
|
+
return {
|
|
889
|
+
default: "text",
|
|
890
|
+
modes: {
|
|
891
|
+
text: qaExecution.text({
|
|
892
|
+
description: "输出终端可读的中文质量报告",
|
|
893
|
+
success: {
|
|
894
|
+
checked: presentQualityText,
|
|
895
|
+
notPassed: presentQualityText
|
|
896
|
+
},
|
|
897
|
+
failures: { checkFailed: ({ message }) => {
|
|
898
|
+
const [first, ...details] = message.split(/\r?\n/u);
|
|
899
|
+
return text.lines([`质量检查失败:${first}`, ...details]);
|
|
900
|
+
} }
|
|
901
|
+
}),
|
|
902
|
+
structured: qaExecution.structured({ description: "输出完整结构化 QA 报告" })
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
}
|
|
906
|
+
})
|
|
907
|
+
}
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
function recordBaselineForConfig(config, baselinePath) {
|
|
911
|
+
const store = createFileComparisonBaselineStore(baselinePath);
|
|
912
|
+
return recordComparisonBaseline(config, store);
|
|
913
|
+
}
|
|
914
|
+
function previewUpdateForConfig(config, baselinePath, options) {
|
|
915
|
+
const store = createFileComparisonBaselineStore(baselinePath);
|
|
916
|
+
return previewUpdate(config, store, options);
|
|
917
|
+
}
|
|
918
|
+
function updateForConfig(config, baselinePath, options) {
|
|
919
|
+
const store = createFileComparisonBaselineStore(baselinePath);
|
|
920
|
+
return update(config, store, options);
|
|
921
|
+
}
|
|
922
|
+
function updateSelection(input) {
|
|
923
|
+
return {
|
|
924
|
+
...languageSelection(input),
|
|
925
|
+
...input.recordBaseline === void 0 ? {} : { recordBaseline: input.recordBaseline }
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
async function runCli(runtime) {
|
|
929
|
+
try {
|
|
930
|
+
const contract = createCliContract(runtime.identity);
|
|
931
|
+
return (await executeCli(contract, {
|
|
932
|
+
invocation: parseCliInvocation(contract, runtime.argv.slice(2)),
|
|
933
|
+
dependencies: void 0,
|
|
934
|
+
write: runtime.write
|
|
935
|
+
})).exitCode;
|
|
936
|
+
} catch (error) {
|
|
937
|
+
if (error instanceof CliWriteError && error.destination === "stdout" && isNodeBrokenPipe(error)) return 0;
|
|
938
|
+
try {
|
|
939
|
+
await runtime.write({
|
|
940
|
+
destination: "stderr",
|
|
941
|
+
chunk: "命令执行失败;请检查运行环境或报告此问题。\n"
|
|
942
|
+
});
|
|
943
|
+
} catch {}
|
|
944
|
+
return 70;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
// src/cli.ts
|
|
948
|
+
const require = createRequire(import.meta.url);
|
|
949
|
+
process.exitCode = await runCli({
|
|
950
|
+
argv: process.argv,
|
|
951
|
+
write: nodeCliOutput({
|
|
952
|
+
stdout: process.stdout,
|
|
953
|
+
stderr: process.stderr
|
|
954
|
+
}),
|
|
955
|
+
get identity() {
|
|
956
|
+
return cliCommandIdentity(require("../package.json"));
|
|
957
|
+
}
|
|
958
|
+
});
|
|
959
|
+
export {};
|