@alauda/doom 2.7.0 → 2.7.1

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.
@@ -22,6 +22,17 @@ export const DEFAULT_CONTEXT_TAIL = 20;
22
22
  const PLACEHOLDER_DISCIPLINE = `## Placeholders
23
23
 
24
24
  Tokens shaped like \`__DOOM_TR_LINK_3__\` stand for content you must not author — link targets, code, identifiers, component attribute values. Reproduce each one verbatim and exactly once, in the position it appears. Never translate, reformat, split, renumber, remove, duplicate or invent one. The text around a placeholder is translated as usual.`;
25
+ /**
26
+ * Kept out of `DEFAULT_SYSTEM_PROMPT` for the same reason the placeholder
27
+ * discipline is: a repository can replace that prompt wholesale through
28
+ * `translate.systemPrompt`, and this constraint is enforced by a blocking
29
+ * check, so it has to live where a repository cannot drop it.
30
+ */
31
+ const EMPHASIS_DISCIPLINE = `## Emphasis
32
+
33
+ \`**bold**\` only works when the delimiters sit directly against the text, and CommonMark will not close a run that is preceded by punctuation and followed by a letter. \`**Note:** text\` is bold; \`**注意:**文本\` is not — it prints the asterisks to the page.
34
+
35
+ When a bold label ends in a colon or other punctuation and the next thing is a word, put the punctuation outside the emphasis (\`**注意**:文本\`) or leave a space after the closing \`**\`. Never write \`** text **\`.`;
25
36
  const SEGMENT_TASK = `Answer with the translated segment and nothing else: no explanation, no preamble, no summary, and no code fence wrapped around your whole answer.
26
37
 
27
38
  The segment is one piece of a longer page. It begins and ends mid-document, and that is correct — do not add a title, an introduction or a conclusion, and do not finish a section that carries on past the end of what you were given.
@@ -39,6 +50,8 @@ export const createSegmentTranslator = ({ models, model, reasoningEffort, transl
39
50
  '',
40
51
  PLACEHOLDER_DISCIPLINE,
41
52
  '',
53
+ EMPHASIS_DISCIPLINE,
54
+ '',
42
55
  '## Translation rules',
43
56
  '',
44
57
  translationRules,
@@ -23,8 +23,20 @@ import type { TermPair } from './translate-terms.ts';
23
23
  */
24
24
  /** How many times a segment is asked for before it is escalated. */
25
25
  export declare const DEFAULT_MAX_SEGMENT_ATTEMPTS = 3;
26
- /** How many times the assembled document may send segments back. */
27
- export declare const DEFAULT_MAX_ASSEMBLY_ROUNDS = 2;
26
+ /**
27
+ * How many times the assembled document may send segments back.
28
+ *
29
+ * Raised from 2 on 2026-09-03. At 2, the only rule that ever fired here in
30
+ * production — `no-unparsed-emphasis`, 22 send-backs out of 22 across four
31
+ * builds of `immutable-infra-docs` — failed three of six documents by running
32
+ * out of rounds, and a document that fails discards every other document's
33
+ * accepted work in the same run. The model does fix it; it does not always fix
34
+ * it twice in a row.
35
+ *
36
+ * This is the backstop, not the fix: that rule is now also checked per segment,
37
+ * where it gets three attempts and a repair agent before it ever reaches here.
38
+ */
39
+ export declare const DEFAULT_MAX_ASSEMBLY_ROUNDS = 4;
28
40
  export type SegmentStatus = 'translated' | 'cached' | 'repaired' | 'failed';
29
41
  export interface SegmentOutcome {
30
42
  index: number;
@@ -21,8 +21,20 @@ import { UnsplittableBlockError, assemble, documentOutline, planSegments, resolv
21
21
  */
22
22
  /** How many times a segment is asked for before it is escalated. */
23
23
  export const DEFAULT_MAX_SEGMENT_ATTEMPTS = 3;
24
- /** How many times the assembled document may send segments back. */
25
- export const DEFAULT_MAX_ASSEMBLY_ROUNDS = 2;
24
+ /**
25
+ * How many times the assembled document may send segments back.
26
+ *
27
+ * Raised from 2 on 2026-09-03. At 2, the only rule that ever fired here in
28
+ * production — `no-unparsed-emphasis`, 22 send-backs out of 22 across four
29
+ * builds of `immutable-infra-docs` — failed three of six documents by running
30
+ * out of rounds, and a document that fails discards every other document's
31
+ * accepted work in the same run. The model does fix it; it does not always fix
32
+ * it twice in a row.
33
+ *
34
+ * This is the backstop, not the fix: that rule is now also checked per segment,
35
+ * where it gets three attempts and a repair agent before it ever reaches here.
36
+ */
37
+ export const DEFAULT_MAX_ASSEMBLY_ROUNDS = 4;
26
38
  /**
27
39
  * A mask finding, said in the vocabulary the rest of the pipeline speaks.
28
40
  *
@@ -1,4 +1,5 @@
1
1
  import { visit } from 'unist-util-visit';
2
+ import { explainUnparsedEmphasis, findUnparsedEmphasis, } from "../remark-lint/no-unparsed-emphasis.js";
2
3
  import { collectComponents, collectHeadingDepths, } from "../remark-lint/translation-parity/shared.js";
3
4
  import { countPlaceholders } from "./translate-mask.js";
4
5
  import { parseAttributeElement } from "./translate-segment.js";
@@ -208,8 +209,48 @@ const structureFindings = (segment, tree, processor) => {
208
209
  });
209
210
  });
210
211
  }
212
+ // Emphasis the translation broke.
213
+ //
214
+ // `**` reaching a text node means the delimiters were printed instead of
215
+ // read, and the usual cause is a target language that does not space the way
216
+ // the source did: `**Note:** text` is bold, and the Chinese it becomes,
217
+ // `**注意:**文本`, is not — the closing run is preceded by punctuation and
218
+ // followed by a letter, which CommonMark refuses to close on. The page then
219
+ // shows the asterisks, and nothing else notices: it parses, every link
220
+ // resolves, every component is present.
221
+ //
222
+ // `no-unparsed-emphasis` already catches this over the whole document. It is
223
+ // here for the same reason the heading and component collectors are (see this
224
+ // function's own note): checked per segment it arrives with the segment
225
+ // attached and can simply be retranslated, with three attempts and a repair
226
+ // agent behind it, instead of sharing the two rounds the assembled page gets.
227
+ //
228
+ // Only what the translation introduced. A source that shows literal asterisks
229
+ // on purpose is the author's business, and its translation should keep them.
230
+ if (!firstUnparsedEmphasis(source)) {
231
+ const broken = firstUnparsedEmphasis(tree);
232
+ if (broken) {
233
+ findings.push({
234
+ rule: 'doom-translate:segment-unparsed-emphasis',
235
+ reason: `${explainUnparsedEmphasis(broken.delimiter, broken.window)} The source segment has none, so this one came from the translation. Put the punctuation outside the emphasis — \`**注意**:文本\` — or leave a space after the closing \`**\`.`,
236
+ });
237
+ }
238
+ }
211
239
  return findings;
212
240
  };
241
+ /**
242
+ * The first `**` a segment prints instead of reading, if there is one.
243
+ *
244
+ * Masked text, so the `__` half of the rule is off: a masked segment is full of
245
+ * `__DOOM_TR_ICODE_0__`, and `**` never appears inside a placeholder.
246
+ */
247
+ const firstUnparsedEmphasis = (tree) => {
248
+ let found;
249
+ visit(tree, 'text', (node) => {
250
+ found ??= findUnparsedEmphasis(node.value, { maskedText: true });
251
+ });
252
+ return found;
253
+ };
213
254
  /**
214
255
  * A tag's prose, checked as the tag it has to become.
215
256
  *
@@ -1,2 +1,15 @@
1
1
  import type { Root } from 'mdast';
2
+ /** What one of these looks like to a person, wherever it is reported. */
3
+ export declare const explainUnparsedEmphasis: (delimiter: string, window: string) => string;
4
+ /**
5
+ * The first unparsed delimiter in a string, if there is one.
6
+ *
7
+ * `maskedText` narrows the test to `**`; see `UNPARSED_STRONG`.
8
+ */
9
+ export declare const findUnparsedEmphasis: (value: string, { maskedText }?: {
10
+ maskedText?: boolean;
11
+ }) => {
12
+ delimiter: string;
13
+ window: string;
14
+ } | undefined;
2
15
  export declare const noUnparsedEmphasis: import("unified-lint-rule").Plugin<Root, unknown>;
@@ -34,15 +34,40 @@ import { visitParents } from 'unist-util-visit-parents';
34
34
  * accident.
35
35
  */
36
36
  const UNPARSED_EMPHASIS = /\*\*|(?<![\p{L}\p{N}])__|__(?![\p{L}\p{N}])/u;
37
+ /**
38
+ * The `**` half of the test on its own.
39
+ *
40
+ * `doom translate` runs this check a segment at a time, before the placeholders
41
+ * are put back, and a masked segment is full of `__DOOM_TR_ICODE_0__`. The `__`
42
+ * half would report every one of them. `**` never appears in a placeholder, so
43
+ * the half that matters for the defect this rule was written for is also the
44
+ * half that is safe to run on masked text.
45
+ */
46
+ const UNPARSED_STRONG = /\*\*/u;
47
+ /** What one of these looks like to a person, wherever it is reported. */
48
+ export const explainUnparsedEmphasis = (delimiter, window) => `\`${delimiter}\` is printed to the page here, not read as emphasis: \`${window}\`. ` +
49
+ `Emphasis delimiters must sit directly against the text they emphasise — \`**text**\`, not \`** text **\` and not \`**text:**more\`.`;
50
+ /**
51
+ * The first unparsed delimiter in a string, if there is one.
52
+ *
53
+ * `maskedText` narrows the test to `**`; see `UNPARSED_STRONG`.
54
+ */
55
+ export const findUnparsedEmphasis = (value, { maskedText = false } = {}) => {
56
+ const match = (maskedText ? UNPARSED_STRONG : UNPARSED_EMPHASIS).exec(value);
57
+ return match
58
+ ? { delimiter: match[0], window: preview(value, match.index) }
59
+ : undefined;
60
+ };
37
61
  export const noUnparsedEmphasis = lintRule('doom-lint:no-unparsed-emphasis', (root, vfile) => {
38
62
  visitParents(root, 'text', (node, parents) => {
39
- const match = UNPARSED_EMPHASIS.exec(node.value);
40
- if (!match) {
63
+ const found = findUnparsedEmphasis(node.value);
64
+ if (!found) {
41
65
  return;
42
66
  }
43
- const delimiter = match[0];
44
- vfile.message(`\`${delimiter}\` is printed to the page here, not read as emphasis: \`${preview(node.value, match.index)}\`. ` +
45
- `Emphasis delimiters must sit directly against the text they emphasise — \`**text**\`, not \`** text **\` and not \`**text:**more\`.`, { ancestors: [...parents, node], place: pointStart(node) });
67
+ vfile.message(explainUnparsedEmphasis(found.delimiter, found.window), {
68
+ ancestors: [...parents, node],
69
+ place: pointStart(node),
70
+ });
46
71
  });
47
72
  });
48
73
  /** A short window around the offending delimiter, for a person reading the log. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {