Skip to content

Commit a2779d6

Browse files
committed
refactor(config-generator): move preview descriptions into the outputs DSL
Raise the configuration DSL to version 5 and remove the separate config-desc block. Per-line preview explanations now live on the output tree: `description` is a common attribute on output nodes, and an `<enum options="field">` output shows the selected option's description, falling back to the node's own. The preview walks the declared outputs against the projected value, so annotations match the generated structure exactly instead of being matched heuristically. Rewrite dsl/description.rs as dsl/preview.rs, dropping conditions and the config-desc parser, and expose Document::preview_lines. Snapshot keeps the preview_lines contract, so the Svelte side is unchanged. Remove the ConfigDescription types and the wire variants for config-desc, and make version 5 mandatory. Migrate the TUIC server and client schemas, the reuse example, and the legacy fixture: move descriptions onto output nodes and enum options, and delete their config-desc blocks. Update the DSL, schema, session, and reuse tests accordingly. Rewrite the Config DSL RFC (Chinese and English) as a structural reference covering each element, its attributes, defaults, and constraints, and reduce the generator guide to a summary that points at it. Assisted-by: opencode:deepseek-v4-flash
1 parent e890961 commit a2779d6

17 files changed

Lines changed: 1447 additions & 2395 deletions

File tree

‎AGENTS.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ BROWSER_CHANNEL=chromium node tests/config-generator/browser.mjs
119119

120120
## DSL and maintenance conventions
121121

122-
[Config DSL v4](config-generator/AGENTS.md) uses independent XML files to statically describe inputs, defaults, enums, conditions, lists, mappings, and sensitive fields, deserialized with quick-xml + Serde; configuration descriptions are not written with Rust macros or closures. `schema/schemas.txt` registers the XML files embedded in the production selector. The Rust session produces the form view, and Svelte renders it; generic projection and redaction live in `dsl.rs`, generic validation and field linkage in `dsl/rules.rs`, and basic address checks in `validation.rs`. TUIC branding, page sections, hints, cross-field rules, random-value generation declarations, and export commands are also entirely provided by XML. Adding a target application requires a new XML file and one manifest entry; `schema/example.xml` provides a reuse example with no TUIC fields.
122+
[Config DSL v5](config-generator/AGENTS.md) uses independent XML files to statically describe inputs, defaults, enums, conditions, lists, mappings, per-line output descriptions, and sensitive fields, deserialized with quick-xml + Serde; configuration descriptions are not written with Rust macros or closures. `schema/schemas.txt` registers the XML files embedded in the production selector. The Rust session produces the form view, and Svelte renders it; generic projection and redaction live in `dsl.rs`, generic validation and field linkage in `dsl/rules.rs`, and basic address checks in `validation.rs`. TUIC branding, page sections, hints, cross-field rules, random-value generation declarations, and export commands are also entirely provided by XML. Adding a target application requires a new XML file and one manifest entry; `schema/example.xml` provides a reuse example with no TUIC fields.
123123

124-
Configuration state is modified only by the Rust `Session`. Svelte submits generic field/collection operations and reads field display values, visibility, errors, and previews from `Snapshot`; per-line preview explanations are matched from `config-desc` in Rust (`Snapshot.preview_lines`), so the frontend only highlights and displays them. It does not parse XML, evaluate conditions, or keep a second mutable copy of the configuration. JSON strings cross the WASM boundary, and both field display values and stable row identities are strings, avoiding JavaScript number precision loss. `ui/types.ts` corresponds to the display contract in `session/view.rs`; when changing the contract, update both sides and run the session tests plus both browser test suites. Copy and download obtain the original text through a separate `export` operation rather than reading the redacted preview.
124+
Configuration state is modified only by the Rust `Session`. Svelte submits generic field/collection operations and reads field display values, visibility, errors, and previews from `Snapshot`; per-line preview explanations are read from the declared output descriptions in Rust (`Snapshot.preview_lines`), so the frontend only highlights and displays them. It does not parse XML, evaluate conditions, or keep a second mutable copy of the configuration. JSON strings cross the WASM boundary, and both field display values and stable row identities are strings, avoiding JavaScript number precision loss. `ui/types.ts` corresponds to the display contract in `session/view.rs`; when changing the contract, update both sides and run the session tests plus both browser test suites. Copy and download obtain the original text through a separate `export` operation rather than reading the redacted preview.
125125

126126
| Path | Contents |
127127
| --- | --- |

‎config-generator/AGENTS.md‎

Lines changed: 11 additions & 174 deletions
Large diffs are not rendered by default.

‎config-generator/schema/example.xml‎

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<config-dsl version="4" target-version="example-1">
1+
<config-dsl version="5" target-version="example-1">
22
<ui title="任务清单生成器" brand="Notebook" mark="N" eyebrow="XML 复用示例" description="同一生成器读取另一份 XML。" mode-field="deployment" format-field="encoding" export-hint="保存所需的清单。">
33
<section name="general" label="清单设置"/>
44
<section name="entries" label="清单项目"/>
@@ -38,32 +38,20 @@
3838
<assert key="last" when="range" message="结束数量不能小于起始数量。"><compare op="gte"><source from="/last" transform="integer"/><source from="/first" transform="integer"/></compare></assert>
3939
<unique collection="entries" key="id" message="项目名称重复。"><source from="id" transform="trim lowercase"/></unique>
4040
</rules>
41-
<config-desc title="清单格式详解" description="预览区按当前填写内容生成配置,并逐行显示字段说明。">
42-
<config name="snapshot" label="完整清单" filename="snapshot">
43-
<string name="title" value="example" description="清单所属项目的名称。" />
44-
<array name="items" description="清单项目列表,按填写顺序输出。">
45-
<object description="单个清单项目。">
46-
<string name="name" value="item" description="项目名称,必须唯一。" />
47-
<boolean name="enabled" value="true" description="项目是否启用。" />
48-
<string name="secret" value="change-this-token" description="项目密钥,属于敏感信息,预览默认脱敏。" />
49-
</object>
50-
</array>
51-
</config>
52-
<config name="selected" label="单项清单" filename="selected">
53-
<string name="item" value="item" description="当前选中项目的名称。" />
54-
</config>
55-
<config name="audit" label="审计信息" filename="audit">
56-
<boolean name="confirmed" value="true" description="清单是否已确认。" />
57-
</config>
58-
</config-desc>
5941
<outputs>
6042
<object name="snapshot" label="完整清单" filename="snapshot" command="notebook --input {filename}" when="all">
61-
<string name="title" from="/project"/>
62-
<list name="items" from="/entries"><object><string name="name" from="id"/><boolean name="enabled" from="enabled"/><string name="secret" from="token" secret="true"/></object></list>
43+
<string name="title" from="/project" description="清单所属项目的名称。"/>
44+
<list name="items" from="/entries" description="清单项目列表,按填写顺序输出。">
45+
<object description="单个清单项目。">
46+
<string name="name" from="id" description="项目名称,必须唯一。"/>
47+
<boolean name="enabled" from="enabled" description="项目是否启用。"/>
48+
<string name="secret" from="token" secret="true" description="项目密钥,属于敏感信息,预览默认脱敏。"/>
49+
</object>
50+
</list>
6351
</object>
6452
<object name="selected" label="单项清单" filename="selected">
65-
<string name="item"><select from="/entries" index="/chosen"><source from="id"/></select></string>
53+
<string name="item" description="当前选中项目的名称。"><select from="/entries" index="/chosen"><source from="id"/></select></string>
6654
</object>
67-
<object name="audit" label="审计信息" filename="audit" when="confirmed"><boolean name="confirmed" from="/confirm"/></object>
55+
<object name="audit" label="审计信息" filename="audit" when="confirmed"><boolean name="confirmed" from="/confirm" description="清单是否已确认。"/></object>
6856
</outputs>
6957
</config-dsl>

0 commit comments

Comments
 (0)