Add the input/event/scenario/interaction/dependency/acceptance model and validation on top of the core loader: - 输入/事件 plain-text tables with non-empty unique names; links rejected; - 场景 only on leaf components, ASCII slug states unique, exactly one initial, content cell is exactly one link to a Knowledge unit (Exec and design component declarations rejected), scene limit 32; - 交互 state references, non-empty unique event labels per state, reachability from the initial state, multi-state requires transitions, 128 limit; - 依赖 must target loaded design components with non-empty reasons and an acyclic design dependency graph; - 验收 keeps the direct section text, rejects empty content, never interprets it as a test; - contract-aligned limits (100 docs/200 defs/1000 instances/12 depth/12 slots per row/1 MiB file/16 MiB total) and a richer deterministic handoff. 14 real-CLI contract tests now cover the positives and main negatives. Docs and the WEB-01 evidence record which security/concurrency cases and WEB-03 handoff remain open; WEB-01 stays open. Refs cflmy/marqdo-web-design#1, cflmy/marqdo#6
2.8 KiB
2.8 KiB
暂定公开 API(provisional)
本文件是 Design 与 Preview 之间的临时接口约定,供 WEB-01 开发收敛;正式定义以 crate 导出与测试为准。它不改变 CLI 或 WEB-DESIGN 作者合同。
入口函数
pub fn load(config: &LoadConfig) -> Result<Design, Diagnostics>;
pub fn handoff(design: &Design) -> String;
LoadConfig:MARQDO_BIN路径、entry、unit(anchor,无#)、root(显式项目根)、主题与资源上限等配置。load失败返回Diagnostics;引擎失败(CLI 缺失/协议不符/IO)与设计错误(作者文档不符合合同)必须可区分,宿主据此映射退出码 2 与 1。handoff只派生 Markdown,不读源文件、不做 IO;源文档始终权威。
数据模型(按 WEB-DESIGN 与规范 §9.3)
| 类型 | 字段与不变量 |
|---|---|
SourceRef |
本轮 project-relative path、结构化 Unit path、anchor、source_digest、UTF-8 byte span、原 Analysis identity |
ComponentDef |
精确 SourceRef、职责原文、可安全渲染的内容 AST 子集、layout rows、输入/事件合同、场景、依赖、验收文本 |
ChildSlot |
局部 slot、row、width enum、目标 definition ID、来源 span |
Instance |
根与 slot path 唯一标识,指向 ComponentDef;复用定义不共享可变状态 |
Scenario |
唯一状态 ID、内容单元 SourceRef、初始标记、确定的事件转移 |
DesignGraph |
定义与实例图、非视觉依赖、直接输入摘要、根身份、诊断 |
Preview 消费边界
- Preview 只读上述公开类型构造页面;禁止自行解析 GFM 表、按 Link label 猜目标或依赖私有字段。
- 渲染所需未知字段通过公开新增 API 讨论,不在 Preview 复制设计解释逻辑。
- 内容 AST 只消费允许节点投影;raw HTML 不作活动代码,不引入第二套 Markdown 解析。
稳定性
load/handoff与数据模型在 WEB-01 前为 provisional,可破坏式调整;WEB-01 后进入 SemVer。- 需要破坏性变更时,Design 与 Preview 在同一领域候选组合中一起升级,
Cargo.lock固定实际消费身份;不维护旧协议 fallback。
实现状态(WEB-01 核心候选)
load 已实现:真实 CLI Analysis 3 摄入、精确 anchor 选 Knowledge H2、组件 表递归布局、宽度/行/槽校验、包含环与资源上限、稳定诊断与源身份;handoff 目前输出确定性的组件树与来源摘要。
InputDecl/EventDecl/Scenario/Interaction/Dependency/Acceptance 已导出;未导出/未实现:DesignGraph 的完整组合图与 WEB-03 的组件切片/漂移标识。按 provisional 约定,这些可在 WEB-01 完成前破坏式调整;Preview 不得自行实现上述解释。