@langlink/l10n-mcp 0.5.0 → 0.6.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.js CHANGED
@@ -631,6 +631,7 @@ AIQA \u6A21\u578B\u5224\u5B9A\u5931\u8D25\uFF08${existing.reason}\uFF09\uFF0C\u7
631
631
  }
632
632
  });
633
633
  }
634
+ return bySegment;
634
635
  }
635
636
 
636
637
  // packages/l10n-core/src/xml.ts
@@ -1223,9 +1224,14 @@ function inlineCharacter(node) {
1223
1224
  return void 0;
1224
1225
  }
1225
1226
  }
1226
- function inlineText(root) {
1227
+ function inlineText(root, onPart) {
1227
1228
  const namespace = root.namespaceUri ?? "";
1228
- const walk = (node) => node.children.map((child) => child.type === "text" ? child.cdata ? child.text : decodeXmlEntities(child.text) : container(child, namespace) ? walk(child) : inlineCharacter(child) ?? "").join("");
1229
+ const walk = (node) => node.children.map((child) => {
1230
+ if (child.type === "element" && container(child, namespace)) return walk(child);
1231
+ const text = child.type === "element" ? inlineCharacter(child) ?? "" : child.cdata ? child.text : decodeXmlEntities(child.text);
1232
+ onPart?.(text, child);
1233
+ return text;
1234
+ }).join("");
1229
1235
  return walk(root);
1230
1236
  }
1231
1237
  function codeIdentity(node, native = true, namespace = node.namespaceUri ?? "") {
@@ -1275,6 +1281,14 @@ function codes(root, xml) {
1275
1281
  walk(root);
1276
1282
  return result;
1277
1283
  }
1284
+ function inlineCodeLocations(root) {
1285
+ const namespace = root.namespaceUri ?? "";
1286
+ return codes(root, "").map(({ node, close }) => ({
1287
+ key: (close ? "/" : "") + codeIdentity(node, true, namespace),
1288
+ start: (close ? node.innerEnd : node.start) - root.innerStart,
1289
+ end: (close || !container(node, namespace) ? node.end : node.openEnd) - root.innerStart
1290
+ }));
1291
+ }
1278
1292
  function inlineCodeOrderError(source, target) {
1279
1293
  const sourceCodes = codes(source, ""), targetCodes = codes(target, "");
1280
1294
  const namespace = source.namespaceUri ?? "";
@@ -1745,12 +1759,14 @@ function extractNumbers(value) {
1745
1759
  [...extractDates(normalized).map((token) => token.span), ...collectPlaceholders(normalized)]
1746
1760
  );
1747
1761
  const results = [];
1748
- for (const match of masked.matchAll(NUMBER_RE)) results.push(normalizeNumber(match[0]));
1762
+ for (const match of masked.matchAll(NUMBER_RE)) {
1763
+ results.push({ key: normalizeNumber(match[0]), start: match.index, end: match.index + match[0].length });
1764
+ }
1749
1765
  return results;
1750
1766
  }
1751
1767
  function checkNumbers(context) {
1752
- const sourceNumbers = extractNumbers(context.source);
1753
- const targetNumbers = extractNumbers(context.target);
1768
+ const sourceNumbers = extractNumbers(context.source).map((token) => token.key);
1769
+ const targetNumbers = extractNumbers(context.target).map((token) => token.key);
1754
1770
  if (sourceNumbers.length === 0 && targetNumbers.length === 0) return;
1755
1771
  const delta = multisetDelta(sourceNumbers, targetNumbers);
1756
1772
  if (delta.missing.length === 0 && delta.extra.length === 0) return;
@@ -2659,6 +2675,107 @@ function runDeterministicChecks(segments, options = {}) {
2659
2675
  rules
2660
2676
  };
2661
2677
  }
2678
+ function unmatched(own, other, key) {
2679
+ const available = multiset(other.map(key));
2680
+ return own.filter((token) => {
2681
+ const id = key(token);
2682
+ const count = available.get(id) ?? 0;
2683
+ if (count === 0) return true;
2684
+ available.set(id, count - 1);
2685
+ return false;
2686
+ });
2687
+ }
2688
+ function displayedTextSpans(segment, side, spans) {
2689
+ const node = side === "source" ? segment.sourceNode : segment.targetNode;
2690
+ const tags = side === "source" ? segment.sourceTags : segment.targetTags;
2691
+ if (!node || tags.length === 0 || spans.length === 0) return [...spans];
2692
+ const result = [];
2693
+ let textOffset = 0;
2694
+ inlineText(node, (text, part) => {
2695
+ const partEnd = textOffset + text.length;
2696
+ for (const span of spans) {
2697
+ const start = Math.max(span.start, textOffset) - textOffset;
2698
+ const end = Math.min(span.end, partEnd) - textOffset;
2699
+ if (start >= end) continue;
2700
+ const base = part.start - node.innerStart;
2701
+ if (part.type === "element") {
2702
+ result.push({ start: base, end: part.end - node.innerStart });
2703
+ } else {
2704
+ let delta = 0;
2705
+ let rawStart = start;
2706
+ let rawEnd = end;
2707
+ if (!part.cdata) {
2708
+ for (const entity of part.text.matchAll(/&(?:#x[0-9a-fA-F]+|#\d+|amp|lt|gt|quot|apos);/gu)) {
2709
+ const entityStart = entity.index - delta;
2710
+ const length = decodeXmlEntities(entity[0]).length;
2711
+ const extra = entity[0].length - length;
2712
+ if (entityStart + length <= start) rawStart += extra;
2713
+ else if (entityStart < start) rawStart = entity.index;
2714
+ if (entityStart < end) rawEnd = Math.max(rawEnd + extra, entity.index + entity[0].length);
2715
+ delta += extra;
2716
+ }
2717
+ }
2718
+ result.push({ start: base + rawStart, end: base + rawEnd });
2719
+ }
2720
+ }
2721
+ textOffset = partEnd;
2722
+ });
2723
+ return result;
2724
+ }
2725
+ function reviewIssueHighlights(segment, issue) {
2726
+ switch (issue.ruleId) {
2727
+ case "TAG_MISMATCH": {
2728
+ const source = segment.sourceNode ? inlineCodeLocations(segment.sourceNode) : [];
2729
+ const target = segment.targetNode ? inlineCodeLocations(segment.targetNode) : [];
2730
+ const sourceOnly = unmatched(source, target, (token) => token.key);
2731
+ const targetOnly = unmatched(target, source, (token) => token.key);
2732
+ if (sourceOnly.length || targetOnly.length) return { source: sourceOnly, target: targetOnly };
2733
+ return {
2734
+ source: source.filter((token, index) => token.key !== target[index]?.key),
2735
+ target: target.filter((token, index) => token.key !== source[index]?.key)
2736
+ };
2737
+ }
2738
+ case "PLACEHOLDER_MISSING":
2739
+ case "PLACEHOLDER_EXTRA": {
2740
+ const source = collectPlaceholders(segment.sourceInner);
2741
+ const target = collectPlaceholders(segment.targetInner);
2742
+ const side = issue.ruleId === "PLACEHOLDER_MISSING" ? "source" : "target";
2743
+ const tokens = side === "source" ? unmatched(source, target, (token) => token.text) : unmatched(target, source, (token) => token.text);
2744
+ const display = side === "source" ? segment.sourceTags.length ? segment.sourceInner : segment.sourceText : segment.targetTags.length ? segment.targetInner : segment.targetText;
2745
+ const inner = side === "source" ? segment.sourceInner : segment.targetInner;
2746
+ if (display === inner) return { [side]: tokens };
2747
+ const remaining = multiset(tokens.map((token) => decodeXmlEntities(token.text)));
2748
+ return { [side]: collectPlaceholders(display).reverse().filter(({ text }) => {
2749
+ const count = remaining.get(text) ?? 0;
2750
+ if (!count) return false;
2751
+ remaining.set(text, count - 1);
2752
+ return true;
2753
+ }) };
2754
+ }
2755
+ case "NUMBER_MISMATCH": {
2756
+ const source = extractNumbers(segment.sourceText);
2757
+ const target = extractNumbers(segment.targetText);
2758
+ return {
2759
+ source: displayedTextSpans(segment, "source", unmatched(source, target, (token) => token.key)),
2760
+ target: displayedTextSpans(segment, "target", unmatched(target, source, (token) => token.key))
2761
+ };
2762
+ }
2763
+ case "DATE_MISMATCH": {
2764
+ const source = extractDates(segment.sourceText);
2765
+ const target = extractDates(segment.targetText);
2766
+ return {
2767
+ source: displayedTextSpans(segment, "source", unmatched(source, target, (token) => token.key).map((token) => token.span)),
2768
+ target: displayedTextSpans(segment, "target", unmatched(target, source, (token) => token.key).map((token) => token.span))
2769
+ };
2770
+ }
2771
+ case "UNPAIRED_BRACKET":
2772
+ return { target: displayedTextSpans(segment, "target", unpairedTokens(segment.targetText).slice(0, 5).map(({ index }) => ({ start: index, end: index + 1 }))) };
2773
+ case "PUNCT_DUP":
2774
+ return issue.targetRange ? { target: displayedTextSpans(segment, "target", [issue.targetRange]) } : {};
2775
+ default:
2776
+ return {};
2777
+ }
2778
+ }
2662
2779
 
2663
2780
  // packages/l10n-core/src/workflows/check.ts
2664
2781
  function termMatchOptions(document2, segment) {
@@ -2973,8 +3090,14 @@ function reviewDocument(file, document2, options, prefix) {
2973
3090
  const candidate = issue.ruleId === "UNTRANSLATED_COPY";
2974
3091
  const segment = indexed.get(issue.segmentId);
2975
3092
  const same = segment.sourceText === segment.targetText ? "\u539F\u8BD1\u5B8C\u5168\u76F8\u540C" : "\u539F\u8BD1\u7ECF\u5F52\u4E00\u5316\u540E\u76F8\u540C";
3093
+ const highlights = reviewIssueHighlights(segment, issue);
3094
+ const spans = (ranges) => ranges.map(({ start, end }) => ({ start, end }));
2976
3095
  return {
2977
3096
  ...segmentLocation(file, document2, segment, prefix),
3097
+ ...highlights.source?.length || highlights.target?.length ? { highlights: {
3098
+ ...highlights.source?.length ? { source: spans(highlights.source) } : {},
3099
+ ...highlights.target?.length ? { target: spans(highlights.target) } : {}
3100
+ } } : {},
2978
3101
  category: categories.get(issue.ruleId),
2979
3102
  severity: candidate ? "neutral" : issue.severity,
2980
3103
  rule: issue.ruleId,
@@ -3037,6 +3160,9 @@ async function runQaReview(files, options, onDocument) {
3037
3160
  // packages/l10n-core/src/qa/review-aiqa.ts
3038
3161
  var AIQA_SELECTION_LIMIT = 20;
3039
3162
  var REVIEW_FORCE_RULES = /* @__PURE__ */ new Map([["EMPTY_TARGET", "OMI"], ["PROJECT_REQUIREMENT", "STY"]]);
3163
+ function reviewAiqaSystemPrompt() {
3164
+ return aiqaSystemPrompt() + "\n\n\u53CC\u8BED QA \u62A5\u544A\u4F1A\u628A\u5224\u65AD\u4F9D\u636E\u4F5C\u4E3A AI \u8BC4\u8BBA\u3002\u6536\u5230 deterministic_observations \u65F6\uFF0C\u5728 evidence \u6216 review_reason \u7ED3\u5408\u539F\u8BD1\u6587\u8BF4\u660E\u54EA\u4E9B\u57FA\u7840 QA \u63D0\u793A\u6210\u7ACB\u3001\u54EA\u4E9B\u5C5E\u4E8E\u5408\u7406\u5DEE\u5F02\u3001\u54EA\u4E9B\u4ECD\u9700\u786E\u8BA4\uFF1B\u5982\u56E0\u5176\u4ED6\u95EE\u9898\u5EFA\u8BAE\u4EBA\u5DE5\u5BA1\u6838\uFF0C\u4E5F\u8BF7\u6307\u51FA\u5177\u4F53\u95EE\u9898\u3002";
3165
+ }
3040
3166
  function configuredReviewAiqa() {
3041
3167
  const model = process.env.L10N_AIQA_MODEL?.trim();
3042
3168
  const baseUrl = process.env.APERTURE_BASE_URL?.trim();
@@ -3120,7 +3246,7 @@ function prepareReviewAiqa({ document: document2, keyPrefix }, options, styleGui
3120
3246
  }
3121
3247
  const neighbors = new Map(document2.segments.map((segment) => [segment.index, segment]));
3122
3248
  const proven = /* @__PURE__ */ new Map();
3123
- mergeDeterministicIssues(proven, [
3249
+ const confirmedIssues = mergeDeterministicIssues(proven, [
3124
3250
  ...qa.issues,
3125
3251
  ...chosen.flatMap((segment) => configuredFindings(options, segment))
3126
3252
  ], REVIEW_FORCE_RULES);
@@ -3128,7 +3254,8 @@ function prepareReviewAiqa({ document: document2, keyPrefix }, options, styleGui
3128
3254
  const key = keyFor(segment);
3129
3255
  const outcome = proven.get(segment.id);
3130
3256
  if (outcome) {
3131
- prepared.set(key, { kind: "result", outcome });
3257
+ const summary = [...new Set(confirmedIssues.get(segment.id)?.map((issue) => issue.message))].join("\uFF1B");
3258
+ prepared.set(key, { kind: "result", outcome: { ...outcome, summary } });
3132
3259
  continue;
3133
3260
  }
3134
3261
  const metadata = document2.files[segment.location.fileIndex];
@@ -3191,7 +3318,7 @@ async function runReviewAiqa(files, options, keys, styleGuide, provider, signal)
3191
3318
  continue;
3192
3319
  }
3193
3320
  try {
3194
- results.set(key, parseAiqaReply(item.input.segmentId, await provider.complete(aiqaSystemPrompt(), prompt, signal)));
3321
+ results.set(key, parseAiqaReply(item.input.segmentId, await provider.complete(reviewAiqaSystemPrompt(), prompt, signal)));
3195
3322
  } catch (error) {
3196
3323
  signal.throwIfAborted();
3197
3324
  results.set(key, { kind: "failed", reason: error instanceof Error ? error.message.slice(0, 200) : "\u6A21\u578B\u8BF7\u6C42\u5931\u8D25\u3002" });
@@ -3202,6 +3329,172 @@ async function runReviewAiqa(files, options, keys, styleGuide, provider, signal)
3202
3329
  return keys.map((segmentKey) => ({ segmentKey, outcome: results.get(segmentKey) }));
3203
3330
  }
3204
3331
 
3332
+ // packages/l10n-core/src/qa/review-page.ts
3333
+ import { readFileSync } from "node:fs";
3334
+ import { createRequire } from "node:module";
3335
+
3336
+ // packages/l10n-core/src/qa/review-presentation.ts
3337
+ function createReviewPresentation() {
3338
+ const ruleLabels = /* @__PURE__ */ new Map([
3339
+ ["UNPAIRED_BRACKET", "\u62EC\u53F7\u6216\u5F15\u53F7\u4E0D\u914D\u5BF9"],
3340
+ ["PUNCT_DUP", "\u6807\u70B9\u91CD\u590D"],
3341
+ ["WHITESPACE", "\u7A7A\u683C\u5F02\u5E38"],
3342
+ ["TAG_MISMATCH", "\u6807\u7B7E\u4E0D\u4E00\u81F4"],
3343
+ ["PLACEHOLDER_MISSING", "\u7F3A\u5C11\u5360\u4F4D\u7B26"],
3344
+ ["PLACEHOLDER_EXTRA", "\u591A\u51FA\u5360\u4F4D\u7B26"],
3345
+ ["NUMBER_MISMATCH", "\u6570\u5B57\u4E0D\u4E00\u81F4"],
3346
+ ["DATE_MISMATCH", "\u65E5\u671F\u4E0D\u4E00\u81F4"],
3347
+ ["EMPTY_TARGET", "\u7A7A\u8BD1\u6216\u6B63\u6587\u7F3A\u5931"],
3348
+ ["UNTRANSLATED_COPY", "\u539F\u8BD1\u76F8\u540C"]
3349
+ ]);
3350
+ const aiTypeLabels = /* @__PURE__ */ new Map([
3351
+ ["ACC", "\u8BED\u4E49\u9519\u8BEF"],
3352
+ ["OMI", "\u6F0F\u8BD1"],
3353
+ ["ADD", "\u591A\u8BD1\u6216\u865A\u6784"],
3354
+ ["TER", "\u672F\u8BED\u9519\u8BEF"],
3355
+ ["NUM", "\u6570\u5B57\u3001\u65E5\u671F\u6216\u5355\u4F4D\u9519\u8BEF"],
3356
+ ["ENT", "\u5B9E\u4F53\u9519\u8BEF"],
3357
+ ["CTX", "\u4E0A\u4E0B\u6587\u9519\u8BEF"],
3358
+ ["FLU", "\u8BED\u8A00\u8D28\u91CF\u95EE\u9898"],
3359
+ ["STY", "\u8FDD\u53CD\u98CE\u683C\u8981\u6C42"],
3360
+ ["LOC", "\u672C\u5730\u5316\u95EE\u9898"],
3361
+ ["TEC", "\u6280\u672F\u683C\u5F0F\u9519\u8BEF"],
3362
+ ["UNC", "\u4FE1\u606F\u4E0D\u8DB3"]
3363
+ ]);
3364
+ const verdictLabels = /* @__PURE__ */ new Map([
3365
+ ["AUTO_PASS", "\u5EFA\u8BAE\u901A\u8FC7"],
3366
+ ["HUMAN_REVIEW", "\u4EBA\u5DE5\u5BA1\u6838"],
3367
+ ["AIQA_UNAVAILABLE", "\u65E0\u6CD5\u5224\u5B9A"],
3368
+ ["AIQA_PENDING", "\u5C1A\u672A\u5B8C\u6210"]
3369
+ ]);
3370
+ const collator = new Intl.Collator(void 0, { numeric: true });
3371
+ function segmentKey(row) {
3372
+ return row.segmentKey ?? JSON.stringify([row.file, row.segment]);
3373
+ }
3374
+ function ruleLabel(finding) {
3375
+ if (finding.category === "AIQA") return "AIQA";
3376
+ return (finding.category === "\u81EA\u5B9A\u4E49" ? void 0 : ruleLabels.get(finding.rule)) ?? finding.rule;
3377
+ }
3378
+ function aiStatusKey(finding) {
3379
+ return verdictLabels.has(finding.rule) ? finding.rule : finding.message;
3380
+ }
3381
+ function aiStatus(finding) {
3382
+ return verdictLabels.get(aiStatusKey(finding)) ?? finding.message;
3383
+ }
3384
+ function aiTypes(finding) {
3385
+ return finding.rule.split(/,\s*/u).flatMap((code) => {
3386
+ const label = aiTypeLabels.get(code);
3387
+ return label ? [label] : [];
3388
+ });
3389
+ }
3390
+ function aiComment(aiqa) {
3391
+ if (!aiqa) return "";
3392
+ const summary = typeof aiqa.aiqaSummary === "string" ? aiqa.aiqaSummary : "";
3393
+ const note = (summary || aiqa.evidence.split(/^确定性QA:/mu, 1)[0] || "").replace(/\s+/gu, " ").trim();
3394
+ if (!note) return aiqa.evidence ? "\u8BF7\u67E5\u770B\u5B8C\u6574\u4F9D\u636E\u3002" : "";
3395
+ const characters = Array.from(note);
3396
+ return characters.length > 100 ? characters.slice(0, 99).join("") + "\u2026" : note;
3397
+ }
3398
+ function textParts(value, findings, side) {
3399
+ const ranges = findings.flatMap((finding) => {
3400
+ const spans = finding.highlights?.[side];
3401
+ if (!Array.isArray(spans)) return [];
3402
+ return spans.filter((span) => span && Number.isSafeInteger(span.start) && Number.isSafeInteger(span.end) && span.start >= 0 && span.start < span.end && span.end <= value.length);
3403
+ }).sort((left, right) => left.start - right.start || left.end - right.end);
3404
+ if (!ranges.length) {
3405
+ return [{ text: value, marked: false }];
3406
+ }
3407
+ const merged = [];
3408
+ for (const span of ranges) {
3409
+ const previous = merged.at(-1);
3410
+ if (previous && span.start < previous.end) previous.end = Math.max(previous.end, span.end);
3411
+ else merged.push({ ...span });
3412
+ }
3413
+ const parts = [];
3414
+ let cursor = 0;
3415
+ for (const { start, end } of merged) {
3416
+ if (start > cursor) parts.push({ text: value.slice(cursor, start), marked: false });
3417
+ parts.push({ text: value.slice(start, end), marked: true });
3418
+ cursor = end;
3419
+ }
3420
+ if (cursor < value.length) parts.push({ text: value.slice(cursor), marked: false });
3421
+ return parts;
3422
+ }
3423
+ function collectSections(matches, rows = matches) {
3424
+ const aiqaBySegment = new Map(rows.filter((row) => row.category === "AIQA").map((row) => [segmentKey(row), row]));
3425
+ const rules = /* @__PURE__ */ new Map();
3426
+ const shown = /* @__PURE__ */ new Set();
3427
+ const included = /* @__PURE__ */ new Set();
3428
+ for (const finding of matches) {
3429
+ if (finding.category === "AIQA") continue;
3430
+ const ruleKey = JSON.stringify([finding.category, finding.rule]);
3431
+ let section = rules.get(ruleKey);
3432
+ if (!section) {
3433
+ section = { label: ruleLabel(finding), entries: /* @__PURE__ */ new Map() };
3434
+ rules.set(ruleKey, section);
3435
+ }
3436
+ const key = segmentKey(finding);
3437
+ let entry = section.entries.get(key);
3438
+ if (!entry) {
3439
+ const aiqa = aiqaBySegment.get(key);
3440
+ entry = { segment: finding, findings: [], ...aiqa ? { aiqa } : {} };
3441
+ section.entries.set(key, entry);
3442
+ if (aiqa) included.add(aiqa);
3443
+ }
3444
+ entry.findings.push(finding);
3445
+ included.add(finding);
3446
+ shown.add(key);
3447
+ }
3448
+ const sections = new Map([...rules].sort(([, left], [, right]) => collator.compare(left.label, right.label)));
3449
+ const aiqaEntries = /* @__PURE__ */ new Map();
3450
+ for (const verdict of matches) {
3451
+ if (verdict.category !== "AIQA") continue;
3452
+ const key = segmentKey(verdict);
3453
+ if (shown.has(key)) continue;
3454
+ aiqaEntries.set(key, { segment: verdict, findings: [], aiqa: verdict });
3455
+ included.add(verdict);
3456
+ shown.add(key);
3457
+ }
3458
+ if (aiqaEntries.size) sections.set("aiqa", { label: "AIQA", entries: aiqaEntries });
3459
+ return { sections, shown, filtered: [...included] };
3460
+ }
3461
+ return { ruleLabel, aiStatus, aiStatusKey, aiTypes, aiComment, textParts, collectSections };
3462
+ }
3463
+
3464
+ // packages/l10n-core/src/qa/review-xlsx.ts
3465
+ async function writeReviewXlsx(Workbook, rows, { collectSections, aiStatus, aiTypes, aiComment, textParts }) {
3466
+ const { sections } = collectSections(rows);
3467
+ const total = [...sections.values()].reduce((count, section) => count + section.entries.size, 0);
3468
+ const limitMessage = "\u7ED3\u679C\u8D85\u8FC7 Excel \u7684\u884C\u6570\u6216\u5355\u5143\u683C\u957F\u5EA6\u9650\u5236\uFF0C\u8BF7\u7F29\u5C0F\u5BFC\u51FA\u8303\u56F4\u3002";
3469
+ if (total > 1048575) throw new Error(limitMessage);
3470
+ const workbook = new Workbook();
3471
+ const sheet = workbook.addWorksheet("QA", { views: [{ state: "frozen", ySplit: 1 }] });
3472
+ const headers = ["\u89C4\u5219\u7C7B\u522B", "\u6587\u4EF6", "\u53E5\u6BB5\u7F16\u53F7", "\u539F\u6587", "\u8BD1\u6587", "\u8BC4\u8BBA", "AI QA \u7ED3\u679C", "AI \u8BC4\u8BBA"];
3473
+ const widths = [23, 31, 14, 42, 42, 42, 21, 64];
3474
+ sheet.columns = headers.map((header, index) => ({
3475
+ header,
3476
+ width: widths[index],
3477
+ style: { alignment: { vertical: "top", wrapText: true } }
3478
+ }));
3479
+ for (const { label, entries } of sections.values()) {
3480
+ for (const { segment, findings, aiqa } of entries.values()) {
3481
+ const verdict = aiqa ? [aiStatus(aiqa), aiTypes(aiqa).join("\u3001")].filter(Boolean).join("\n") : "\u672A\u5BA1\u6821";
3482
+ const comments = [...new Set(findings.map((finding) => finding.message))].join("\n");
3483
+ const values = [label, segment.file, segment.segment, segment.source, segment.target, comments, verdict, aiComment(aiqa)];
3484
+ if (values.some((value) => value.length > 32767)) throw new Error(limitMessage);
3485
+ const row = sheet.addRow(values);
3486
+ for (const [column, side] of [[4, "source"], [5, "target"]]) {
3487
+ const parts = textParts(segment[side], findings, side);
3488
+ if (!parts.some(({ marked }) => marked)) continue;
3489
+ row.getCell(column).value = { richText: parts.map(({ text, marked }) => marked ? { text, font: { color: { argb: "FFA22628" }, bold: true, underline: true } } : { text }) };
3490
+ }
3491
+ }
3492
+ }
3493
+ sheet.getRow(1).font = { bold: true };
3494
+ sheet.autoFilter = { from: { row: 1, column: 1 }, to: { row: Math.max(2, sheet.rowCount), column: headers.length } };
3495
+ return new Uint8Array(await workbook.xlsx.writeBuffer());
3496
+ }
3497
+
3205
3498
  // packages/l10n-core/src/qa/review-page.ts
3206
3499
  var styles = `
3207
3500
  :root { color-scheme: light; --paper: #f4f6f9; --ink: #192438; --muted: #4b5a6f;
@@ -3243,30 +3536,48 @@ var styles = `
3243
3536
  .filters { margin: 8px 0 12px; }
3244
3537
  .filters .field, .exports .field { flex: 1 1 125px; margin: 0; font-size: 13px; }
3245
3538
  .filters .search { flex-basis: 180px; }
3246
- .exports { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 14px; align-items: end; }
3539
+ .exports { margin-bottom: 14px; }
3247
3540
  .exports .field { flex: 0 1 150px; }
3248
- .table { overflow: auto; max-height: 64vh; border: 1px solid var(--border); border-radius: 8px; }
3249
- table { width: 100%; min-width: 680px; border-collapse: collapse; table-layout: fixed; text-align: left; font-size: 13px; }
3541
+ .rule-section { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; }
3542
+ .rule-section > summary { background: #edf2f8; padding: 9px 12px; border-radius: 7px; }
3543
+ .rule-section[open] > summary { border-bottom: 1px solid var(--border); border-radius: 7px 7px 0 0; }
3544
+ .rule-count { color: var(--muted); font-weight: 400; margin-left: 8px; }
3545
+ .table { overflow: auto; max-height: 64vh; }
3546
+ table { width: 100%; min-width: 800px; border-collapse: collapse; table-layout: fixed; text-align: left; font-size: 13px; }
3250
3547
  th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; white-space: pre-wrap; }
3251
3548
  th { position: sticky; top: 0; background: #edf2f8; }
3252
- th:nth-child(1) { width: 17%; } th:nth-child(2), th:nth-child(3) { width: 23%; } th:nth-child(4) { width: 14%; }
3253
- .with-aiqa table { min-width: 790px; }
3254
- .with-aiqa th:nth-child(1) { width: 15%; }
3255
- .with-aiqa th:nth-child(2), .with-aiqa th:nth-child(3) { width: 19%; }
3256
- .with-aiqa th:nth-child(4) { width: 12%; }
3257
- .with-aiqa th:nth-child(6) { width: 16%; }
3549
+ th:nth-child(1) { width: 11%; }
3550
+ th:nth-child(2), th:nth-child(3) { width: 19%; }
3551
+ th:nth-child(4) { width: 17%; }
3552
+ th:nth-child(5) { width: 13%; }
3553
+ th:nth-child(6) { width: 21%; }
3554
+ .segment-id { font-weight: 700; }
3555
+ .segment-file { font-weight: 400; margin-top: 3px; }
3556
+ .segment-select { display: flex; align-items: center; gap: 4px; }
3557
+ .segment-select input { margin: 0; }
3558
+ .qa-mark { background: #ffebec; color: #a22628; font-weight: 700; text-decoration: underline; }
3559
+ .qa-verdict { font-weight: 700; }
3560
+ .qa-verdict[data-status="AUTO_PASS"] { color: #16634a; }
3561
+ .qa-verdict[data-status="HUMAN_REVIEW"] { color: #a22628; }
3562
+ .finding-list { margin: 0; padding-left: 0; list-style: none; }
3563
+ .finding-list li + li { margin-top: 6px; }
3258
3564
  tr:last-child td { border-bottom: 0; }
3259
3565
  td small { display: block; }
3260
3566
  td details { margin-top: 5px; }
3567
+ .ai-comment-summary { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
3568
+ .ai-comment-evidence summary { color: var(--blue); font-size: 12px; }
3569
+ .ai-comment-evidence p { max-height: 16em; overflow: auto; margin-top: 4px; }
3570
+ .finding-list + small { margin-top: 4px; }
3261
3571
  .aiqa { margin: 12px 0; border-top: 1px solid var(--border); padding-top: 12px; }
3262
3572
  .aiqa .run { margin: 8px 0; align-items: center; }
3263
3573
  .aiqa .field { max-width: 560px; }
3264
3574
  .ask-agent button { margin-top: 5px; }
3265
- .pager { justify-content: space-between; align-items: center; margin-top: 10px; }
3575
+ .pager { justify-content: space-between; align-items: center; padding: 8px 12px; border-top: 1px solid var(--border); }
3266
3576
  [hidden] { display: none !important; }
3267
3577
  @media (max-width: 950px) { .layout { grid-template-columns: minmax(0, 1fr); } }
3268
3578
  `;
3269
- function reviewClient() {
3579
+ function reviewClient(presentation, writeXlsx) {
3580
+ const { ruleLabel, aiStatus, aiStatusKey, aiTypes, aiComment, textParts, collectSections } = presentation;
3270
3581
  const get = (id) => document.getElementById(id);
3271
3582
  const form = document.getElementById("settings");
3272
3583
  const results = get("results");
@@ -3276,15 +3587,12 @@ function reviewClient() {
3276
3587
  const category = get("category");
3277
3588
  const severity = get("severity");
3278
3589
  const order = get("order");
3279
- const pagerText = get("pager-text");
3280
- const previous = get("previous");
3281
- const next = get("next");
3282
- const table = get("rows");
3590
+ const ruleSections = get("rule-sections");
3591
+ const ruleTable = get("rule-table");
3283
3592
  const status = get("status");
3284
3593
  const error = get("error");
3285
3594
  const allSegments = document.getElementById("all-segments");
3286
3595
  const aiqaRun = document.getElementById("aiqa-run");
3287
- const showAiqa = document.getElementById("aiqa-column") !== null;
3288
3596
  const aiqaLimit = Number(aiqaRun?.dataset.limit ?? 0);
3289
3597
  const selected = /* @__PURE__ */ new Set();
3290
3598
  const aiqaRows = /* @__PURE__ */ new Map();
@@ -3293,10 +3601,9 @@ function reviewClient() {
3293
3601
  const collator = new Intl.Collator(void 0, { numeric: true });
3294
3602
  let report = { rows: [], files: [] };
3295
3603
  let filtered = [];
3296
- let groups = [];
3297
3604
  let lastScan;
3298
3605
  let aiqaRunning = false;
3299
- let page = 0;
3606
+ const collapsed = /* @__PURE__ */ new Set();
3300
3607
  const pageSize = 50;
3301
3608
  async function requestLocal(path, options) {
3302
3609
  try {
@@ -3314,11 +3621,24 @@ function reviewClient() {
3314
3621
  td.textContent = text;
3315
3622
  return td;
3316
3623
  }
3624
+ function markedText(td, value, findings, side) {
3625
+ if (!value) td.textContent = "\u2014";
3626
+ else for (const { text, marked } of textParts(value, findings, side)) {
3627
+ if (!marked) td.append(text);
3628
+ else {
3629
+ const mark = document.createElement("mark");
3630
+ mark.className = "qa-mark";
3631
+ mark.textContent = text;
3632
+ td.append(mark);
3633
+ }
3634
+ }
3635
+ }
3317
3636
  function updateSelection() {
3318
3637
  if (!aiqaRun) return;
3319
3638
  aiqaRun.disabled = aiqaRunning || selected.size === 0;
3320
3639
  get("aiqa-selection").textContent = `\u5DF2\u9009 ${selected.size} / ${aiqaLimit} \u6BB5`;
3321
- for (const checkbox of table.querySelectorAll("input[type=checkbox]")) {
3640
+ for (const checkbox of ruleSections.querySelectorAll("input[data-segment]")) {
3641
+ checkbox.checked = selected.has(checkbox.dataset.segment);
3322
3642
  checkbox.disabled = aiqaRunning || selected.size >= aiqaLimit && !checkbox.checked;
3323
3643
  }
3324
3644
  }
@@ -3370,92 +3690,170 @@ function reviewClient() {
3370
3690
  details.append(summary, label, copy, copyStatus, manual);
3371
3691
  return details;
3372
3692
  }
3373
- function render() {
3374
- const maxPage = Math.max(0, Math.ceil(groups.length / pageSize) - 1);
3375
- page = Math.min(page, maxPage);
3376
- table.replaceChildren();
3377
- for (const { segment: issue, findings: group } of groups.slice(page * pageSize, (page + 1) * pageSize)) {
3378
- const row = document.createElement("tr");
3379
- const location = cell(row, issue.file);
3380
- const segment = document.createElement("small");
3381
- segment.textContent = "\u6BB5 " + issue.segment;
3382
- location.append(segment);
3383
- if (issue.segmentKey && aiqaRun) {
3384
- const key = issue.segmentKey;
3385
- const checkbox = document.createElement("input");
3386
- checkbox.type = "checkbox";
3387
- checkbox.checked = selected.has(key);
3388
- checkbox.setAttribute("aria-label", `\u9009\u62E9 ${issue.file} \u6BB5 ${issue.segment}`);
3389
- checkbox.addEventListener("change", () => {
3390
- if (checkbox.checked) selected.add(key);
3391
- else selected.delete(key);
3392
- updateSelection();
3393
- });
3394
- location.append(checkbox);
3395
- }
3396
- cell(row, issue.source || "\u2014");
3397
- cell(row, issue.target || "\u2014");
3398
- const regular = group.filter((entry) => entry.category !== "AIQA");
3399
- const kind = cell(row, [...new Set(regular.map((entry) => entry.category))].join("\uFF0F"));
3400
- if (regular.length > 0) {
3401
- const level = document.createElement("small");
3402
- const strongest = regular.reduce((left, right) => (severityRank[left.severity] ?? 4) <= (severityRank[right.severity] ?? 4) ? left : right);
3403
- level.textContent = severityLabel[strongest.severity] || strongest.severity;
3404
- kind.append(level);
3693
+ function renderRow({ segment: issue, findings, aiqa }) {
3694
+ const row = document.createElement("tr");
3695
+ const location = cell(row, "");
3696
+ const number3 = document.createElement("div");
3697
+ number3.className = "segment-id segment-select";
3698
+ if (issue.segmentKey && aiqaRun) {
3699
+ const key = issue.segmentKey;
3700
+ const checkbox = document.createElement("input");
3701
+ checkbox.type = "checkbox";
3702
+ checkbox.dataset.segment = key;
3703
+ checkbox.setAttribute("aria-label", `\u9009\u62E9 ${issue.file} \u6BB5 ${issue.segment}`);
3704
+ checkbox.addEventListener("change", () => {
3705
+ if (checkbox.checked) selected.add(key);
3706
+ else selected.delete(key);
3707
+ updateSelection();
3708
+ });
3709
+ number3.append(checkbox);
3710
+ }
3711
+ number3.append(issue.segment);
3712
+ const filename = document.createElement("small");
3713
+ filename.className = "segment-file";
3714
+ filename.textContent = issue.file;
3715
+ location.append(number3, filename);
3716
+ markedText(cell(row, ""), issue.source, findings, "source");
3717
+ markedText(cell(row, ""), issue.target, findings, "target");
3718
+ const comments = cell(row, findings.length ? "" : "\u2014");
3719
+ if (findings.length) {
3720
+ const list = document.createElement("ul");
3721
+ list.className = "finding-list";
3722
+ for (const finding of findings) {
3723
+ const item = document.createElement("li");
3724
+ item.textContent = finding.message;
3725
+ if (finding.evidence && finding.rule !== "TAG_MISMATCH") {
3726
+ const details = document.createElement("details");
3727
+ const summary = document.createElement("summary");
3728
+ summary.textContent = "\u67E5\u770B\u4F9D\u636E";
3729
+ const evidence = document.createElement("p");
3730
+ evidence.textContent = finding.evidence;
3731
+ details.append(summary, evidence);
3732
+ item.append(details);
3733
+ }
3734
+ list.append(item);
3405
3735
  }
3406
- const problem = cell(row, "");
3407
- const aiqa = showAiqa ? cell(row, "") : void 0;
3408
- for (const finding of group) {
3409
- const details = document.createElement("details");
3410
- const summary = document.createElement("summary");
3411
- summary.textContent = finding.message;
3412
- const evidence = document.createElement("p");
3413
- evidence.textContent = [finding.rule, finding.evidence].filter(Boolean).join(" \xB7 ");
3414
- details.append(summary, evidence);
3415
- (finding.category === "AIQA" ? aiqa : problem)?.append(details);
3736
+ const level = document.createElement("small");
3737
+ level.textContent = severityLabel[findings[0].severity] || findings[0].severity;
3738
+ comments.append(list, level);
3739
+ }
3740
+ const verdict = cell(row, aiqa ? aiStatus(aiqa) : "\u672A\u5BA1\u6821");
3741
+ verdict.className = aiqa ? "qa-verdict" : "muted";
3742
+ if (aiqa) {
3743
+ verdict.dataset.status = aiStatusKey(aiqa);
3744
+ const types = aiTypes(aiqa);
3745
+ if (types.length) {
3746
+ const detail = document.createElement("small");
3747
+ detail.textContent = types.join("\u3001");
3748
+ verdict.append(detail);
3416
3749
  }
3417
- if (form) problem.append(askAgent(issue, group));
3418
- table.append(row);
3419
- }
3420
- get("no-results").hidden = groups.length > 0;
3421
- get("table").hidden = groups.length === 0;
3422
- pagerText.textContent = groups.length + " \u4E2A\u6BB5 \xB7 \u7B2C " + (page + 1) + " / " + (maxPage + 1) + " \u9875";
3423
- previous.disabled = page === 0;
3424
- next.disabled = page === maxPage;
3750
+ }
3751
+ const aiComments = cell(row, "");
3752
+ const note = aiComment(aiqa);
3753
+ if (aiqa?.evidence && (note !== aiqa.evidence || note.length > 30)) {
3754
+ const preview = document.createElement("p");
3755
+ preview.className = "ai-comment-summary";
3756
+ preview.textContent = note;
3757
+ const details = document.createElement("details");
3758
+ details.className = "ai-comment-evidence";
3759
+ const summary = document.createElement("summary");
3760
+ summary.textContent = "\u67E5\u770B\u5B8C\u6574\u4F9D\u636E";
3761
+ const evidence = document.createElement("p");
3762
+ evidence.textContent = aiqa.evidence;
3763
+ details.append(summary, evidence);
3764
+ aiComments.append(preview, details);
3765
+ } else {
3766
+ aiComments.textContent = note || "\u2014";
3767
+ }
3768
+ if (form) aiComments.append(askAgent(issue, aiqa ? [...findings, aiqa] : findings));
3769
+ return row;
3770
+ }
3771
+ function renderSections(sections) {
3772
+ for (const section of ruleSections.querySelectorAll(".rule-section")) {
3773
+ if (section.open) collapsed.delete(section.dataset.rule);
3774
+ else collapsed.add(section.dataset.rule);
3775
+ }
3776
+ ruleSections.replaceChildren();
3777
+ for (const [key, { label, entries }] of sections) {
3778
+ let renderPage2 = function() {
3779
+ table.replaceChildren(...rows.slice(page * pageSize, (page + 1) * pageSize).map(renderRow));
3780
+ pagerText.textContent = `\u7B2C ${page + 1} / ${pages} \u9875`;
3781
+ previous.disabled = page === 0;
3782
+ next.disabled = page === pages - 1;
3783
+ };
3784
+ var renderPage = renderPage2;
3785
+ const rows = [...entries.values()];
3786
+ const section = document.createElement("details");
3787
+ section.className = "rule-section";
3788
+ section.dataset.rule = key;
3789
+ section.open = !collapsed.has(key);
3790
+ const heading = document.createElement("summary");
3791
+ heading.textContent = label;
3792
+ const count = document.createElement("span");
3793
+ count.className = "rule-count";
3794
+ count.textContent = `${rows.length} \u6BB5`;
3795
+ heading.append(count);
3796
+ const content = ruleTable.content.cloneNode(true);
3797
+ content.querySelector(".table").setAttribute("aria-label", label);
3798
+ const table = content.querySelector("tbody");
3799
+ const pager = content.querySelector(".pager");
3800
+ const pagerText = pager.querySelector("span");
3801
+ const previous = pager.querySelector("[data-previous]");
3802
+ const next = pager.querySelector("[data-next]");
3803
+ const pages = Math.ceil(rows.length / pageSize);
3804
+ pager.hidden = pages <= 1;
3805
+ let page = 0;
3806
+ previous.addEventListener("click", () => {
3807
+ page -= 1;
3808
+ renderPage2();
3809
+ updateSelection();
3810
+ });
3811
+ next.addEventListener("click", () => {
3812
+ page += 1;
3813
+ renderPage2();
3814
+ updateSelection();
3815
+ });
3816
+ renderPage2();
3817
+ section.append(heading, content);
3818
+ ruleSections.append(section);
3819
+ }
3820
+ get("no-results").hidden = sections.size > 0;
3425
3821
  updateSelection();
3426
3822
  }
3427
3823
  function filter() {
3428
3824
  const query = search.value.trim().toLocaleLowerCase();
3429
- filtered = [...report.rows, ...aiqaRows.values()].filter(
3430
- (row) => (!file.value || row.file === file.value) && (!category.value || row.category === category.value) && (!severity.value || row.severity === severity.value) && (!query || Object.values(row).some((value) => value.toLocaleLowerCase().includes(query)))
3825
+ const rows = [...report.rows, ...aiqaRows.values()];
3826
+ const matches = rows.filter(
3827
+ (row) => (!file.value || row.file === file.value) && (!category.value || ruleLabel(row) === category.value) && (!severity.value || row.severity === severity.value) && (!query || [
3828
+ row.file,
3829
+ row.segment,
3830
+ row.source,
3831
+ row.target,
3832
+ row.category,
3833
+ row.rule,
3834
+ row.message,
3835
+ row.evidence,
3836
+ ruleLabel(row),
3837
+ ...row.category === "AIQA" ? [aiStatus(row), aiComment(row), ...aiTypes(row)] : []
3838
+ ].some((value) => value.toLocaleLowerCase().includes(query)))
3431
3839
  );
3432
- filtered.sort((left, right) => {
3433
- const byLocation = collator.compare(left.file, right.file) || collator.compare(left.segment, right.segment);
3434
- if (order.value === "severity") return (severityRank[left.severity] ?? 4) - (severityRank[right.severity] ?? 4) || byLocation;
3435
- if (order.value === "category") return collator.compare(left.category, right.category) || byLocation;
3436
- return order.value === "desc" ? -byLocation : byLocation;
3840
+ const byLocation = (left, right) => collator.compare(left.file, right.file) || collator.compare(left.segment, right.segment);
3841
+ matches.sort((left, right) => {
3842
+ if (order.value === "severity") return (severityRank[left.severity] ?? 4) - (severityRank[right.severity] ?? 4) || byLocation(left, right);
3843
+ return (order.value === "desc" ? -1 : 1) * byLocation(left, right);
3437
3844
  });
3438
- const grouped = /* @__PURE__ */ new Map();
3439
- for (const issue of filtered) {
3440
- const key = issue.segmentKey ?? JSON.stringify([issue.file, issue.segment]);
3441
- const existing = grouped.get(key);
3442
- if (existing) existing.findings.push(issue);
3443
- else grouped.set(key, { segment: issue, findings: [issue] });
3444
- }
3845
+ const view = collectSections(matches, rows);
3846
+ const { sections, shown } = view;
3445
3847
  if (allSegments?.checked && !category.value && !severity.value) {
3446
- for (const segment of report.segments ?? []) {
3447
- if (!grouped.has(segment.segmentKey) && (!file.value || segment.file === file.value) && (!query || Object.values(segment).some((value) => value.toLocaleLowerCase().includes(query)))) {
3448
- grouped.set(segment.segmentKey, { segment, findings: [] });
3449
- }
3450
- }
3451
- }
3452
- groups = [...grouped.values()];
3453
- if (order.value === "file" || order.value === "desc") {
3454
- const direction = order.value === "desc" ? -1 : 1;
3455
- groups.sort(({ segment: left }, { segment: right }) => direction * (collator.compare(left.file, right.file) || collator.compare(left.segment, right.segment)));
3848
+ const clean = (report.segments ?? []).filter((segment) => !shown.has(segment.segmentKey) && (!file.value || segment.file === file.value) && (!query || Object.values(segment).some((value) => value.toLocaleLowerCase().includes(query))));
3849
+ clean.sort((left, right) => (order.value === "desc" ? -1 : 1) * byLocation(left, right));
3850
+ if (clean.length) sections.set("clean", {
3851
+ label: "\u65E0\u68C0\u67E5\u53D1\u73B0",
3852
+ entries: new Map(clean.map((segment) => [segment.segmentKey, { segment, findings: [] }]))
3853
+ });
3456
3854
  }
3457
- page = 0;
3458
- render();
3855
+ filtered = view.filtered;
3856
+ renderSections(sections);
3459
3857
  }
3460
3858
  function show(data) {
3461
3859
  report = data;
@@ -3481,22 +3879,49 @@ function reviewClient() {
3481
3879
  severity.value = "";
3482
3880
  order.value = "file";
3483
3881
  fillOptions(file, (data.segments ?? data.rows).map((row) => row.file));
3484
- fillOptions(category, data.rows.map((row) => row.category));
3882
+ fillOptions(category, data.rows.map(ruleLabel));
3485
3883
  results.hidden = false;
3486
3884
  filter();
3487
3885
  }
3488
3886
  search.addEventListener("input", filter);
3489
3887
  allSegments?.addEventListener("change", filter);
3490
3888
  for (const select of [file, category, severity, order]) select.addEventListener("change", filter);
3491
- previous.addEventListener("click", () => {
3492
- page -= 1;
3493
- render();
3494
- });
3495
- next.addEventListener("click", () => {
3496
- page += 1;
3497
- render();
3498
- });
3499
3889
  if (reportData) show(JSON.parse(reportData.textContent ?? "{}"));
3890
+ for (const button of document.querySelectorAll("button[data-export]")) {
3891
+ button.addEventListener("click", async () => {
3892
+ const format = button.dataset.export;
3893
+ if (button.disabled) return;
3894
+ button.disabled = true;
3895
+ error.textContent = "";
3896
+ try {
3897
+ const chosen = get("export-scope").value === "all" ? [...report.rows, ...aiqaRows.values()] : filtered;
3898
+ let blob;
3899
+ if (form) {
3900
+ const response = await requestLocal("/export/" + format, {
3901
+ method: "POST",
3902
+ headers: { "Content-Type": "application/json" },
3903
+ body: JSON.stringify({ rows: chosen, files: report.files })
3904
+ });
3905
+ if (!response.ok) throw new Error((await response.json()).error || "\u5BFC\u51FA\u5931\u8D25\u3002");
3906
+ blob = await response.blob();
3907
+ } else {
3908
+ const { ExcelJS: ExcelJS3 } = globalThis;
3909
+ const bytes = await writeXlsx(ExcelJS3.Workbook, chosen, presentation);
3910
+ blob = new Blob([bytes], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });
3911
+ }
3912
+ const url = URL.createObjectURL(blob);
3913
+ const anchor = document.createElement("a");
3914
+ anchor.href = url;
3915
+ anchor.download = "langlink-qa." + format;
3916
+ anchor.click();
3917
+ setTimeout(() => URL.revokeObjectURL(url), 1e3);
3918
+ } catch (cause) {
3919
+ error.textContent = cause instanceof Error ? cause.message : "\u5BFC\u51FA\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002";
3920
+ } finally {
3921
+ button.disabled = false;
3922
+ }
3923
+ });
3924
+ }
3500
3925
  if (!form) return;
3501
3926
  const add = get("add-rule");
3502
3927
  const ruleList = get("custom-rules");
@@ -3584,6 +4009,7 @@ function reviewClient() {
3584
4009
  severity: verdict.severity.toLowerCase(),
3585
4010
  rule: verdict.errorTypes.join(", ") || verdict.label,
3586
4011
  message: verdict.label,
4012
+ aiqaSummary: outcome.summary || verdict.reviewReason || verdict.evidence,
3587
4013
  evidence: [
3588
4014
  verdict.reviewReason,
3589
4015
  verdict.evidence,
@@ -3596,7 +4022,7 @@ function reviewClient() {
3596
4022
  aiqaStatus.textContent = `AIQA \u5B8C\u6210 ${completed} \u6BB5\uFF0C${data.items.length - completed} \u6BB5\u65E0\u6CD5\u5224\u5B9A\u3002`;
3597
4023
  selected.clear();
3598
4024
  const previousCategory = category.value;
3599
- fillOptions(category, [...report.rows.map((row) => row.category), "AIQA"]);
4025
+ fillOptions(category, [...report.rows.map(ruleLabel), "AIQA"]);
3600
4026
  category.value = previousCategory;
3601
4027
  filter();
3602
4028
  } catch (cause) {
@@ -3607,37 +4033,17 @@ function reviewClient() {
3607
4033
  updateSelection();
3608
4034
  }
3609
4035
  });
3610
- for (const button of document.querySelectorAll("button[data-export]")) {
3611
- button.addEventListener("click", async () => {
3612
- const format = button.dataset.export;
3613
- if (button.disabled) return;
3614
- button.disabled = true;
3615
- error.textContent = "";
3616
- try {
3617
- const chosen = get("export-scope").value === "all" ? [...report.rows, ...aiqaRows.values()] : filtered;
3618
- const response = await requestLocal("/export/" + format, {
3619
- method: "POST",
3620
- headers: { "Content-Type": "application/json" },
3621
- body: JSON.stringify({ rows: chosen, files: report.files })
3622
- });
3623
- if (!response.ok) throw new Error((await response.json()).error || "\u5BFC\u51FA\u5931\u8D25\u3002");
3624
- const url = URL.createObjectURL(await response.blob());
3625
- const anchor = document.createElement("a");
3626
- anchor.href = url;
3627
- anchor.download = "langlink-qa." + format;
3628
- anchor.click();
3629
- setTimeout(() => URL.revokeObjectURL(url), 1e3);
3630
- } catch (cause) {
3631
- error.textContent = cause instanceof Error ? cause.message : "\u5BFC\u51FA\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002";
3632
- } finally {
3633
- button.disabled = false;
3634
- }
3635
- });
4036
+ }
4037
+ var excelBrowserScript;
4038
+ function excelScript() {
4039
+ if (excelBrowserScript === void 0) {
4040
+ const path = createRequire(import.meta.url).resolve("exceljs/dist/exceljs.min.js");
4041
+ excelBrowserScript = readFileSync(path, "utf8").replace(/\n\/\/# sourceMappingURL=.*$/mu, "").replace(/<\/script/giu, "<\\/script");
3636
4042
  }
4043
+ return excelBrowserScript;
3637
4044
  }
3638
4045
  function renderReviewPage(report, nonce = "", aiqaEnabled = false) {
3639
4046
  const offline = report !== void 0;
3640
- const showAiqa = aiqaEnabled || report?.rows.some((row) => row.category === "AIQA");
3641
4047
  const title = offline ? "\u53CC\u8BED QA \u62A5\u544A" : "\u53CC\u8BED\u6587\u4EF6\u68C0\u67E5";
3642
4048
  const settings = offline ? "" : `<form class="panel" id="settings">
3643
4049
  <h2>\u672C\u6B21\u68C0\u67E5</h2>
@@ -3661,9 +4067,9 @@ function renderReviewPage(report, nonce = "", aiqaEnabled = false) {
3661
4067
  <button type="button">\u79FB\u9664\u68C0\u67E5\u9879</button>
3662
4068
  </fieldset></template>
3663
4069
  </form>`;
3664
- const exports = offline ? "" : `<div class="exports">
4070
+ const exports = `<div class="exports">
3665
4071
  <label class="field">\u5BFC\u51FA\u8303\u56F4<select id="export-scope"><option value="filtered">\u5F53\u524D\u7B5B\u9009</option><option value="all">\u5168\u90E8\u7ED3\u679C</option></select></label>
3666
- <button type="button" data-export="xlsx">Excel</button><button type="button" data-export="csv">CSV</button><button type="button" data-export="html">HTML</button></div>`;
4072
+ <button type="button" data-export="xlsx">\u5BFC\u51FA Excel</button>${offline ? "" : '<button type="button" data-export="csv">CSV</button><button type="button" data-export="html">HTML</button>'}</div>`;
3667
4073
  const aiqa = offline ? "" : `<div class="aiqa">
3668
4074
  <label class="checkbox"><input type="checkbox" id="all-segments">\u67E5\u770B\u5168\u90E8\u6BB5\u843D</label>
3669
4075
  ${aiqaEnabled ? `<details><summary>\u9879\u76EE\u672F\u8BED\u4E0E\u98CE\u683C\uFF08\u53EF\u9009\uFF09</summary>
@@ -3674,6 +4080,7 @@ function renderReviewPage(report, nonce = "", aiqaEnabled = false) {
3674
4080
  <p id="aiqa-status" role="status"></p>` : "<small>\u914D\u7F6E\u6A21\u578B\u7F51\u5173\u540E\u53EF\u8FD0\u884C AIQA\u3002</small>"}
3675
4081
  </div>`;
3676
4082
  const data = offline ? `<script type="application/json" id="report-data">${JSON.stringify(report).replaceAll("<", "\\u003c")}</script>` : "";
4083
+ const scriptNonce = nonce ? ` nonce="${nonce}"` : "";
3677
4084
  return `<!doctype html><html lang="zh-CN"><head><meta charset="utf-8">
3678
4085
  <meta name="viewport" content="width=device-width, initial-scale=1"><title>${title} \xB7 LangLink</title>
3679
4086
  <style>${styles}</style></head><body><main><p class="brand">LangLink</p><h1>${title}</h1>
@@ -3684,17 +4091,21 @@ function renderReviewPage(report, nonce = "", aiqaEnabled = false) {
3684
4091
  <div id="results" hidden>${aiqa}<div class="filters">
3685
4092
  <label class="field search">\u641C\u7D22<input type="search" id="search" placeholder="\u539F\u6587\u3001\u8BD1\u6587\u3001\u6BB5\u53F7\u6216\u89C4\u5219"></label>
3686
4093
  <label class="field">\u6587\u4EF6<select id="file-filter"><option value="">\u5168\u90E8\u6587\u4EF6</option></select></label>
3687
- <div class="field"><label for="category">\u5206\u7C7B</label><select id="category"><option value="">\u5168\u90E8\u5206\u7C7B</option></select></div>
4094
+ <div class="field"><label for="category">\u89C4\u5219\u7C7B\u522B</label><select id="category"><option value="">\u5168\u90E8\u89C4\u5219</option></select></div>
3688
4095
  <label class="field">\u4E25\u91CD\u7A0B\u5EA6<select id="severity"><option value="">\u5168\u90E8</option><option value="critical">\u4E25\u91CD</option><option value="major">\u4E3B\u8981</option><option value="minor">\u8F7B\u5FAE</option><option value="neutral">\u5F85\u6838\u67E5</option></select></label>
3689
- <label class="field">\u6392\u5E8F<select id="order"><option value="file">\u6587\u4EF6\u548C\u6BB5\u53F7</option><option value="desc">\u6587\u4EF6\u548C\u6BB5\u53F7\u5012\u5E8F</option><option value="severity">\u4E25\u91CD\u7A0B\u5EA6</option><option value="category">\u95EE\u9898\u5206\u7C7B</option></select></label>
3690
- </div><p id="no-results" hidden>\u5F53\u524D\u7B5B\u9009\u6CA1\u6709\u5339\u914D\u8BB0\u5F55\u3002</p>
3691
- <div class="table${showAiqa ? " with-aiqa" : ""}" id="table" tabindex="0" role="region" aria-label="\u95EE\u9898\u660E\u7EC6"><table>
3692
- <thead><tr><th scope="col">\u6587\u4EF6\uFF0F\u6BB5\u53F7</th><th scope="col">\u539F\u6587</th><th scope="col">\u8BD1\u6587</th><th scope="col">\u5206\u7C7B</th><th scope="col">\u666E\u901A QA</th>
3693
- ${showAiqa ? '<th id="aiqa-column" scope="col">AIQA</th>' : ""}</tr></thead>
3694
- <tbody id="rows"></tbody></table></div>
3695
- <div class="pager"><span id="pager-text" aria-live="polite"></span><div><button type="button" id="previous">\u4E0A\u4E00\u9875</button> <button type="button" id="next">\u4E0B\u4E00\u9875</button></div></div>
3696
- ${exports}</div></section></div></main>${data}
3697
- <script${nonce ? ` nonce="${nonce}"` : ""}>(${reviewClient.toString()})();</script></body></html>`;
4096
+ <label class="field">\u7EC4\u5185\u6392\u5E8F<select id="order"><option value="file">\u6587\u4EF6\u548C\u6BB5\u53F7</option><option value="desc">\u6587\u4EF6\u548C\u6BB5\u53F7\u5012\u5E8F</option><option value="severity">\u4E25\u91CD\u7A0B\u5EA6</option></select></label>
4097
+ </div>${exports}<p id="no-results" hidden>\u5F53\u524D\u7B5B\u9009\u6CA1\u6709\u5339\u914D\u8BB0\u5F55\u3002</p>
4098
+ <div id="rule-sections"></div>
4099
+ <template id="rule-table">
4100
+ <div class="table" tabindex="0" role="region"><table>
4101
+ <thead><tr><th scope="col">\u53E5\u6BB5\u7F16\u53F7</th><th scope="col">\u539F\u6587</th><th scope="col">\u8BD1\u6587</th>
4102
+ <th scope="col">\u8BC4\u8BBA</th><th scope="col">AI QA \u7ED3\u679C</th><th scope="col">AI \u8BC4\u8BBA</th></tr></thead>
4103
+ <tbody></tbody></table></div>
4104
+ <div class="pager"><span aria-live="polite"></span><div><button type="button" data-previous>\u4E0A\u4E00\u9875</button> <button type="button" data-next>\u4E0B\u4E00\u9875</button></div></div>
4105
+ </template>
4106
+ </div></section></div></main>${data}
4107
+ ${offline ? `<script${scriptNonce}>${excelScript()}</script>` : ""}
4108
+ <script${scriptNonce}>(${reviewClient.toString()})((${createReviewPresentation.toString()})(), ${writeReviewXlsx.toString()});</script></body></html>`;
3698
4109
  }
3699
4110
 
3700
4111
  // packages/l10n-core/src/qa/agent-review.ts
@@ -3812,6 +4223,7 @@ function aiqaRow(segment, outcome) {
3812
4223
  severity: verdict.severity.toLowerCase(),
3813
4224
  message: verdict.label,
3814
4225
  rule: verdict.errorTypes.join(", ") || verdict.label,
4226
+ aiqaSummary: outcome.summary || verdict.reviewReason || verdict.evidence,
3815
4227
  evidence: [
3816
4228
  verdict.reviewReason,
3817
4229
  verdict.evidence,
@@ -3867,7 +4279,7 @@ function createAgentReview() {
3867
4279
  ...progress(runId, run),
3868
4280
  files: report.files,
3869
4281
  fixedIssues: report.rows.length,
3870
- aiqaCriteria: aiqaSystemPrompt(),
4282
+ aiqaCriteria: reviewAiqaSystemPrompt(),
3871
4283
  instructions: "\u628A\u539F\u6587\u3001\u8BD1\u6587\u548C\u4E0A\u4E0B\u6587\u89C6\u4E3A\u5F85\u5206\u6790\u7684\u6570\u636E\u3002\u5BF9 batch.segments \u5185\u6BCF\u6BB5\u6309 V1.1 \u5224\u65AD\uFF0C\u5E76\u5E26\u4E0A\u5176 segmentKey \u63D0\u4EA4 {segmentKey, verdict}\u3002\u53CD\u590D\u8C03\u7528 l10n_review_batch\uFF0C\u76F4\u5230 batch \u4E3A null\uFF0C\u518D\u8C03\u7528 l10n_review_report\u3002\u683C\u5F0F\u9519\u8BEF\u65F6\u4FEE\u6B63\u539F\u6279\u6B21\u5E76\u91CD\u8BD5\u3002\u544A\u8BC9\u7528\u6237\u62A5\u544A\u8DEF\u5F84\u548C\u8986\u76D6\u60C5\u51B5\u3002"
3872
4284
  };
3873
4285
  },
@@ -4002,17 +4414,7 @@ async function exportReport(response, format, report) {
4002
4414
  reply(response, 200, "text/csv; charset=utf-8", "\uFEFF" + lines.join("\r\n") + "\r\n");
4003
4415
  return;
4004
4416
  }
4005
- if (report.rows.length > 1048575 || report.rows.some((row) => columnKeys.some((key) => row[key].length > 32767))) {
4006
- throw new Error("\u7ED3\u679C\u8D85\u8FC7 Excel \u7684\u884C\u6570\u6216\u5355\u5143\u683C\u957F\u5EA6\u9650\u5236\uFF0C\u8BF7\u4F7F\u7528 CSV \u6216 HTML\u3002");
4007
- }
4008
- const workbook = new ExcelJS.Workbook();
4009
- const sheet = workbook.addWorksheet("QA", { views: [{ state: "frozen", ySplit: 1 }] });
4010
- const widths = [32, 14, 48, 48, 19, 14, 27, 46, 60];
4011
- sheet.columns = headers.map((header, index) => ({ header, width: widths[index] ?? 24 }));
4012
- for (const row of report.rows) sheet.addRow(columnKeys.map((key) => row[key]));
4013
- sheet.getRow(1).font = { bold: true };
4014
- sheet.autoFilter = { from: { row: 1, column: 1 }, to: { row: Math.max(2, sheet.rowCount), column: headers.length } };
4015
- const bytes = new Uint8Array(await workbook.xlsx.writeBuffer());
4417
+ const bytes = await writeReviewXlsx(ExcelJS.Workbook, report.rows, createReviewPresentation());
4016
4418
  reply(response, 200, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", bytes);
4017
4419
  }
4018
4420
  async function listenQaReview(options = {}) {