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
5.4 KiB
5.4 KiB
开发指南
本仓库是 Web 领域的设计编译实现。当前状态 planned:本文描述实现要求与准入清单,不代表任何能力已实现。
数据流
ENTRY + --unit ANCHOR + --root DIR
-> 静态 marqdo check ENTRY --emit TEMP(固定 CLI 制品)
-> 校验 Analysis 3:AST/units/anchors/references/source_digest
-> 选取 Knowledge H2,解释直接保留 H3 节
-> 递归解析明确的设计链接(必要时对目标 entry 单独 check --emit)
-> 设计模型(定义、实例、布局、场景、依赖、来源身份)
-> 校验与诊断 -> Preview 渲染 / handoff Markdown
- 只接受本地项目内
.mq.md设计文档;不接受远程链接加载、普通.md作为设计目标、跨 package 设计引用(首版)。 - CLI 调用使用直接 argv(无 shell),限制工作时长/输出大小,临时目录 owner-only,失败清理;不自动
lock/install/联网,不启动 plugin/worker/Foreign。 check --emit是现有公开能力;禁止改用inspect私有输出或复制 AST parser。
链接解析要点
RC.4 Analysis 只包含已静态加载模块,not_loaded 不等于缺失。设计必须显式遍历被选择的设计链接:
- 从对应 AST Link span 与
references记录绑定源模块/来源 Unit;优先消费已 resolved 的精确目标与 anchor。 - 对
not_loaded:只接受属于当前根项目、带明确 anchor 的candidate_path;用公开 package module root 映射到--root内允许的本地文件,再次check --emit该 entry,用返回的 source digest 与 anchors 做一次解码后的精确定位;不重新实现 slug,不用 Link label 推断,不做同名搜索 fallback。 missing/ambiguous/outside_scope/invalid/external对设计依赖是错误;普通内容链接不追踪。无法从公开字段确认物理映射时报告“不支持”,不得调用私有 loader 或搜索文件名。- 并发编辑一致性:以实际输入 bytes 与 digest 校验;同一文件在一轮中两次 Analysis 内容不同即失败重试;输出前复核所有参与设计的源码/资产摘要。交付只列真正使用的输入,不打包全部已加载依赖。
代码结构(WEB-01 核心已创建)
Cargo.toml / Cargo.lock
src/lib.rs # 公开 API、递归布局/实例/上限/handoff(WEB-01 核心)
src/analysis.rs # CLI check --emit 调用、Analysis 3 校验、模块快照
src/document.rs # 精确 anchor/H3/GFM 表/Link 选择
src/diagnostic.rs # 稳定错误码、span、Engine/Design 区分
tests/design_contract.rs # 真实 CLI 正例 + 负例
scripts/ci.sh # 显式独立验收入口(fmt/clippy/test)
docs/ # API、开发指南与证据
尚未拆分 model.rs/graph.rs/handoff.rs 是当前规模下的有意选择;场景/输入事件合同与完整 handoff 落地时再按真实边界拆分,不做预先空壳。
不为每个表格新建 crate;Design 与 Preview 各一个主要 crate。docs/WEB-DESIGN.md 在领域仓库,本仓库不得复制。
公开 API 原则
- 对外只导出
load(config) -> Result<Design, Diagnostics>与handoff(&Design) -> Markdown(名称可在 WEB-01 收敛),只维护一套结构定义。Preview 通过公开类型消费,不自行解读表格。 - 所有结构字段使用结构化
UnitId.path/anchor/span/digest,禁止从 display 字符串切割;复用组件定义只复用不可变内容,实例状态按“根 + slot 路径”独立。 - 解析与模型确定:相同输入 + 相同 CLI 制品产生相同结构与交付;诊断包含稳定代码、path/anchor/span 与说明,失败非零退出。
- 暂定类型见 API;接口经原型证明不稳定时先收敛,不通过在 Preview 复制解析器规避。
测试策略
- 真实 CLI 正例:§8 示例、多文件递归、跨文档
not_loaded、场景与重复实例、单组件切片。 - 负例:表头/列数/位置错误、非 Link 单元格、表达式求值企图、H2 Exec、错误层级、anchor 缺失/歧义/越界、绝对/file 路径、双重编码/逃逸/恶意 symlink、包含环、非法场景/转移、超预算。
- 身份与一致性:source digest、UTF-8 span、anchors 交叉验证;篡改 Analysis 或 CLI 输出被拒绝;并发编辑拒绝;同输入两次构建一致。
- 诊断:错误码稳定、来源位置可定位、失败无部分成功制品。
- 激活准入:
scripts/ci.sh在独立 checkout 用精确 CLI 制品跑上述用例;领域 CI 与根递归校验通过;与 Preview 同候选证据。对应验收项 W01–W14、W28/W29/W35/W36。
资源上限
首版工程上限(工程建议,不是已测结果):100 设计文档、200 定义、1000 实例、深度 12、每行 12 槽、每组件 32 场景/128 转移、每源 1 MiB、总输入 16 MiB、单 Analysis 32 MiB、单图片 4 MiB、资产总量 24 MiB、单次 CLI 调用 20 s、全部静态调用 120 s;超限确定失败并报告来源。缓存只在单次构建内复用,首版不引入持久索引。
发布与证据
- 独立 SemVer;
Cargo.lock固定依赖;发布制品记录版本、Git SHA、依赖身份、平台与测试证据。 - 破坏性 API 变更与 Preview 以配对候选一次切换,不维护多版本作者面或旧 fallback。
- 发布前确认:真实 CLI 夹具通过、领域 gitlink 指向本仓库精确提交、领域/根证据同候选、
UNVERIFIED项明确列出。