Files
cflmy 495d2e4bf7 feat: project safe content, verify load stability and cover scope escapes
- Expose ContentBlock/ContentLink projected from the analysis AST and source
  byte spans; raw HTML becomes an inert placeholder, links keep url/span for the
  Preview protocol allowlist. Components and scenario content units use it.
- After building the graph, re-analyze every participating module and require
  the same source_digest; a mid-load edit returns Engine web.engine.stale and no
  partial model.
- Security cases: symlink escape outside --root is rejected, absolute link
  targets are rejected, percent-encoded traversal stays unresolved, raw HTML is
  inert.
- Tests grow to 18 real-CLI cases (content projection, html placeholder,
  symlink/absolute/encoded scope escapes, forged CLI output stale detection).
- Evidence/docs record what remains: WEB-03 graph/slicing, component CI
  service, WEB-02 output budget/CSP, WEB-05 root integration.

Refs cflmy/marqdo-web-design#1, cflmy/marqdo#6
2026-11-27 08:47:56 +08:00

2.8 KiB
Raw Permalink Blame History

暂定公开 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 已导出;ContentBlock/ContentLink 已导出(安全结构投影,raw HTML 为占位)。未导出/未实现:DesignGraph 的完整组合图与 WEB-03 的组件切片/漂移标识。按 provisional 约定,这些可在 WEB-01 完成前破坏式调整;Preview 不得自行实现上述解释。