@sparkelf/dsh-genui 0.11.4-patch.2 → 0.13.0-sparkelf.3

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.
Files changed (112) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/ICON-NAMES.md +30 -0
  3. package/README.md +26 -28
  4. package/README.zh-CN.md +26 -28
  5. package/SKILL.md +128 -19
  6. package/THIRD_PARTY_NOTICES.md +42 -0
  7. package/assets/genui-icon.svg +20 -0
  8. package/assets/genui-logo.svg +18 -0
  9. package/lib/assets/icons.js +1 -0
  10. package/lib/assets/mermaid.js +325 -325
  11. package/lib/assets/standalone-runtime.js +10 -9
  12. package/lib/client.js +32 -31
  13. package/lib/index.js +523 -80
  14. package/lib/types/client/action-context.d.ts +1 -1
  15. package/lib/types/client/artifact/types.d.ts +1 -1
  16. package/lib/types/client/asset-loader.d.ts +2 -2
  17. package/lib/types/client/blocks/blocks.d.ts +12 -0
  18. package/lib/types/client/blocks/icon.d.ts +4 -0
  19. package/lib/types/client/dom-fence.d.ts +2 -1
  20. package/lib/types/client/fence-render.d.ts +5 -21
  21. package/lib/types/client/file-address.d.ts +4 -0
  22. package/lib/types/client/file-link-context.d.ts +49 -0
  23. package/lib/types/client/file-link.d.ts +17 -0
  24. package/lib/types/client/gallery.d.ts +8 -2
  25. package/lib/types/client/genui-runtime/diagnostics.d.ts +1 -1
  26. package/lib/types/client/genui-runtime/limits.d.ts +4 -0
  27. package/lib/types/client/genui-runtime/schema.d.ts +14 -1
  28. package/lib/types/client/guard.d.ts +4 -1
  29. package/lib/types/client/i18n/en.d.ts +5 -1
  30. package/lib/types/client/i18n/index.d.ts +1 -1
  31. package/lib/types/client/icons/asset-icons.d.ts +1 -0
  32. package/lib/types/client/icons/icon-data-full.d.ts +23 -0
  33. package/lib/types/client/icons/icon-data.d.ts +24 -0
  34. package/lib/types/client/icons/icon-lazy.d.ts +18 -0
  35. package/lib/types/client/icons/icon-names-full.d.ts +12 -0
  36. package/lib/types/client/index.d.ts +5 -15
  37. package/lib/types/client/inline.d.ts +1 -1
  38. package/lib/types/client/mermaid-colors.d.ts +2 -0
  39. package/lib/types/client/mermaid-core.d.ts +2 -1
  40. package/lib/types/client/mermaid-lazy.d.ts +5 -1
  41. package/lib/types/client/panel-command.d.ts +21 -1
  42. package/lib/types/client/panel.d.ts +6 -1
  43. package/lib/types/client/primitive-adapter.d.ts +0 -2
  44. package/lib/types/client/session-resolver.d.ts +13 -2
  45. package/lib/types/client/source-fence.d.ts +1 -1
  46. package/lib/types/client/spec.d.ts +127 -3
  47. package/lib/types/client/standalone/asset-loader.d.ts +1 -1
  48. package/lib/types/client/standalone/primitive-adapter.d.ts +0 -4
  49. package/lib/types/plugin/fence-feedback.d.ts +11 -7
  50. package/lib/types/plugin/index.d.ts +6 -2
  51. package/lib/types/shared/fence-language.d.ts +14 -0
  52. package/lib/types/shared/fence-repair.d.ts +2 -1
  53. package/lib/types/shared/fence-resolve.d.ts +1 -1
  54. package/package.json +92 -83
  55. package/src/client/EChartNode.tsx +17 -3
  56. package/src/client/GenuiBlock.module.css +411 -76
  57. package/src/client/action-context.ts +5 -15
  58. package/src/client/artifact/ArtifactExport.module.css +34 -3
  59. package/src/client/artifact/ExportableGenuiBlock.tsx +23 -2
  60. package/src/client/artifact/portability.ts +6 -1
  61. package/src/client/artifact/types.ts +1 -1
  62. package/src/client/asset-loader.ts +3 -3
  63. package/src/client/blocks/advanced.tsx +101 -14
  64. package/src/client/blocks/blocks.tsx +143 -0
  65. package/src/client/blocks/charts.tsx +22 -6
  66. package/src/client/blocks/icon.tsx +93 -0
  67. package/src/client/blocks/image.tsx +1 -0
  68. package/src/client/blocks/render-node.tsx +84 -52
  69. package/src/client/dom-fence.tsx +546 -72
  70. package/src/client/fence-render.tsx +5 -21
  71. package/src/client/file-address.ts +37 -0
  72. package/src/client/file-link-context.tsx +116 -0
  73. package/src/client/file-link.ts +46 -0
  74. package/src/client/gallery.ts +161 -133
  75. package/src/client/genui-runtime/diagnostics.ts +1 -1
  76. package/src/client/genui-runtime/limits.ts +4 -0
  77. package/src/client/genui-runtime/normalize.ts +42 -6
  78. package/src/client/genui-runtime/schema.ts +39 -7
  79. package/src/client/guard.ts +170 -15
  80. package/src/client/i18n/en.ts +5 -1
  81. package/src/client/i18n/index.ts +1 -1
  82. package/src/client/i18n/zh.ts +5 -1
  83. package/src/client/icons/asset-icons.ts +16 -0
  84. package/src/client/icons/icon-data-full.ts +5715 -0
  85. package/src/client/icons/icon-data.ts +507 -0
  86. package/src/client/icons/icon-lazy.ts +80 -0
  87. package/src/client/icons/icon-names-full.ts +12 -0
  88. package/src/client/index.tsx +27 -51
  89. package/src/client/inline.ts +17 -6
  90. package/src/client/mermaid-colors.ts +40 -0
  91. package/src/client/mermaid-core.ts +69 -61
  92. package/src/client/mermaid-lazy.ts +99 -4
  93. package/src/client/panel-command.ts +16 -2
  94. package/src/client/panel.tsx +18 -5
  95. package/src/client/parse-partial.ts +6 -1
  96. package/src/client/primitive-adapter.ts +0 -11
  97. package/src/client/session-resolver.ts +12 -21
  98. package/src/client/source-fence.ts +4 -2
  99. package/src/client/spec.ts +149 -2
  100. package/src/client/standalone/asset-loader.ts +1 -1
  101. package/src/client/standalone/primitive-adapter.tsx +1 -9
  102. package/src/client/table-details.ts +4 -3
  103. package/src/plugin/fence-feedback.ts +60 -14
  104. package/src/plugin/index.ts +45 -20
  105. package/src/plugin/tool.ts +11 -2
  106. package/src/shared/fence-language.ts +30 -0
  107. package/src/shared/fence-repair.ts +37 -1
  108. package/src/shared/fence-resolve.ts +1 -1
  109. package/tsdown.config.ts +7 -8
  110. package/lib/invariant.js +0 -19
  111. package/lib/types/plugin/invariant.d.ts +0 -15
  112. package/src/plugin/invariant.ts +0 -30
package/lib/index.js CHANGED
@@ -6,6 +6,7 @@ import { createHash, randomUUID } from "node:crypto";
6
6
  //#region src/client/genui-runtime/schema.ts
7
7
  /** Canonical enum domains shared by schema validation and repair. */
8
8
  const TEXT_SIZES = [
9
+ "display",
9
10
  "h1",
10
11
  "h2",
11
12
  "h3",
@@ -13,6 +14,11 @@ const TEXT_SIZES = [
13
14
  "muted",
14
15
  "caption"
15
16
  ];
17
+ const TEXT_ALIGNS = [
18
+ "left",
19
+ "center",
20
+ "right"
21
+ ];
16
22
  const BUTTON_TONES = [
17
23
  "primary",
18
24
  "danger",
@@ -142,6 +148,46 @@ const CARD_TONES = [
142
148
  "warning",
143
149
  "danger"
144
150
  ];
151
+ /** Text run tones (semantic colour without a badge). */
152
+ const TEXT_TONES = [
153
+ "danger",
154
+ "success",
155
+ "warning",
156
+ "info",
157
+ "muted"
158
+ ];
159
+ /** Arrow directions. */
160
+ const ARROW_DIRS = ["down", "right"];
161
+ /** Row main-axis alignment values. */
162
+ const ROW_JUSTIFY = [
163
+ "start",
164
+ "center",
165
+ "end",
166
+ "between"
167
+ ];
168
+ /** Block-row paint modes: filled cells, or outlined cells for bit grids. */
169
+ const BLOCKS_VARIANTS = [
170
+ "fill",
171
+ "outline",
172
+ "plain"
173
+ ];
174
+ /** 单格强调的语义档位。 */
175
+ const BLOCK_CELL_TONES = [
176
+ "accent",
177
+ "success",
178
+ "warning",
179
+ "danger",
180
+ "muted"
181
+ ];
182
+ /** Icon tones: the four semantic roles plus neutral/muted text colours. */
183
+ const ICON_TONES = [
184
+ "default",
185
+ "muted",
186
+ "info",
187
+ "success",
188
+ "warning",
189
+ "danger"
190
+ ];
145
191
  /** Hero cover tones. */
146
192
  const HERO_TONES = [
147
193
  "accent",
@@ -217,6 +263,12 @@ const timelineRecordSchema = recordSchema(["title"], {
217
263
  desc: "string",
218
264
  time: "string"
219
265
  });
266
+ const blocksRowSchema = recordSchema(["cells"], {
267
+ label: "string",
268
+ cells: "array",
269
+ color: "string",
270
+ variant: "string"
271
+ }, {}, { variant: BLOCKS_VARIANTS }, { title: "label" });
220
272
  const diffRecordSchema = recordSchema(["path", "newText"], {
221
273
  path: "string",
222
274
  oldText: "string-or-null",
@@ -318,6 +370,12 @@ const GENUI_SPEC_SCHEMA = schema(["items"], {
318
370
  * diagnostics, where erased interfaces are unavailable.
319
371
  */
320
372
  const COMPONENT_SCHEMAS = {
373
+ arrow: schema([], {
374
+ ...nodeFields,
375
+ dir: "string",
376
+ length: "number",
377
+ label: "string"
378
+ }, { direction: "dir" }, { enums: { dir: ARROW_DIRS } }),
321
379
  accordion: schema(["items"], {
322
380
  ...nodeFields,
323
381
  items: "array"
@@ -378,9 +436,11 @@ const COMPONENT_SCHEMAS = {
378
436
  card: schema(["items"], {
379
437
  ...nodeFields,
380
438
  title: "string",
439
+ eyebrow: "string",
381
440
  items: "nodes",
382
441
  tone: "string",
383
- accent: "string"
442
+ accent: "string",
443
+ flat: "boolean"
384
444
  }, {
385
445
  label: "title",
386
446
  content: "items"
@@ -429,7 +489,8 @@ const COMPONENT_SCHEMAS = {
429
489
  col: schema(["items"], {
430
490
  ...nodeFields,
431
491
  items: "nodes",
432
- gap: "number"
492
+ gap: "number",
493
+ width: "number"
433
494
  }),
434
495
  copy: schema(["text"], {
435
496
  ...nodeFields,
@@ -468,7 +529,13 @@ const COMPONENT_SCHEMAS = {
468
529
  items: "diffs",
469
530
  files: "diffs"
470
531
  }, { nested: { diffs: diffRecordSchema } }),
471
- divider: schema([], nodeFields),
532
+ divider: schema([], {
533
+ ...nodeFields,
534
+ label: "string"
535
+ }, {
536
+ title: "label",
537
+ text: "label"
538
+ }),
472
539
  echart: schema([], {
473
540
  ...nodeFields,
474
541
  title: "string",
@@ -497,10 +564,29 @@ const COMPONENT_SCHEMAS = {
497
564
  cols: "number",
498
565
  items: "nodes"
499
566
  }),
567
+ blocks: schema(["rows"], {
568
+ ...nodeFields,
569
+ rows: "array",
570
+ columns: "number",
571
+ caption: "string",
572
+ title: "string"
573
+ }, {
574
+ items: "rows",
575
+ data: "rows"
576
+ }, { nested: { rows: blocksRowSchema } }),
577
+ icon: schema(["name"], {
578
+ ...nodeFields,
579
+ name: "string",
580
+ label: "string",
581
+ tone: "string",
582
+ size: "number",
583
+ tile: "boolean"
584
+ }, { icon: "name" }, { enums: { tone: ICON_TONES } }),
500
585
  image: schema(["src"], {
501
586
  ...nodeFields,
502
587
  src: "string",
503
- alt: "string"
588
+ alt: "string",
589
+ caption: "string"
504
590
  }, {
505
591
  url: "src",
506
592
  link: "src"
@@ -590,8 +676,9 @@ const COMPONENT_SCHEMAS = {
590
676
  ...nodeFields,
591
677
  items: "nodes",
592
678
  wrap: "boolean",
593
- spacer: "boolean"
594
- }),
679
+ spacer: "boolean",
680
+ justify: "string"
681
+ }, {}, { enums: { justify: ROW_JUSTIFY } }),
595
682
  scene3d: schema(["meshes"], {
596
683
  ...nodeFields,
597
684
  title: "string",
@@ -678,8 +765,15 @@ const COMPONENT_SCHEMAS = {
678
765
  ...nodeFields,
679
766
  content: "string",
680
767
  size: "string",
681
- center: "boolean"
682
- }, { text: "content" }, { enums: { size: TEXT_SIZES } }),
768
+ center: "boolean",
769
+ align: "string",
770
+ tone: "string",
771
+ mono: "boolean"
772
+ }, { text: "content" }, { enums: {
773
+ size: TEXT_SIZES,
774
+ align: TEXT_ALIGNS,
775
+ tone: TEXT_TONES
776
+ } }),
683
777
  textarea: schema([], {
684
778
  ...nodeFields,
685
779
  label: "string",
@@ -768,6 +862,38 @@ function wrapSingleComponentRoot(value) {
768
862
  };
769
863
  }
770
864
  /**
865
+ * Adopt a spec whose root `items` is ONE component instead of a list.
866
+ *
867
+ * The envelope takes a list, and a body that names a single component at the root
868
+ * is already accepted — `{"type":"callout",…}` wraps into a one-item spec. The same
869
+ * intent written one level down, as `{"items":{"type":"callout",…}}`, was rejected
870
+ * outright, so two spellings of the same thing disagreed: the bare form rendered
871
+ * and the envelope form kept degrading to a code block with a parse banner.
872
+ *
873
+ * Returns null unless the value really is that shape, so nothing else is affected:
874
+ * the root must be a spec envelope (`items` present, not a component itself) and
875
+ * the value under `items` must be component-shaped — an object carrying a non-empty
876
+ * `type` string. An `items` holding anything else stays rejected, because there is
877
+ * no single component to adopt and guessing one would invent content.
878
+ *
879
+ * @param value - the parsed fence body, before validation.
880
+ * @returns the same spec with `items` wrapped in an array, or null when the body
881
+ * is not this particular mistake.
882
+ */
883
+ function adoptSingleItemEnvelope(value) {
884
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
885
+ if (isComponentRoot(value)) return null;
886
+ const v = value;
887
+ const inner = v.items;
888
+ if (typeof inner !== "object" || inner === null || Array.isArray(inner)) return null;
889
+ const candidate = inner;
890
+ if (typeof candidate.type !== "string" || candidate.type === "") return null;
891
+ return {
892
+ ...v,
893
+ items: [inner]
894
+ };
895
+ }
896
+ /**
771
897
  * Basic structural guard: is this object a valid GenuiSpec?
772
898
  *
773
899
  * A bare component root is not a spec (it is wrapped instead), so
@@ -826,6 +952,10 @@ const GENUI_LIMITS = {
826
952
  maxKeyValuePairs: 24,
827
953
  /** Maximum `file-tree` nesting. */
828
954
  maxTreeDepth: 6,
955
+ /** Maximum `blocks` figure rows / cells per row. Cells are data, not nodes,
956
+ * so a wide figure still costs one node against `maxNodes`. */
957
+ maxBlocksRows: 14,
958
+ maxBlocksCells: 16,
829
959
  /** Maximum `diagram` nodes / edges / zones / focal accents. */
830
960
  maxDiagramNodes: 9,
831
961
  maxDiagramEdges: 12,
@@ -891,7 +1021,7 @@ function repairColumnValues(value) {
891
1021
  if (typeof item === "string") columns.push(item.slice(0, 128));
892
1022
  else if (item !== null && typeof item === "object") {
893
1023
  const column = item;
894
- const label = typeof column.label === "string" ? column.label : typeof column.value === "string" ? column.value : typeof column.title === "string" ? column.title : JSON.stringify(item);
1024
+ const label = typeof column.label === "string" ? column.label : typeof column.value === "string" ? column.value : typeof column.title === "string" ? column.title : typeof column.name === "string" && column.name !== "" ? column.name : JSON.stringify(item);
895
1025
  columns.push(label.slice(0, 128));
896
1026
  }
897
1027
  }
@@ -943,7 +1073,8 @@ function columnKeyOf(value) {
943
1073
  "key",
944
1074
  "dataIndex",
945
1075
  "title",
946
- "label"
1076
+ "label",
1077
+ "name"
947
1078
  ]) if (typeof column[key] === "string" && column[key] !== "") return column[key];
948
1079
  }
949
1080
  /** 将 object row 中的值转换为 table 单元格,并保留列位置。 */
@@ -961,7 +1092,8 @@ function columnHeaderText(value) {
961
1092
  "title",
962
1093
  "label",
963
1094
  "key",
964
- "dataIndex"
1095
+ "dataIndex",
1096
+ "name"
965
1097
  ]) if (typeof column[key] === "string" && column[key] !== "") return column[key];
966
1098
  return JSON.stringify(value);
967
1099
  }
@@ -971,9 +1103,34 @@ function columnHeaderText(value) {
971
1103
  function record$1(value) {
972
1104
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
973
1105
  }
974
- function isNode$1(value) {
1106
+ /**
1107
+ * Resolve an explicit component type or a type uniquely identified by fields.
1108
+ *
1109
+ * @param value - Value to inspect without changing it.
1110
+ * @returns The explicit or inferred component type when available.
1111
+ */
1112
+ function nodeTypeOf(value) {
975
1113
  const candidate = record$1(value);
976
- return candidate !== void 0 && typeof candidate.type === "string";
1114
+ if (candidate === void 0) return void 0;
1115
+ if (typeof candidate.type === "string") return candidate.type;
1116
+ if ("type" in candidate) return void 0;
1117
+ const matches = [];
1118
+ if (Array.isArray(candidate.columns) && Array.isArray(candidate.rows)) matches.push("table");
1119
+ if (Array.isArray(candidate.pairs)) matches.push("keyvalue");
1120
+ if (Array.isArray(candidate.steps)) matches.push("steps");
1121
+ if (Array.isArray(candidate.diffs)) matches.push("diff");
1122
+ if (Array.isArray(candidate.meshes)) matches.push("scene3d");
1123
+ if (Array.isArray(candidate.tabs)) matches.push("tabs");
1124
+ return matches.length === 1 ? matches[0] : void 0;
1125
+ }
1126
+ /**
1127
+ * Check whether a value can be treated as a component node.
1128
+ *
1129
+ * @param value - Value to inspect without changing it.
1130
+ * @returns Whether the value has an explicit or uniquely inferred type.
1131
+ */
1132
+ function isNode$1(value) {
1133
+ return nodeTypeOf(value) !== void 0;
977
1134
  }
978
1135
  /** Fields a `stat` keeps when a metric record is folded into its own node. */
979
1136
  const STAT_METRIC_FIELDS = [
@@ -1092,12 +1249,25 @@ function defaultFileTreeDirectories(value) {
1092
1249
  if (out.children !== void 0) out.children = defaultFileTreeDirectories(out.children);
1093
1250
  return out;
1094
1251
  }
1252
+ /**
1253
+ * Normalize one component node and its renderer-reachable children.
1254
+ *
1255
+ * @param value - Raw component or other value.
1256
+ * @param path - Stable diagnostic path for this node.
1257
+ * @param warnings - Alias and structural normalization diagnostics.
1258
+ * @returns The normalized component, or the original value when it is not a node.
1259
+ */
1095
1260
  function normalizeNode(value, path, warnings) {
1096
- if (!isNode$1(value)) return value;
1097
- const type = value.type;
1261
+ const type = nodeTypeOf(value);
1262
+ const candidate = record$1(value);
1263
+ if (type === void 0 || candidate === void 0) return value;
1264
+ const node = typeof candidate.type === "string" ? candidate : {
1265
+ ...candidate,
1266
+ type
1267
+ };
1098
1268
  const definition = COMPONENT_SCHEMAS[type];
1099
- if (definition === void 0) return value;
1100
- const out = normalizeAliasFields(value, path, type, warnings);
1269
+ if (definition === void 0) return node;
1270
+ const out = normalizeAliasFields(node, path, type, warnings);
1101
1271
  for (const [field, nested] of Object.entries(definition.nested)) if (out[field] !== void 0) out[field] = normalizeRecordTree(out[field], nested, `${path}.${field}`, type, warnings);
1102
1272
  const normalizeNodeValue = (child, childPath) => normalizeNode(child, childPath, warnings);
1103
1273
  const normalizeNodeArray = (children, childPath) => Array.isArray(children) ? children.map((child, index) => normalizeNodeValue(child, `${childPath}[${index}]`)) : children;
@@ -1547,6 +1717,46 @@ function opt(key, value) {
1547
1717
  return value === void 0 ? {} : { [key]: value };
1548
1718
  }
1549
1719
  //#endregion
1720
+ //#region src/client/file-link.ts
1721
+ /** Decode a local file destination and its optional first line fragment. */
1722
+ function parseFileLink(value) {
1723
+ if (value.length > 2048) return void 0;
1724
+ const hash = value.indexOf("#");
1725
+ const destination = hash < 0 ? value : value.slice(0, hash);
1726
+ if (destination.includes("?")) return void 0;
1727
+ let path;
1728
+ try {
1729
+ path = decodeURIComponent(destination);
1730
+ } catch {
1731
+ return;
1732
+ }
1733
+ if (path === "" || /[\u0000-\u001f\u007f]/.test(path) || /^[\\/]{2}/.test(path) || /^[a-z][a-z\d+.-]*:/i.test(path) && !/^[a-z]:[\\/]/i.test(path)) return void 0;
1734
+ if (hash < 0) return { path };
1735
+ const match = /^L([1-9]\d*)(?:-L([1-9]\d*))?$/.exec(value.slice(hash + 1));
1736
+ if (match === null) return void 0;
1737
+ const line = Number(match[1]);
1738
+ const end = match[2] === void 0 ? line : Number(match[2]);
1739
+ if (!Number.isSafeInteger(line) || !Number.isSafeInteger(end) || end < line) return void 0;
1740
+ return {
1741
+ path,
1742
+ line
1743
+ };
1744
+ }
1745
+ /** Classify a link destination while preserving the existing external URL policy. */
1746
+ function classifyLinkTarget(value) {
1747
+ const external = safeHref(value);
1748
+ if (external !== void 0) return {
1749
+ type: "external",
1750
+ href: external
1751
+ };
1752
+ if (typeof value !== "string") return { type: "invalid" };
1753
+ const file = parseFileLink(value.trim());
1754
+ return file === void 0 ? { type: "invalid" } : {
1755
+ type: "file",
1756
+ file
1757
+ };
1758
+ }
1759
+ //#endregion
1550
1760
  //#region src/client/guard.ts
1551
1761
  function fieldKindMatches(value, kind) {
1552
1762
  switch (kind) {
@@ -1717,19 +1927,76 @@ function repairNodeFields(value, ctx, depth) {
1717
1927
  type: "text",
1718
1928
  content,
1719
1929
  ...opt("size", enu(v.size, TEXT_SIZES)),
1930
+ ...opt("align", enu(v.align, TEXT_ALIGNS)),
1931
+ ...opt("tone", enu(v.tone, TEXT_TONES)),
1932
+ ...opt("mono", v.mono === true ? true : void 0),
1720
1933
  ...opt("center", v.center === true ? true : void 0)
1721
1934
  };
1722
1935
  }
1936
+ case "icon": {
1937
+ const name = str(v.name, 64);
1938
+ if (name === void 0) return null;
1939
+ return {
1940
+ type: "icon",
1941
+ name,
1942
+ ...opt("label", str(v.label, GENUI_LIMITS.maxString)),
1943
+ ...opt("tone", enu(v.tone, ICON_TONES)),
1944
+ ...opt("size", int(v.size, 8, 96)),
1945
+ ...opt("tile", v.tile === true ? true : void 0)
1946
+ };
1947
+ }
1948
+ case "blocks": {
1949
+ if (!Array.isArray(v.rows)) return null;
1950
+ const rows = v.rows.slice(0, GENUI_LIMITS.maxBlocksRows).flatMap((entry) => {
1951
+ const row = obj(entry);
1952
+ if (row === void 0 || !Array.isArray(row.cells)) return [];
1953
+ return [{
1954
+ cells: row.cells.slice(0, GENUI_LIMITS.maxBlocksCells).map((cell) => {
1955
+ if (cell === null) return null;
1956
+ if (typeof cell === "string") return str(cell, GENUI_LIMITS.maxString) ?? "";
1957
+ const holder = obj(cell);
1958
+ if (holder === void 0) return null;
1959
+ const text = str(holder.text, GENUI_LIMITS.maxString);
1960
+ if (text === void 0) return null;
1961
+ return {
1962
+ text,
1963
+ ...opt("color", color(holder.color)),
1964
+ ...opt("tone", enu(holder.tone, BLOCK_CELL_TONES)),
1965
+ ...opt("sub", str(holder.sub, 128))
1966
+ };
1967
+ }),
1968
+ ...opt("label", str(row.label, 128)),
1969
+ ...opt("color", color(row.color)),
1970
+ ...opt("variant", enu(row.variant, BLOCKS_VARIANTS))
1971
+ }];
1972
+ });
1973
+ if (rows.length === 0) return null;
1974
+ return {
1975
+ type: "blocks",
1976
+ rows,
1977
+ ...opt("columns", int(v.columns, 1, GENUI_LIMITS.maxBlocksCells)),
1978
+ ...opt("title", str(v.title, GENUI_LIMITS.maxString)),
1979
+ ...opt("caption", str(v.caption, GENUI_LIMITS.maxString))
1980
+ };
1981
+ }
1982
+ case "arrow": return {
1983
+ type: "arrow",
1984
+ ...opt("dir", enu(v.dir, ARROW_DIRS)),
1985
+ ...opt("length", int(v.length, 16, 96)),
1986
+ ...opt("label", str(v.label, 200))
1987
+ };
1723
1988
  case "row": return {
1724
1989
  type: "row",
1725
1990
  items: repairItems(v.items, ctx, depth + 1),
1726
1991
  ...opt("wrap", v.wrap === true ? true : void 0),
1727
- ...opt("spacer", v.spacer === true ? true : void 0)
1992
+ ...opt("spacer", v.spacer === true ? true : void 0),
1993
+ ...opt("justify", enu(v.justify, ROW_JUSTIFY))
1728
1994
  };
1729
1995
  case "col": return {
1730
1996
  type: "col",
1731
1997
  items: repairItems(v.items, ctx, depth + 1),
1732
- ...opt("gap", num(v.gap, 0, 96))
1998
+ ...opt("gap", num(v.gap, 0, 96)),
1999
+ ...opt("width", num(v.width, 1, 100))
1733
2000
  };
1734
2001
  case "grid": return {
1735
2002
  type: "grid",
@@ -1739,9 +2006,11 @@ function repairNodeFields(value, ctx, depth) {
1739
2006
  case "card": return {
1740
2007
  type: "card",
1741
2008
  items: repairItems(v.items, ctx, depth + 1),
2009
+ ...opt("eyebrow", str(v.eyebrow, 64)),
1742
2010
  ...opt("title", str(v.title, GENUI_LIMITS.maxString)),
1743
2011
  ...opt("tone", enu(v.tone, CARD_TONES)),
1744
- ...opt("accent", color(v.accent))
2012
+ ...opt("accent", color(v.accent)),
2013
+ ...opt("flat", v.flat === true ? true : void 0)
1745
2014
  };
1746
2015
  case "button": {
1747
2016
  const label = str(v.label, GENUI_LIMITS.maxString);
@@ -1791,10 +2060,11 @@ function repairNodeFields(value, ctx, depth) {
1791
2060
  case "link": {
1792
2061
  const label = str(v.label, GENUI_LIMITS.maxString);
1793
2062
  if (label === void 0) return null;
2063
+ const target = classifyLinkTarget(v.href);
1794
2064
  return {
1795
2065
  type: "link",
1796
2066
  label,
1797
- ...opt("href", safeHref(v.href))
2067
+ ...opt("href", target.type === "external" ? target.href : target.type === "file" ? String(v.href).trim() : void 0)
1798
2068
  };
1799
2069
  }
1800
2070
  case "image": {
@@ -1803,7 +2073,8 @@ function repairNodeFields(value, ctx, depth) {
1803
2073
  return {
1804
2074
  type: "image",
1805
2075
  src,
1806
- ...opt("alt", str(v.alt, GENUI_LIMITS.maxString))
2076
+ ...opt("alt", str(v.alt, GENUI_LIMITS.maxString)),
2077
+ ...opt("caption", str(v.caption, GENUI_LIMITS.maxString))
1807
2078
  };
1808
2079
  }
1809
2080
  case "audio": {
@@ -1878,7 +2149,10 @@ function repairNodeFields(value, ctx, depth) {
1878
2149
  ...opt("target", num(v.target, 0, 100))
1879
2150
  };
1880
2151
  }
1881
- case "divider": return { type: "divider" };
2152
+ case "divider": return {
2153
+ type: "divider",
2154
+ ...opt("label", str(v.label, 64))
2155
+ };
1882
2156
  case "spacer": return { type: "spacer" };
1883
2157
  case "avatar": {
1884
2158
  const name = str(v.name, 64);
@@ -2736,8 +3010,14 @@ const GENUI_NODE_TYPES = GENUI_NATIVE_TYPES;
2736
3010
  * white-listed string, descending the same containers `countGenuiNodes`
2737
3011
  * walks. Callers can inspect field semantics or compare the count with the
2738
3012
  * repaired tree without maintaining another traversal.
3013
+ *
3014
+ * With `familyCaps` (default) the traversal applies the same per-family
3015
+ * policy caps repair enforces (tabs ≤ maxTabs, accordion items ≤
3016
+ * maxAccordionItems): nodes beyond a cap are policy-truncated, not defects,
3017
+ * so the declared-vs-rendered ledger must not count them as vanished (#298).
2739
3018
  */
2740
- function visitDeclaredGenuiNodes(value, cap, visit) {
3019
+ function visitDeclaredGenuiNodes(value, cap, visit, options = {}) {
3020
+ const familyCaps = options.familyCaps !== false;
2741
3021
  let count = 0;
2742
3022
  const declared = (candidate) => {
2743
3023
  const o = obj(candidate);
@@ -2756,9 +3036,13 @@ function visitDeclaredGenuiNodes(value, cap, visit) {
2756
3036
  if (v === void 0) return;
2757
3037
  count += 1;
2758
3038
  visit(v, at);
2759
- if (v.type === "tabs" && Array.isArray(v.tabs)) for (let tab = 0; tab < v.tabs.length; tab++) walkItemsOf(v.tabs[tab], `${at}.tabs[${tab}]`);
2760
- else if (v.type === "accordion" && Array.isArray(v.items)) for (let row = 0; row < v.items.length; row++) walkItemsOf(v.items[row], `${at}.items[${row}]`);
2761
- else if ((v.type === "row" || v.type === "col" || v.type === "grid" || v.type === "card") && Array.isArray(v.items)) walk(v.items, `${at}.items`);
3039
+ if (v.type === "tabs" && Array.isArray(v.tabs)) {
3040
+ const tabCount = familyCaps ? Math.min(v.tabs.length, GENUI_LIMITS.maxTabs) : v.tabs.length;
3041
+ for (let tab = 0; tab < tabCount; tab++) walkItemsOf(v.tabs[tab], `${at}.tabs[${tab}]`);
3042
+ } else if (v.type === "accordion" && Array.isArray(v.items)) {
3043
+ const rowCount = familyCaps ? Math.min(v.items.length, GENUI_LIMITS.maxAccordionItems) : v.items.length;
3044
+ for (let row = 0; row < rowCount; row++) walkItemsOf(v.items[row], `${at}.items[${row}]`);
3045
+ } else if ((v.type === "row" || v.type === "col" || v.type === "grid" || v.type === "card") && Array.isArray(v.items)) walk(v.items, `${at}.items`);
2762
3046
  else if (v.type === "list" && Array.isArray(v.items)) for (let row = 0; row < v.items.length; row++) walkNode(v.items[row], `${at}.items[${row}]`);
2763
3047
  else if (v.type === "table" && Array.isArray(v.details)) {
2764
3048
  const rowCount = tableRowsForDetails(v).length;
@@ -2782,10 +3066,11 @@ function visitDeclaredGenuiNodes(value, cap, visit) {
2782
3066
  * Count white-listed nodes declared by a raw spec before repair drops invalid entries.
2783
3067
  * @param value - raw GenUI spec.
2784
3068
  * @param cap - traversal ceiling.
3069
+ * @param options - `familyCaps: false` counts beyond per-family policy caps too.
2785
3070
  * @returns declared node count up to the ceiling.
2786
3071
  */
2787
- function countDeclaredGenuiNodes(value, cap = Number.POSITIVE_INFINITY) {
2788
- return visitDeclaredGenuiNodes(value, cap, () => {});
3072
+ function countDeclaredGenuiNodes(value, cap = Number.POSITIVE_INFINITY, options = {}) {
3073
+ return visitDeclaredGenuiNodes(value, cap, () => {}, options);
2789
3074
  }
2790
3075
  /** Count native nodes that survived repair, excluding opaque custom nodes. */
2791
3076
  function countRenderedNativeGenuiNodes(value, cap = Number.POSITIVE_INFINITY) {
@@ -2866,18 +3151,25 @@ function processGenuiSpec(value) {
2866
3151
  const repaired = repairCanonicalGenuiSpec(normalized.value);
2867
3152
  const validation = validateCanonicalGenuiSpec(normalized.value);
2868
3153
  const declaredNativeCount = countDeclaredGenuiNodes(normalized.value, GENUI_LIMITS.maxNodes + 1);
3154
+ const uncappedDeclaredCount = countDeclaredGenuiNodes(normalized.value, GENUI_LIMITS.maxNodes + 1, { familyCaps: false });
2869
3155
  const renderedNativeCount = repaired === null ? 0 : countRenderedNativeGenuiNodes(repaired);
2870
3156
  const renderedTotalCount = repaired === null ? 0 : countGenuiNodes(repaired);
2871
3157
  const errors = validation.errors.filter((error) => !error.includes(": unknown type "));
2872
3158
  if (repaired !== null && errors.length === 0) errors.push(...analyzeSubmissionRegistry(repaired).diagnostics);
2873
3159
  if (declaredNativeCount > renderedNativeCount) errors.push(`repair dropped ${declaredNativeCount - renderedNativeCount} declared native node(s): declared ${declaredNativeCount}, rendered ${renderedNativeCount}`);
3160
+ const warnings = [...normalized.warnings, ...diagnoseUnknownGenuiFields(normalized.value)];
3161
+ if (uncappedDeclaredCount > declaredNativeCount) warnings.push({
3162
+ kind: "truncated",
3163
+ path: "spec",
3164
+ message: `策略上限截断:${uncappedDeclaredCount - declaredNativeCount} 个声明节点超出 tabs ≤ ${GENUI_LIMITS.maxTabs} / accordion ≤ ${GENUI_LIMITS.maxAccordionItems} 的上限,未渲染;围栏照常渲染,重发时可拆分为多个组件`
3165
+ });
2874
3166
  return {
2875
3167
  value: normalized.value,
2876
3168
  normalized: normalized.value,
2877
3169
  repaired,
2878
3170
  spec: repaired,
2879
3171
  errors: [...new Set(errors)],
2880
- warnings: [...normalized.warnings, ...diagnoseUnknownGenuiFields(normalized.value)],
3172
+ warnings,
2881
3173
  declaredCount: declaredNativeCount,
2882
3174
  renderedCount: renderedTotalCount,
2883
3175
  declaredNativeCount,
@@ -3200,6 +3492,8 @@ function validateNode(value, depth, at, errors, walk) {
3200
3492
  case "diff":
3201
3493
  if (!Array.isArray(v.diffs)) errors.push(`${at}: type 'diff' requires diffs (array)`);
3202
3494
  break;
3495
+ case "divider":
3496
+ case "spacer": break;
3203
3497
  case "json":
3204
3498
  if (!("value" in v)) errors.push(`${at}: type 'json' requires value`);
3205
3499
  break;
@@ -3244,6 +3538,40 @@ function validateNode(value, depth, at, errors, walk) {
3244
3538
  if (typeof v.question !== "string") errors.push(`${at}: type 'quiz' requires question (string)`);
3245
3539
  if (!Array.isArray(v.options)) errors.push(`${at}: type 'quiz' requires options (array)`);
3246
3540
  break;
3541
+ case "blocks":
3542
+ if (!Array.isArray(v.rows)) {
3543
+ errors.push(`${at}: type 'blocks' requires rows (array)`);
3544
+ break;
3545
+ }
3546
+ isNum("columns");
3547
+ v.rows.forEach((entry, i) => {
3548
+ const row = obj(entry);
3549
+ if (row === void 0) {
3550
+ errors.push(`${at}.rows[${i}] must be an object`);
3551
+ return;
3552
+ }
3553
+ if (!Array.isArray(row.cells)) {
3554
+ errors.push(`${at}.rows[${i}].cells must be an array`);
3555
+ return;
3556
+ }
3557
+ row.cells.forEach((cell, j) => {
3558
+ if (cell === null || typeof cell === "string") return;
3559
+ const holder = obj(cell);
3560
+ if (holder === void 0) {
3561
+ errors.push(`${at}.rows[${i}].cells[${j}] must be a string, null, or object`);
3562
+ return;
3563
+ }
3564
+ if (typeof holder.text !== "string") errors.push(`${at}.rows[${i}].cells[${j}].text must be a string`);
3565
+ if (holder.tone !== void 0 && !BLOCK_CELL_TONES.includes(holder.tone)) errors.push(`${at}.rows[${i}].cells[${j}].tone must be one of ${BLOCK_CELL_TONES.join(", ")}`);
3566
+ if (holder.color !== void 0 && color(holder.color) === void 0) errors.push(`${at}.rows[${i}].cells[${j}].color must be a literal colour or host token`);
3567
+ });
3568
+ });
3569
+ break;
3570
+ case "icon":
3571
+ if (typeof v.name !== "string") errors.push(`${at}: type 'icon' requires name (string)`);
3572
+ isNum("size");
3573
+ break;
3574
+ case "arrow": break;
3247
3575
  case "diagram":
3248
3576
  if (typeof v.kind !== "string") errors.push(`${at}: type 'diagram' requires kind (string)`);
3249
3577
  if (!Array.isArray(v.nodes)) errors.push(`${at}: type 'diagram' requires nodes (array)`);
@@ -3253,7 +3581,7 @@ function validateNode(value, depth, at, errors, walk) {
3253
3581
  if (v.option === void 0 && v.data === void 0 && v.series === void 0 && (!Array.isArray(v.links) || v.links.length === 0)) errors.push(`${at}: type 'echart' requires option, data, series, or links`);
3254
3582
  isNum("height");
3255
3583
  break;
3256
- default: errors.push(`${at}: unknown type '${type}' (custom renderer?)`);
3584
+ default: if (!Object.hasOwn(COMPONENT_SCHEMAS, type)) errors.push(`${at}: unknown type '${type}' (custom renderer?)`);
3257
3585
  }
3258
3586
  const definition = COMPONENT_SCHEMAS[type];
3259
3587
  if (definition !== void 0) validateRegistryFields(v, at, definition, errors);
@@ -3270,6 +3598,7 @@ function validateNode(value, depth, at, errors, walk) {
3270
3598
  * with ASCII quotes (e.g. `对"别名路径"判定失败`), which makes JSON.parse
3271
3599
  * fail near that quote with "Expected ',' or ']'...".
3272
3600
  * 2. Trailing commas before `}` / `]` or at end of input.
3601
+ * 3. Valueless object keys immediately before a complete key-and-colon pair.
3273
3602
  *
3274
3603
  * A shared grammar-aware scan distinguishes object keys from values and
3275
3604
  * checks the continuation after a potential string terminator. Ambiguous
@@ -3292,6 +3621,33 @@ const MAX_QUOTE_LOOKAHEAD = 4096;
3292
3621
  function isJsonSpace(ch) {
3293
3622
  return ch === " " || ch === " " || ch === "\n" || ch === "\r";
3294
3623
  }
3624
+ /** Skip only complete, valueless object keys followed by a valued member. */
3625
+ function skipValuelessKeys(raw, start, limit = raw.length) {
3626
+ let cursor = start;
3627
+ let repairs = 0;
3628
+ while (cursor < limit && raw[cursor] === "\"") {
3629
+ const keyStart = cursor++;
3630
+ while (cursor < limit && raw[cursor] !== "\"") if (raw[cursor] === "\\") cursor += 2;
3631
+ else cursor++;
3632
+ if (cursor >= limit) return null;
3633
+ cursor++;
3634
+ try {
3635
+ JSON.parse(raw.slice(keyStart, cursor));
3636
+ } catch {
3637
+ return null;
3638
+ }
3639
+ while (cursor < limit && isJsonSpace(raw[cursor])) cursor++;
3640
+ if (raw[cursor] === ":") return repairs > 0 ? {
3641
+ start: keyStart,
3642
+ repairs
3643
+ } : null;
3644
+ if (raw[cursor] !== ",") return null;
3645
+ repairs++;
3646
+ cursor++;
3647
+ while (cursor < limit && isJsonSpace(raw[cursor])) cursor++;
3648
+ }
3649
+ return null;
3650
+ }
3295
3651
  /**
3296
3652
  * Quote closure is contextual: only keys may be followed by `:`, and a comma
3297
3653
  * must introduce the next member of the enclosing object/array. Walk closing
@@ -3330,6 +3686,8 @@ function quoteCanClose(raw, index, key, scopes, complete) {
3330
3686
  if (raw[cursor] === scope.closer) return true;
3331
3687
  if (scope.closer === "]") return /["[{tfn\-0-9]/.test(raw[cursor]);
3332
3688
  if (raw[cursor] !== "\"") return false;
3689
+ const valueless = skipValuelessKeys(raw, cursor, limit);
3690
+ if (valueless !== null) cursor = valueless.start;
3333
3691
  cursor++;
3334
3692
  while (cursor < limit) {
3335
3693
  if (raw[cursor] === "\\") {
@@ -3406,6 +3764,14 @@ function scanFenceCandidate(raw, complete, contentQuotes) {
3406
3764
  }
3407
3765
  if (ch === "\"") {
3408
3766
  key = scopes[scopes.length - 1]?.expecting === "key";
3767
+ if (key) {
3768
+ const valueless = skipValuelessKeys(raw, i);
3769
+ if (valueless !== null) {
3770
+ repairs += valueless.repairs;
3771
+ i = valueless.start - 1;
3772
+ continue;
3773
+ }
3774
+ }
3409
3775
  interiorQuote = false;
3410
3776
  inString = true;
3411
3777
  out += ch;
@@ -4132,6 +4498,8 @@ function formatProcessWarnings(processed) {
4132
4498
  const canonicalPath = `${separator < 0 ? "" : warning.path.slice(0, separator + 1)}${warning.canonical}`;
4133
4499
  return warning.message.includes("ignored") ? `warning=alias_ignored path=${warning.path} canonical=${canonicalPath}` : `warning=alias_normalized path=${warning.path} canonical=${canonicalPath}`;
4134
4500
  }
4501
+ if (warning.kind === "unknown-field") return `warning=unknown_field path=${JSON.stringify(warning.path)} detail=${JSON.stringify(warning.message)}`;
4502
+ if (warning.kind === "truncated") return `warning=policy_truncated path=${JSON.stringify(warning.path)} detail=${JSON.stringify(warning.message)}`;
4135
4503
  return `warning=process detail=${JSON.stringify(warning.message)}`;
4136
4504
  });
4137
4505
  }
@@ -4226,7 +4594,7 @@ function createRenderUiTool() {
4226
4594
  * before emitting — turning "render a red banner after the fact" into
4227
4595
  * "verify before you send". Purely local: no LLM, no network, no DOM.
4228
4596
  */
4229
- const VALIDATE_DESCRIPTION = "Validate the JSON body of a ```dsh-ui fence BEFORE emitting it — use for non-trivial specs (≥3 nodes or containing a table); skip for trivial ones (≤2 nodes). Pass the exact JSON text you are about to put inside the fence as the \"spec\" argument (a string). Returns a [genui-validation] protocol block with status, diagnostics, next action, and reply_language=conversation. When invalid JSON is repairable, repaired_json contains the fixed body; emit it only with next=emit_repaired_fence. A warning=block_markdown requires the indicated replacement node and another validation call.";
4597
+ const VALIDATE_DESCRIPTION = "Validate the JSON body of a ```dsh-ui fence BEFORE emitting it — use for non-trivial specs (≥3 nodes or containing a table); skip for trivial ones (≤2 nodes). Pass the exact JSON text you are about to put inside the fence as the \"spec\" argument (a string). Returns a [genui-validation] protocol block with status, diagnostics, next action, and reply_language=conversation. When invalid JSON is repairable, repaired_json contains the fixed body; emit it only with next=emit_repaired_fence. A warning=unknown_field requires fixing the indicated path and another validation call. A warning=block_markdown requires the indicated replacement node and another validation call.";
4230
4598
  const VALIDATE_PARAMETERS = {
4231
4599
  type: "object",
4232
4600
  properties: { spec: {
@@ -4342,6 +4710,7 @@ function createValidateDshUiTool() {
4342
4710
  if (processed.spec !== null && processed.errors.length === 0) {
4343
4711
  const warnings = formatProcessWarnings(processed);
4344
4712
  const inlineWarnings = formatInlineContentWarnings(processed.spec);
4713
+ const requiresCorrection = inlineWarnings.length > 0 || processed.warnings.some((warning) => warning.kind === "unknown-field");
4345
4714
  return `${validationProtocol([
4346
4715
  "status=invalid",
4347
4716
  "error=invalid_json",
@@ -4351,7 +4720,7 @@ function createValidateDshUiTool() {
4351
4720
  ...inlineWarnings,
4352
4721
  "repair=applied",
4353
4722
  `repair_count=${repaired.repairs}`,
4354
- inlineWarnings.length === 0 ? "next=emit_repaired_fence" : "next=fix_and_revalidate"
4723
+ requiresCorrection ? "next=fix_and_revalidate" : "next=emit_repaired_fence"
4355
4724
  ])}\nrepaired_json:\n\`\`\`\n${repaired.text}\n\`\`\``;
4356
4725
  }
4357
4726
  }
@@ -4383,12 +4752,13 @@ function createValidateDshUiTool() {
4383
4752
  }
4384
4753
  const warnings = formatProcessWarnings(processed);
4385
4754
  const inlineWarnings = formatInlineContentWarnings(processed.spec);
4755
+ const requiresCorrection = inlineWarnings.length > 0 || processed.warnings.some((warning) => warning.kind === "unknown-field");
4386
4756
  return validationProtocol([
4387
4757
  "status=valid",
4388
4758
  `rendered=${processed.renderedCount}`,
4389
4759
  ...warnings,
4390
4760
  ...inlineWarnings,
4391
- inlineWarnings.length === 0 ? "next=emit_fence" : "next=fix_and_revalidate"
4761
+ requiresCorrection ? "next=fix_and_revalidate" : "next=emit_fence"
4392
4762
  ]);
4393
4763
  },
4394
4764
  presentCall() {
@@ -4479,6 +4849,8 @@ function trySpec(candidate, allowSingleComponentRoot) {
4479
4849
  return null;
4480
4850
  }
4481
4851
  if (isGenuiSpec(value)) return value;
4852
+ const envelope = adoptSingleItemEnvelope(value);
4853
+ if (envelope !== null) return envelope;
4482
4854
  if (Array.isArray(value) && value.length > 0) return { items: value };
4483
4855
  return allowSingleComponentRoot ? wrapSingleComponentRoot(value) : null;
4484
4856
  } catch {
@@ -4507,7 +4879,7 @@ function parsePartialGenuiSpec(raw) {
4507
4879
  //#region src/shared/fence-resolve.ts
4508
4880
  /**
4509
4881
  * 使用浏览器 renderer 与 Node 侧最终回复反馈守卫共用的流程解析 dsh-ui 围栏正文。
4510
- * @module @changfenhuang/dsh-genui/shared/fence-resolve
4882
+ * @module @sparkelf/dsh-genui/shared/fence-resolve
4511
4883
  */
4512
4884
  /**
4513
4885
  * 对已经解析的值执行规格守卫和坏节点清理。
@@ -4557,17 +4929,47 @@ function resolveFence(raw, options) {
4557
4929
  return reparsed === null ? unresolvedFence() : resolveParsedFence(reparsed);
4558
4930
  }
4559
4931
  //#endregion
4932
+ //#region src/shared/fence-language.ts
4933
+ /** 围栏开头的 `dsh-ui` 标签在书写时可能被带上标点(```dsh-ui> / ```dsh-ui` …)。
4934
+ * 这类标记在 mdast 里原样留在 `lang` 上,严格相等判断会让整条围栏静默退化成
4935
+ * 普通代码块——真实会话里同一个模型可以在一条消息里写出 182 个这样的围栏。
4936
+ * 这里只吸收**标签之后**的标点,`dsh-ui-something` 这样的真实语言名不受影响。 */
4937
+ const GENUI_LABEL_PATTERN = /^dsh-ui$/;
4938
+ const GENUI_TRAILING_PUNCTUATION = /[>`"'.,;:)\]】」』]+$/;
4939
+ /**
4940
+ * 把宿主的围栏语言标记规范化成 GenUI 能识别的写法。
4941
+ *
4942
+ * @param lang - 宿主 markdown 里的原始 language(可能含尾部标点或大小写差异)
4943
+ * @returns 规范化后的语言名;无法规范化时返回输入本身
4944
+ */
4945
+ function normalizeFenceLanguage(lang) {
4946
+ const trimmed = lang.trim();
4947
+ if (GENUI_LABEL_PATTERN.test(trimmed.toLowerCase())) return "dsh-ui";
4948
+ const stripped = trimmed.replace(GENUI_TRAILING_PUNCTUATION, "").trim().toLowerCase();
4949
+ if (GENUI_LABEL_PATTERN.test(stripped)) return "dsh-ui";
4950
+ return lang;
4951
+ }
4952
+ /**
4953
+ * 判断语言标记是否指向 GenUI 围栏。
4954
+ *
4955
+ * @param lang - 宿主暴露的围栏语言(`null` = 围栏没有语言)
4956
+ * @returns 规范化为 `dsh-ui` 时返回 true
4957
+ */
4958
+ function isGenuiFenceLanguage(lang) {
4959
+ return typeof lang === "string" && normalizeFenceLanguage(lang) === "dsh-ui";
4960
+ }
4961
+ //#endregion
4560
4962
  //#region src/plugin/fence-feedback.ts
4561
4963
  /** Plugin name recorded on every message this loop steers. */
4562
- const FEEDBACK_PLUGIN_NAME = "@changfenhuang/dsh-genui";
4964
+ const FEEDBACK_PLUGIN_NAME = "@sparkelf/dsh-genui";
4563
4965
  /** Source kind persisted by this plugin in Session format v4. */
4564
4966
  const FEEDBACK_SOURCE_KIND = `plugin:${FEEDBACK_PLUGIN_NAME}`;
4565
4967
  /** Marker prefix inside the correction text: `[genui-fence-repair #<fingerprint>]`. */
4566
4968
  const MARKER_PREFIX = "[genui-fence-repair #";
4567
4969
  /** Marker prefix written by older plugin versions. */
4568
4970
  const LEGACY_MARKER_PREFIX = "[genui 自修 #";
4569
- /** A fence opener is an info string of exactly `dsh-ui` (≤3 spaces indent). */
4570
- const FENCE_OPEN = /^ {0,3}```[ \t]*dsh-ui[ \t]*$/u;
4971
+ /** Read one language token (≤3 spaces indent); backticks are invalid in a backtick info string. */
4972
+ const FENCE_OPEN = /^ {0,3}```[ \t]*([^` \t]+)[ \t]*$/u;
4571
4973
  /** Any fence closer (the renderer never nests fences in one body). */
4572
4974
  const FENCE_CLOSE = /^ {0,3}```[ \t]*$/u;
4573
4975
  /** Upper bound on fences inspected per reply — a reply is text, not a corpus. */
@@ -4585,7 +4987,8 @@ function extractDshUiFences(text) {
4585
4987
  for (let line = 0; line < lines.length; line++) {
4586
4988
  const current = lines[line] ?? "";
4587
4989
  if (open === null) {
4588
- if (FENCE_OPEN.test(current)) open = {
4990
+ const label = FENCE_OPEN.exec(current)?.[1];
4991
+ if (isGenuiFenceLanguage(label)) open = {
4589
4992
  start: line + 1,
4590
4993
  index: fences.length + 1
4591
4994
  };
@@ -4631,9 +5034,9 @@ function fenceFailures(text) {
4631
5034
  }
4632
5035
  /** `null` when this fence renders; otherwise the reason it does not. */
4633
5036
  function fenceFailureDetail(fence) {
4634
- if (!fence.closed) return "error=unterminated_fence\nrequired=closing_fence";
4635
5037
  const resolution = resolveFence(fence.raw, { settled: true });
4636
5038
  if (resolution.spec !== null) return null;
5039
+ if (!fence.closed) return "error=unterminated_fence\nrequired=closing_fence";
4637
5040
  if (resolution.processed !== null) return droppedNodeFailure(resolution.processed, resolution.value)?.join("\n") ?? ["error=invalid_spec", ...resolution.processed.errors.map((error) => `diagnostic=${JSON.stringify(error)}`)].join("\n");
4638
5041
  return "error=invalid_json\nrepair=failed";
4639
5042
  }
@@ -4710,7 +5113,7 @@ function planFenceFeedback(input) {
4710
5113
  if (input.validatedThisTurn !== true || input.deliveredThisTurn === true) return null;
4711
5114
  if (input.deliveryRemindedTurns?.has(input.turn) === true) return null;
4712
5115
  return {
4713
- text: missingBodyCorrectionText(input.turn, used + 1),
5116
+ text: missingBodyCorrectionText(input.turn, used + 1, input.renderUiToolEnabled ?? true),
4714
5117
  fingerprints: [],
4715
5118
  turn: input.turn,
4716
5119
  kind: "delivery"
@@ -4722,19 +5125,27 @@ function planFenceFeedback(input) {
4722
5125
  *
4723
5126
  * @param turn - turn that reached the boundary.
4724
5127
  * @param attempt - correction number within the shared turn budget.
5128
+ * @param renderUiToolEnabled - whether the correction may recommend `render_ui`.
4725
5129
  * @returns the message text to steer into the running turn.
4726
5130
  */
4727
- function missingBodyCorrectionText(turn, attempt = 1) {
4728
- return `${`${MARKER_PREFIX}turn-${turn}]\n\n[genui-fence-repair]\nstatus=nothing_delivered\nfences=0\nnext=emit_fence_in_body\nrepeat_rendered_content=false\nreply_language=conversation\n\n`}本轮尚未产生正式回答,也没有通过支持的通道交付结果${attempt <= 1 ? "" : `(第 ${attempt} 次提醒)`}。请根据用户当前请求完成正式答复;需要 UI 时,在回答正文输出你最终选定的 dsh-ui 围栏,或明确调用 render_ui。可以修改或放弃此前候选;不能完成时,请在正文说明原因。\n`;
5131
+ function missingBodyCorrectionText(turn, attempt = 1, renderUiToolEnabled = true) {
5132
+ return `${`${MARKER_PREFIX}turn-${turn}]\n\n[genui-fence-repair]\nstatus=nothing_delivered\nfences=0\nnext=emit_fence_in_body\nrepeat_rendered_content=false\nreply_language=conversation\n\n`}本轮尚未产生正式回答,也没有通过支持的通道交付结果${attempt <= 1 ? "" : `(第 ${attempt} 次提醒)`}。请根据用户当前请求完成正式答复;需要 UI 时,在回答正文输出你最终选定的 dsh-ui 围栏${renderUiToolEnabled ? ",或明确调用 render_ui" : ""}。可以修改或放弃此前候选;不能完成时,请在正文说明原因。\n`;
4729
5133
  }
4730
5134
  /**
4731
5135
  * 将 GenUI 回合中仅含 reasoning 的完整响应转换为宿主已有的可重试空响应错误。
4732
5136
  *
5137
+ * 只有回合边界确实还能发送交付提醒时,才放行原始 stop,
5138
+ * 让回合正常结束并走到 `agent/turn-stopping` 边界——那里会 steer 一条交付提醒,
5139
+ * 回合因此继续到下一个 step,模型有机会在同一回合把内容补进正文。
5140
+ * 提醒发过仍然只有 reasoning,才用 EMPTY_RESPONSE 交给宿主重试兜底。
5141
+ *
4733
5142
  * @param options - LLM stream waterfall 拦截的请求。
4734
5143
  * @param source - 本次请求的 provider stream。
4735
- * @returns 原始 stream;仅符合条件的终止 stop 会被改写。
5144
+ * @param state - 当前回合状态;缺省时没有可用提醒,保留宿主重试。
5145
+ * @param feedbackEnabled - 同回合修正是否启用。关闭时没有提醒可用,保持原有改写行为。
5146
+ * @returns 原始 stream;仅在提醒已发出、或提醒不可用时改写 reasoning-only 终止。
4736
5147
  */
4737
- async function* retryReasoningOnlyGenuiStream(options, source) {
5148
+ async function* retryReasoningOnlyGenuiStream(options, source, state, feedbackEnabled = true) {
4738
5149
  const { EMPTY_RESPONSE_CODE, isAgentLoopRequest } = await import("@deepseek-ai/dsh-llm");
4739
5150
  if (!isAgentLoopRequest(options)) {
4740
5151
  yield* source;
@@ -4747,17 +5158,32 @@ async function* retryReasoningOnlyGenuiStream(options, source) {
4747
5158
  if (chunk.block.type === "reasoning") hasReasoningBlock = true;
4748
5159
  else hasOtherBlock = true;
4749
5160
  }
4750
- if (chunk.type === "finish" && chunk.reason.kind === "stop" && hasReasoningBlock && !hasOtherBlock) yield {
4751
- type: "finish",
4752
- reason: {
4753
- kind: "error",
4754
- failure: {
4755
- message: "GenUI turn completed with reasoning only and no deliverable response",
4756
- code: EMPTY_RESPONSE_CODE
4757
- }
5161
+ if (chunk.type === "finish" && chunk.reason.kind === "stop" && hasReasoningBlock && !hasOtherBlock) {
5162
+ if (feedbackEnabled && state !== void 0 && state.currentTurn !== void 0 && state.pendingRenders.size === 0 && planFenceFeedback({
5163
+ text: "",
5164
+ turn: state.currentTurn,
5165
+ correctedSpec: state.correctedSpec,
5166
+ deliveryRemindedTurns: state.deliveryRemindedTurns,
5167
+ validatedThisTurn: state.validatedThisTurn,
5168
+ deliveredThisTurn: state.deliveredThisTurn,
5169
+ aborted: options.signal?.aborted ?? false,
5170
+ correctionsThisTurn: state.correctionsThisTurn,
5171
+ correctionsTurn: state.correctionsTurn
5172
+ })?.kind === "delivery") {
5173
+ yield chunk;
5174
+ continue;
4758
5175
  }
4759
- };
4760
- else yield chunk;
5176
+ yield {
5177
+ type: "finish",
5178
+ reason: {
5179
+ kind: "error",
5180
+ failure: {
5181
+ message: "GenUI turn completed with reasoning only and no deliverable response",
5182
+ code: EMPTY_RESPONSE_CODE
5183
+ }
5184
+ }
5185
+ };
5186
+ } else yield chunk;
4761
5187
  }
4762
5188
  }
4763
5189
  /** Text of one assistant message's text blocks, in order. */
@@ -4854,15 +5280,16 @@ function accountReplayedCorrection(state, turn) {
4854
5280
  }
4855
5281
  /** Identify this plugin's source across current and migrated session shapes. */
4856
5282
  function isFeedbackSource(source) {
4857
- return source?.kind === FEEDBACK_SOURCE_KIND || source?.kind === "plugin" && source.plugin === "@changfenhuang/dsh-genui";
5283
+ return source?.kind === FEEDBACK_SOURCE_KIND || source?.kind === "plugin" && source.plugin === "@sparkelf/dsh-genui";
4858
5284
  }
4859
5285
  /**
4860
5286
  * 注册 GenUI 回合跟踪、宿主重试判定和可选的围栏修正流程。
4861
5287
  *
4862
5288
  * @param ctx - 宿主 Context。
4863
5289
  * @param enabled - 是否启用同回合围栏修正。
5290
+ * @param renderUiToolEnabled - 是否已注册 `render_ui` 工具。
4864
5291
  */
4865
- function installFenceFeedback(ctx, enabled) {
5292
+ function installFenceFeedback(ctx, enabled, renderUiToolEnabled = true) {
4866
5293
  const sessions = /* @__PURE__ */ new Map();
4867
5294
  const stateOf = (sessionId) => {
4868
5295
  let state = sessions.get(sessionId);
@@ -4973,7 +5400,7 @@ function installFenceFeedback(ctx, enabled) {
4973
5400
  if (options.sessionId === void 0 || options.purpose !== void 0) return next();
4974
5401
  const state = sessions.get(String(options.sessionId));
4975
5402
  if (state?.validatedThisTurn !== true || state.isSubagent) return next();
4976
- return retryReasoningOnlyGenuiStream(options, next());
5403
+ return retryReasoningOnlyGenuiStream(options, next(), state, enabled);
4977
5404
  }, { global: true });
4978
5405
  ctx.on("agent/turn-stopping", ({ agent, turn, signal }) => {
4979
5406
  if (!enabled) return;
@@ -4992,7 +5419,8 @@ function installFenceFeedback(ctx, enabled) {
4992
5419
  deliveredThisTurn: state.deliveredThisTurn,
4993
5420
  aborted: signal.aborted,
4994
5421
  correctionsThisTurn: usedThisTurn,
4995
- correctionsTurn: state.correctionsTurn
5422
+ correctionsTurn: state.correctionsTurn,
5423
+ renderUiToolEnabled
4996
5424
  });
4997
5425
  if (plan === null) return;
4998
5426
  for (const fingerprint of plan.fingerprints) state.correctedSpec.add(fingerprint);
@@ -5021,7 +5449,7 @@ function installFenceFeedback(ctx, enabled) {
5021
5449
  * and plugin reloads.
5022
5450
  */
5023
5451
  /** Route prefix under /plugins; anything under it is this plugin's asset. */
5024
- const ASSET_ROUTE_PATH = "/plugins/@changfenhuang/dsh-genui/assets";
5452
+ const ASSET_ROUTE_PATH = "/plugins/@sparkelf/dsh-genui/assets";
5025
5453
  /** Safe flat file names only: no slashes, no traversal, js assets only. */
5026
5454
  const ASSET_FILE_RE = /^[A-Za-z0-9][A-Za-z0-9._-]*\.js$/;
5027
5455
  /** The handler itself (registered via the optional webServer probe). */
@@ -5039,7 +5467,7 @@ async function serveGenuiAsset(req, res) {
5039
5467
  res.end();
5040
5468
  return;
5041
5469
  }
5042
- const rel = pathname.startsWith(`${ASSET_ROUTE_PATH}/`) ? pathname.slice(40) : null;
5470
+ const rel = pathname.startsWith(`${ASSET_ROUTE_PATH}/`) ? pathname.slice(35) : null;
5043
5471
  if (rel === null) {
5044
5472
  res.writeHead(404);
5045
5473
  res.end();
@@ -5064,11 +5492,12 @@ async function serveGenuiAsset(req, res) {
5064
5492
  res.end();
5065
5493
  }
5066
5494
  }
5495
+ const RENDER_UI_TOOL_GUIDANCE = "- Tool channel: render_ui 工具把同一 spec 渲染为工具行卡片;围栏用于回答内联 UI。";
5067
5496
  /** The fence language description injected into every assembled system prompt.
5068
5497
  * Deliberately slim: the `genui` skill carries the full component→field
5069
5498
  * mapping; this section keeps only the contract that must always be
5070
5499
  * present (fence syntax, type whitelist, and critical behavioral rules). */
5071
- const GENUI_SECTION_TEXT = `You can render interactive UI components INSIDE your reply — between paragraphs — by emitting a fenced block with the language tag \`dsh-ui\` containing a JSON spec:
5500
+ const GENUI_SECTION_TEXT = `Render UI inside your reply with a fenced \`dsh-ui\` JSON block:
5072
5501
 
5073
5502
  \`\`\`dsh-ui
5074
5503
  {"title":"<user-language text>","gap":14,"items":[...]}
@@ -5077,21 +5506,23 @@ const GENUI_SECTION_TEXT = `You can render interactive UI components INSIDE your
5077
5506
  Allowed \`type\` values; the \`genui\` skill, when available, carries the full content→component mapping and per-component field details:
5078
5507
 
5079
5508
  - 布局: text · row · col · grid · card · divider · spacer · hero(封面块,一条回答最多一个)
5080
- - 展示: badge · stat · progress · list · table · keyvalue · timeline · file-tree · breadcrumb · callout · steps · diff · json · code · copy · avatar · audio · video
5081
- - 图表: chart {"kind":"bars|line|donut","data":[{"label":"...","value":n}],"series":[{"label":"...","data":[...]}]?,"horizontal":true?,"stacked":true?}(series:bars 分组/堆叠 / line 多序列;horizontal 横向柱) · echart (preset 名或 option 直通,预设清单见 skill) · plot (函数图)
5082
- - 交互: button · input · textarea · select · checkbox · switch · slider · radio · submit · quiz · link · tabs · accordion
5083
- - 高级: mermaid (流程图/时序/甘特/ER 等,关键字见 skill) · diagram (架构/流程图,27 种 kind) · scene3d (3D WebGL)
5509
+ - 展示: badge · stat · progress · list · table · keyvalue · timeline · file-tree · breadcrumb · callout · steps · diff · json · code · copy · avatar · image · audio · video · icon · blocks · arrow
5510
+ - 图表: chart {"kind":"bars|line|donut","data":[{"label":"...","value":n}]}(series:bars 分组/堆叠 / line 多序列) · echart (preset 名或 option 直通,清单见 skill) · plot (函数图) · svg (单图预览)
5511
+ - 交互: button · input · textarea · select · checkbox · switch · slider · radio · submit · quiz · link · tabs · accordion(row.justify / col.width / card.flat 见图元)
5512
+ - 高级: mermaid (流程图/时序/甘特/ER 等,关键字见 skill) · diagram (架构/流程图) · scene3d (3D WebGL)
5084
5513
 
5085
5514
  **默认就该出 UI**:出现下列情况至少出一个围栏:
5086
5515
  - ≥3 条并列要点 → \`list\`;数字对比 → \`table\`;指标/进度/状态 → \`stat\`/\`progress\`/\`badge\`
5087
- - 步骤/时间线 → \`steps\`/\`timeline\`/\`mermaid\`;架构/流程 → \`diagram\` 或 \`mermaid\`;风险/结论 → \`callout\`;代码/改动 → \`code\`/\`diff\`/\`json\`
5088
- - 行内富文本:支持公式、\`code\`、加粗、高亮、链接;禁用 Markdown table / fenced code,改用 table / code / diff / json。
5089
- - 默认无卡:按触发条件使用组件,每个组件承载不同信息;卡片只用于并排项与数据对象,单段文字用标题、正文与间距。
5516
+ - 步骤/时间线 → \`steps\`/\`timeline\`/\`mermaid\`;架构/流程 → \`diagram\` 或 \`mermaid\`;单条风险/结论摘要 → \`callout\`;代码/改动 → \`code\`/\`diff\`/\`json\`
5517
+ - 行内富文本:支持公式、\`code\`、加粗、高亮、链接;禁用 Markdown table 与 fenced code,改用 table/code/diff/json。
5518
+ - 默认无卡:卡片用于并排项、数据对象或需底色的风险清单。
5090
5519
 
5091
- **发回答前最后自检一次**:这段内容里有没有 ≥3 条并列要点、任何对比、任何数字/指标、任何步骤或流程?有就先转成组件再开口。**状态汇报、进度说明、提交与改动清单同样算**。
5092
- - 趋势/占比 → \`chart\`(≤8 点)或 \`echart\`(多序列/要交互时);配色默认跟随主题,只有语义需要时才用 \`palette\`/\`card.accent\`;grid 子节点用 \`"span":2\` 跨列做宽窄混排;数据多时给 \`table\`/\`chart\`/\`list\` 配一个 \`input\`(id) + \`filter\` 绑定,读者能就地筛选。
5520
+ **发回答前最后自检一次**:有没有 ≥3 条并列要点、任何对比、任何数字/指标、任何步骤或流程?有就先转成组件。**状态汇报、进度说明、提交与改动清单同样算**。
5521
+ - 趋势/占比 → \`chart\`(≤8 点)或 \`echart\`;配色跟随主题,语义需要时才用 \`palette\`/\`card.accent\`;grid 子节点用 \`"span":2\` 做宽窄混排;数据多时给 \`table\`/\`list\` 配 \`input\`(id)+\`filter\` 就地筛选。
5522
+ - 多组件回答先套 skill「编排范式」,别一行一个往下堆;章节分隔 \`divider\` 带 \`label\`。
5093
5523
 
5094
- **字段速查**(完整见 genui skill):\`stat\` \`{"label","value","delta"?}\` · \`table\` \`{"columns":[...],"rows":[[...]],"types"?,"details"?,"filter"?,"export"?}\` · \`progress\` \`{"value":0-100,"label"?,"variant"?,"target"?}\` · \`keyvalue\` \`{"pairs":[{"key","value"}]}\` · \`steps\` \`{"steps":[{"title","desc"?}]}\` · \`file-tree\` \`{"items":[{"name","type":"file|dir","children"?}]}\` · \`callout\` \`{"content","tone"?,"title"?}\`
5524
+ **字段速查**(完整见 genui skill):\`stat\` \`{"type":"stat","label","value"}\` · \`table\` \`{"type":"table","columns":[...],"rows":[[...]]}\` · \`progress\` \`{"type":"progress","value":0-100}\` · \`keyvalue\` \`{"type":"keyvalue","pairs":[{"key","value"}]}\` · \`steps\` \`{"type":"steps","steps":[{"title"}]}\` · \`file-tree\` \`{"type":"file-tree","items":[{"name","type":"file|dir"}]}\` · \`callout\` \`{"type":"callout","content"}\`
5525
+ **节点规则:** 组件节点必须带字符串 \`type\`,值为组件名;\`file-tree.items[].type\` 表示 \`file\` 或 \`dir\`。
5095
5526
 
5096
5527
  **字段名写错 = 该组件被丢弃**(其余组件照常渲染):\`callout\` 正文是 \`content\` 不是 text/desc;\`table\` 要 \`columns\`+\`rows\` 不是 items;\`keyvalue\` 记录是 \`{key,value}\` 不是 \`{label,value}\`;\`file-tree\` 记录是 \`{name,type}\` 不是 \`{label}\`;callout tone 是 info/success/warning/error(无 danger)。不确定就调 \`validate_dsh_ui\`。
5097
5528
 
@@ -5104,22 +5535,31 @@ Rules:
5104
5535
  - Durable state: 交互状态按「会话+内容指纹」持久化——刷新/重放恢复;相同内容保留,新内容重置。
5105
5536
  - 卷子模式: 每题一个 radio(group+answer+explanation)+ 一个 submit(groups 全列),本地判分。
5106
5537
  - Secrets ban: 不索取密码、API Key、Token、恢复码;需要时拒绝并解释。
5107
- - Tool channel: render_ui 工具把同一 spec 渲染为工具行卡片;围栏用于回答内联 UI。
5538
+ ${RENDER_UI_TOOL_GUIDANCE}
5108
5539
  - 围栏位置:\`dsh-ui\` 只写在**回答正文**;写在 reasoning/思考块里不渲染、用户看不到——思考里验证好 spec,正文再输出同一份。
5109
5540
  - Panel: "panel":true 只渲染进会话面板 dock 并原地更新;"append":true 追加合并;上限 200 节点/200 次追加,满了发 replace 重建。面板来的 [genui-action] 只回一个 panel:true 围栏 + 至多一行 10 字内确认。`;
5110
5541
  /**
5111
5542
  * Register the GenUI output-language section and the render_ui tool.
5112
5543
  * @param ctx - cordis context.
5113
5544
  */
5114
- const name = "@changfenhuang/dsh-genui";
5545
+ const name = "@sparkelf/dsh-genui";
5115
5546
  const inject = ["systemPrompt"];
5116
5547
  const BUNDLED_SKILL_RANK = 600;
5117
5548
  const BUNDLED_SKILL_PROVIDER = "dsh-genui";
5118
- const BUNDLED_SKILL_DESCRIPTION = "GenUI dsh-ui component/schema reference. Preserve conversation language for all user-visible text.";
5119
5549
  const BUNDLED_SKILL_INVOCATION = {
5120
5550
  modelInvocable: true,
5121
5551
  userInvocable: true
5122
5552
  };
5553
+ /**
5554
+ * The frontmatter field the routing description comes from.
5555
+ *
5556
+ * A second copy of this sentence in code drifted from SKILL.md unnoticed, and the
5557
+ * panel showed the code copy while the model read the same string — so an edit to
5558
+ * the skill's own frontmatter changed nothing. The file is the only source.
5559
+ */
5560
+ function frontmatterField(front, key) {
5561
+ return new RegExp("^\\s*" + key + "\\s*:\\s*(.+?)\\s*$", "mu").exec(front)?.[1]?.replace(/^['"]|['"]$/gu, "");
5562
+ }
5123
5563
  /** Register through the provider path so source=bundled also gets bundled precedence. */
5124
5564
  function bundledSkillProvider() {
5125
5565
  const moduleDirectory = dirname(fileURLToPath(new URL(import.meta.url)));
@@ -5127,11 +5567,13 @@ function bundledSkillProvider() {
5127
5567
  const raw = readFileSync(path, "utf8");
5128
5568
  const end = raw.indexOf("\n---\n", 4);
5129
5569
  if (!raw.startsWith("---\n") || end < 0) throw new Error("genui SKILL.md has invalid frontmatter");
5570
+ const description = frontmatterField(raw.slice(4, end), "description");
5571
+ if (description === void 0) throw new Error("genui SKILL.md frontmatter has no description");
5130
5572
  return {
5131
5573
  name: BUNDLED_SKILL_PROVIDER,
5132
5574
  list: () => Promise.resolve([{
5133
5575
  name: "genui",
5134
- description: BUNDLED_SKILL_DESCRIPTION,
5576
+ description,
5135
5577
  invocation: BUNDLED_SKILL_INVOCATION,
5136
5578
  source: "bundled",
5137
5579
  provider: BUNDLED_SKILL_PROVIDER,
@@ -5145,7 +5587,7 @@ function bundledSkillProvider() {
5145
5587
  }]),
5146
5588
  get: () => Promise.resolve({
5147
5589
  name: "genui",
5148
- description: BUNDLED_SKILL_DESCRIPTION,
5590
+ description,
5149
5591
  invocation: BUNDLED_SKILL_INVOCATION,
5150
5592
  source: "bundled",
5151
5593
  provider: BUNDLED_SKILL_PROVIDER,
@@ -5159,15 +5601,16 @@ function bundledSkillProvider() {
5159
5601
  };
5160
5602
  }
5161
5603
  function apply(ctx, config) {
5604
+ const renderUiToolEnabled = config?.renderUiTool !== false;
5162
5605
  ctx.systemPrompt.section({
5163
5606
  name: "genui:fence",
5164
5607
  order: ctx.systemPrompt.getSectionOrder("STRUCTURED_OUTPUT"),
5165
- text: GENUI_SECTION_TEXT
5608
+ text: renderUiToolEnabled ? GENUI_SECTION_TEXT : GENUI_SECTION_TEXT.replace(`${RENDER_UI_TOOL_GUIDANCE}\n`, "")
5166
5609
  });
5167
- installFenceFeedback(ctx, config?.fenceFeedback !== false);
5610
+ installFenceFeedback(ctx, config?.fenceFeedback !== false, renderUiToolEnabled);
5168
5611
  ctx.inject(["tools"], (toolsCtx) => {
5169
5612
  toolsCtx.effect(function* () {
5170
- yield toolsCtx.tools.register(createRenderUiTool());
5613
+ if (renderUiToolEnabled) yield toolsCtx.tools.register(createRenderUiTool());
5171
5614
  yield toolsCtx.tools.register(createValidateDshUiTool());
5172
5615
  }, "dsh-genui: model tools");
5173
5616
  });