JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix: disable A2UI by default and reject nested templates
jack_rickyf2b59f2fc912
diff --git a/docs/en/A2UI.md b/docs/en/A2UI.mdindex c5ba6cd46d..25a5fe8ae6 100644--- a/docs/en/A2UI.md+++ b/docs/en/A2UI.md@@ -38,7 +38,7 @@ Default configuration lives in `jiuwenswarm/resources/config.yaml`:```yamla2ui:- enabled: true+ enabled: falseprotocol_version: "0.8"stream_validation_enabled: truenon_web_fallback_enabled: false@@ -50,6 +50,8 @@ A2UI can be controlled through:- User workspace config: `a2ui.enabled` in `config.yaml`.- Environment variable: `JIUWENSWARM_A2UI_ENABLED=false` or `true`.+A2UI is disabled by default. It must be explicitly enabled before the Web channel injects the A2UI prompt and runs response finalization.+`non_web_fallback_enabled` is kept only for compatibility with older configs. A2UI is currently Web-only, so non-Web channels always bypass A2UI.Legacy `JIUWENCLAW_A2UI_*` environment variables are not supported after this PR update on June 4, 2026. Use the `JIUWENSWARM_A2UI_*` prefix for all A2UI runtime overrides.diff --git a/docs/zh/A2UI.md b/docs/zh/A2UI.mdindex a07bfc97fa..35ddc8f5a2 100644--- a/docs/zh/A2UI.md+++ b/docs/zh/A2UI.md@@ -38,7 +38,7 @@ A2UI 是 JiuwenSwarm 的可选生成式界面能力,目前仅 Web channel 原```yamla2ui:- enabled: true+ enabled: falseprotocol_version: "0.8"stream_validation_enabled: truenon_web_fallback_enabled: false@@ -50,6 +50,8 @@ a2ui:- 用户工作区配置:修改 `config.yaml` 中的 `a2ui.enabled`。- 环境变量:`JIUWENSWARM_A2UI_ENABLED=false` 或 `true`。+A2UI 默认关闭,需要显式开启后才会向 Web channel 注入 A2UI prompt 并执行 response finalizer。+`non_web_fallback_enabled` 是兼容旧配置的保留字段;当前 A2UI 为 Web-only,非 Web channel 始终 bypass A2UI。旧的 `JIUWENCLAW_A2UI_*` 环境变量在本 PR 更新后不再支持,弃用时间线为 2026-06-04 起移除兼容;A2UI 运行时覆盖项统一使用 `JIUWENSWARM_A2UI_*` 前缀。diff --git a/jiuwenswarm/resources/config.yaml b/jiuwenswarm/resources/config.yamlindex d9d20c3ab7..4b8a9e279d 100644--- a/jiuwenswarm/resources/config.yaml+++ b/jiuwenswarm/resources/config.yaml@@ -6,7 +6,7 @@ auto_recap:enabled: truea2ui:- enabled: true+ enabled: falseprotocol_version: "0.8"stream_validation_enabled: truenon_web_fallback_enabled: falsediff --git a/jiuwenswarm/server/runtime/a2ui/config.py b/jiuwenswarm/server/runtime/a2ui/config.pyindex 247d5e260c..483343ab70 100644--- a/jiuwenswarm/server/runtime/a2ui/config.py+++ b/jiuwenswarm/server/runtime/a2ui/config.py@@ -16,7 +16,7 @@ SUPPORTED_A2UI_PROTOCOL_VERSIONS = frozenset({"0.8"})class A2UIConfig:"""Runtime switches controlling the optional A2UI feature."""- enabled: bool = True+ enabled: bool = Falseprotocol_version: str = "0.8"stream_validation_enabled: bool = Truenon_web_fallback_enabled: bool = False@@ -43,7 +43,7 @@ def get_a2ui_config(config: dict[str, Any] | None = None) -> A2UIConfig:section = raw.get("a2ui") if isinstance(raw, dict) else {}section = section if isinstance(section, dict) else {}- enabled = _to_bool(section.get("enabled"), True)+ enabled = _to_bool(section.get("enabled"), False)env_enabled = os.getenv("JIUWENSWARM_A2UI_ENABLED")if env_enabled is not None:enabled = _to_bool(env_enabled, enabled)diff --git a/jiuwenswarm/server/runtime/a2ui/integration.py b/jiuwenswarm/server/runtime/a2ui/integration.pyindex 9990594447..f18ba1c49f 100644--- a/jiuwenswarm/server/runtime/a2ui/integration.py+++ b/jiuwenswarm/server/runtime/a2ui/integration.py@@ -21,7 +21,7 @@ _WEB_CONFIG_KEY_MAP: dict[str, str] = {}_A2UI_CONFIG_DEFAULT_PAYLOAD: dict[str, str] = {- "a2ui_enabled": "true",+ "a2ui_enabled": "false",}_A2UI_CHANNEL_ID = "web"diff --git a/jiuwenswarm/server/runtime/a2ui/prompt_instructions.py b/jiuwenswarm/server/runtime/a2ui/prompt_instructions.pyindex f5fa27c8c6..6094ca6311 100644--- a/jiuwenswarm/server/runtime/a2ui/prompt_instructions.py+++ b/jiuwenswarm/server/runtime/a2ui/prompt_instructions.py@@ -13,7 +13,10 @@ def build_a2ui_autonomy_instruction(language: str = "en") -> str:"each item contains its own nested valueMap fields. Inside template ""components, use item-relative paths like 'name', 'price', or ""'/item/name' for Text, Image, and Button.action.context values; do not "- "use collection-absolute paths such as '/phones/name' inside templates."+ "use collection-absolute paths such as '/phones/name' inside templates. "+ "Do not nest templates inside template-rendered components in A2UI 0.8; "+ "flatten repeated item details into fields on the outer item, or use "+ "explicit child components that bind to those fields.")image_url_rule_en = (" Do not invent image URLs. If external facts or images are needed, use "@@ -62,7 +65,9 @@ def build_a2ui_autonomy_instruction(language: str = "en") -> str:"请把数组编码为一个集合 key,并在 valueMap 中使用 \"0\"、\"1\" 这类索引项;""每个 item 包含自己的嵌套 valueMap 字段。模板组件和 Button.action.context ""内使用 item-relative path,例如 name、price 或 /item/name;"- "不要在模板内使用 /phones/name 这类集合绝对路径。"+ "不要在模板内使用 /phones/name 这类集合绝对路径。A2UI 0.8 不要在模板渲染出的"+ "组件内部再嵌套 template;请把重复 item 的明细拍平成外层 item 字段,或使用显式"+ "子组件绑定这些字段。")image_url_rule_zh = (" 不要编造图片 URL。如果需要外部事实或图片,可以短暂使用可用工具,"diff --git a/jiuwenswarm/server/runtime/a2ui/validator.py b/jiuwenswarm/server/runtime/a2ui/validator.pyindex de8ee2c8f2..52cc40ea35 100644--- a/jiuwenswarm/server/runtime/a2ui/validator.py+++ b/jiuwenswarm/server/runtime/a2ui/validator.py@@ -147,6 +147,10 @@ def _iter_binding_paths(value: Any) -> list[str]:return paths+def _component_has_template(value: Any) -> bool:+ return bool(_iter_templates(value))++def _is_valid_template_item_path(path: str) -> bool:if not path.startswith("/"):return True@@ -233,6 +237,13 @@ def _validate_template_runtime_semantics(messages: list[dict[str, Any]]) -> Nonebinding_path = _normalize_data_path(data_binding)paths: list[str] = []for component_id in _component_subtree_ids(template_component_id, components_by_id):+ if _component_has_template(components_by_id[component_id]):+ raise ValueError(+ "A2UI v0.8 nested templates are not supported by the Web renderer; "+ f"found a template inside template {template_component_id!r}. "+ "Flatten repeated item content into fields on the outer item, or use "+ "explicit child components inside the template."+ )component_paths = _iter_binding_paths(components_by_id[component_id])for path in component_paths:if not _is_valid_template_item_path(path):diff --git a/tests/unit_tests/a2ui/test_feature_config.py b/tests/unit_tests/a2ui/test_feature_config.pyindex ea5f3d1e1d..04c5a8df01 100644--- a/tests/unit_tests/a2ui/test_feature_config.py+++ b/tests/unit_tests/a2ui/test_feature_config.py@@ -3,26 +3,26 @@from __future__ import annotations-def test_a2ui_config_defaults_enabled():+def test_a2ui_config_defaults_disabled():from jiuwenswarm.server.runtime.a2ui.config import get_a2ui_configcfg = get_a2ui_config({})- assert cfg.enabled is True+ assert cfg.enabled is Falseassert cfg.protocol_version == "0.8"assert cfg.stream_validation_enabled is Trueassert cfg.non_web_fallback_enabled is Falseassert cfg.dev_smoke_tools_enabled is False-def test_a2ui_config_env_can_disable_feature(monkeypatch):+def test_a2ui_config_env_can_enable_feature(monkeypatch):from jiuwenswarm.server.runtime.a2ui.config import get_a2ui_config- monkeypatch.setenv("JIUWENSWARM_A2UI_ENABLED", "false")+ monkeypatch.setenv("JIUWENSWARM_A2UI_ENABLED", "true")- cfg = get_a2ui_config({"a2ui": {"enabled": True}})+ cfg = get_a2ui_config({"a2ui": {"enabled": False}})- assert cfg.enabled is False+ assert cfg.enabled is Truedef test_legacy_jiuwenclaw_env_alias_no_longer_overrides_config(monkeypatch):diff --git a/tests/unit_tests/a2ui/test_integration_bridge.py b/tests/unit_tests/a2ui/test_integration_bridge.pyindex 60fa82e44a..ba320a8cf3 100644--- a/tests/unit_tests/a2ui/test_integration_bridge.py+++ b/tests/unit_tests/a2ui/test_integration_bridge.py@@ -112,7 +112,7 @@ def test_get_a2ui_config_payload_defaults():"""Config payloads should expose only user-facing A2UI Web keys."""payload = get_a2ui_config_payload({"a2ui": {}})- assert payload == {"a2ui_enabled": "true"}+ assert payload == {"a2ui_enabled": "false"}def test_validate_a2ui_config_update_rejects_internal_keys():diff --git a/tests/unit_tests/a2ui/test_prompt_instructions.py b/tests/unit_tests/a2ui/test_prompt_instructions.pyindex a0a62eb846..3884785dc9 100644--- a/tests/unit_tests/a2ui/test_prompt_instructions.py+++ b/tests/unit_tests/a2ui/test_prompt_instructions.py@@ -25,6 +25,13 @@ def test_a2ui_prompt_is_autonomous_not_forced():assert "Do not promise to show the result with A2UI and then output only Markdown" in instruction+def test_a2ui_prompt_discourages_nested_templates():+ instruction = build_a2ui_autonomy_instruction("en")++ assert "Do not nest templates" in instruction+ assert "flatten repeated item details" in instruction++def test_a2ui_zh_prompt_section_is_readable():prompt = build_a2ui_prompt_section("zh")diff --git a/tests/unit_tests/a2ui/test_validator.py b/tests/unit_tests/a2ui/test_validator.pynew file mode 100644index 0000000000..1e451a0d2d--- /dev/null+++ b/tests/unit_tests/a2ui/test_validator.py@@ -0,0 +1,172 @@+# Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved.++"""Regression coverage for A2UI runtime semantic validation."""++from __future__ import annotations+++def test_a2ui_validator_accepts_single_level_template():+ from jiuwenswarm.server.runtime.a2ui.protocol import get_protocol_spec++ response = """<a2ui-json>+[+ {+ "beginRendering": {+ "surfaceId": "single-template",+ "root": "root"+ }+ },+ {+ "surfaceUpdate": {+ "surfaceId": "single-template",+ "components": [+ {+ "id": "root",+ "component": {+ "List": {+ "children": {+ "template": {+ "componentId": "student-row-tpl",+ "dataBinding": "/students"+ }+ },+ "direction": "vertical"+ }+ }+ },+ {+ "id": "student-row-tpl",+ "component": {+ "Text": {+ "text": {+ "path": "summary"+ },+ "usageHint": "body"+ }+ }+ }+ ]+ }+ },+ {+ "dataModelUpdate": {+ "surfaceId": "single-template",+ "contents": [+ {+ "key": "/students",+ "valueMap": [+ {+ "key": "0",+ "valueMap": [+ {+ "key": "summary",+ "valueString": "姓名:张雨萱 | 学号:2024001"+ }+ ]+ }+ ]+ }+ ]+ }+ }+]+</a2ui-json>"""++ assert get_protocol_spec().validate_response(response).valid is True+++def test_a2ui_validator_rejects_nested_templates():+ from jiuwenswarm.server.runtime.a2ui.protocol import get_protocol_spec++ response = """<a2ui-json>+[+ {+ "beginRendering": {+ "surfaceId": "nested-template",+ "root": "root"+ }+ },+ {+ "surfaceUpdate": {+ "surfaceId": "nested-template",+ "components": [+ {+ "id": "root",+ "component": {+ "List": {+ "children": {+ "template": {+ "componentId": "student-card-tpl",+ "dataBinding": "/students"+ }+ },+ "direction": "vertical"+ }+ }+ },+ {+ "id": "student-card-tpl",+ "component": {+ "Column": {+ "children": {+ "template": {+ "componentId": "line-tpl",+ "dataBinding": "lines"+ }+ }+ }+ }+ },+ {+ "id": "line-tpl",+ "component": {+ "Text": {+ "text": {+ "path": "text"+ },+ "usageHint": "body"+ }+ }+ }+ ]+ }+ },+ {+ "dataModelUpdate": {+ "surfaceId": "nested-template",+ "contents": [+ {+ "key": "/students",+ "valueMap": [+ {+ "key": "0",+ "valueMap": [+ {+ "key": "lines",+ "valueMap": [+ {+ "key": "0",+ "valueMap": [+ {+ "key": "text",+ "valueString": "姓名:张雨萱"+ }+ ]+ }+ ]+ }+ ]+ }+ ]+ }+ ]+ }+ }+]+</a2ui-json>"""++ result = get_protocol_spec().validate_response(response)++ assert result.valid is False+ assert result.error is not None+ assert "nested templates" in result.error