RFC: Render System — Resolution 衰减模型 + LiquidJS 模板引擎 #36
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
背景
json-cas 节点需要人类可读的渲染能力。不同场景需要不同的展开深度——概览只看顶层,调试需要完整展开。之前讨论过离散的
verboseLevel0-5 方案,现改为连续的 resolution 衰减模型,更灵活、语义由模板定义而非引擎规定。核心设计
1. Resolution 衰减模型
(0, 1]的浮点数,表示当前节点的"分辨率"resolution = 父节点 resolution × decayresolution ≤ epsilon时渲染为cas:<hash>引用,停止递归cas:<hash>示例(resolution=0.8, decay=0.5, epsilon=0.01):
2. CLI 参数
--resolution1.0--decay0.5--epsilon0.01cas:<hash>3. Decay 优先级
4. 无模板默认行为
没有模板时,使用 YAML 渲染 + 二元截断:
resolution > epsilon→ 展开为内联 YAMLresolution ≤ epsilon→cas:<hash>统一使用 CLI
--decay或引擎默认值作为所有子节点的衰减系数。5. 模板引擎:LiquidJS
选择 LiquidJS 作为全局模板引擎(替代 mustache),理由:
{% if resolution > 0.5 %}),无需注册 helper{% render %}是 Liquid 保留 tag,语义天然匹配递归渲染模板示例:
6. 差异化衰减
同一层不同子节点可设不同衰减系数:
重要字段慢衰减(看得更深),次要字段快衰减(早截断)。
后续工作
参考
小橘 🍊(NEKO Team)
补充:模板注册机制 + 内置 Schema + CLI 子命令
1.
@ucas保留变量域模板通过 Variable System 注册,使用保留命名空间:
@ucas— json-cas 系统保留域,用户变量不可使用此前缀template/text— 类别(Liquid 文本模板)<schema-hash>— 目标 node type 的 schema hash需要调整变量名校验规则:允许首段以
@开头(当前只允许[a-zA-Z0-9._-])。2. 内置 Schema 别名
在
init/bootstrap时自动注册常用 schema,CLI 支持@前缀快捷引用:@schema@string{ "type": "string" }@number{ "type": "number" }@object{ "type": "object" }@array{ "type": "array" }@bool{ "type": "boolean" }用法:
3.
templateCLI 子命令封装底层
put+var set为一步操作:template set内部流程:@stringschema 存在store.put(stringSchemaHash, templateContent)— 存模板到 CASvar.set("@ucas/template/text/<schema-hash>", contentHash)— 绑定变量4.
render模板发现ucas render <hash>时自动按 node 的 type hash 查找模板:小橘 🍊(NEKO Team)
RFC 全部交付完成 ✅
Phases:
— 小橘 🍊(NEKO Team)