Files
marqdo-web-design/docs/API.md
cflmy 75cd26ef89 feat: WEB-01 core Design interpreter over public Analysis 3
Implement the first real Design capability in the unique owner repository:
- src/analysis.rs runs the verified CLI check --emit with direct argv, validates
  Analysis 3 schema/source_digest, and snapshots one module without any implicit
  discovery or Markdown parser.
- src/document.rs selects the exact Knowledge H2 by anchor, direct retained H3
  sections, and the single GFM 组件 table from the analysis AST; cell text is
  read from the analysis-provided source by UTF-8 byte span.
- src/lib.rs binds design links by exact candidate_path + anchor (never label or
  filename guessing), validates rows/slots/widths, recursion, containment cycles
  and module/depth/byte limits, and builds deterministic component definitions,
  separate instances, source identities and a provisional handoff.
- Stable diagnostics separate Engine failures (exit 2) from author-contract
  errors (exit 1); no partial model on failure.
- tests/design_contract.rs exercises the real CLI for recursive layout,
  definition reuse, width forms and the main negative cases; scripts/ci.sh is the
  explicit entry (fmt/clippy/test) with a verified CLI.

Scenarios/input/event/dependency contracts and the full WEB-03 handoff remain
open and are recorded as unverified in the evidence document.

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

43 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 暂定公开 API(provisional)
本文件是 Design 与 Preview 之间的**临时**接口约定,供 WEB-01 开发收敛;正式定义以 crate 导出与测试为准。它不改变 CLI 或 WEB-DESIGN 作者合同。
## 入口函数
```rust
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` 目前输出确定性的组件树与来源摘要。
未导出/未实现:`输入`/`事件`/`依赖`/`验收` 合同模型、`Scenario`/`Interaction`、`DesignGraph` 的完整依赖图与 WEB-03 handoff。按 provisional 约定,这些可在 WEB-01 完成前破坏式调整;Preview 不得自行实现上述解释。