From 725a06d2e528af53da8c03b9af4bbc7733b38696 Mon Sep 17 00:00:00 2001 From: cflmy Date: Thu, 26 Nov 2026 16:52:22 +0800 Subject: [PATCH] docs: initialize Web Preview component development --- .gitignore | 26 ++++ AGENTS.md | 83 ++++++++++++ LICENSE | 201 +++++++++++++++++++++++++++++ README.md | 137 ++++++++++++++++++++ docs/DEVELOPMENT.md | 300 ++++++++++++++++++++++++++++++++++++++++++++ docs/SECURITY.md | 233 ++++++++++++++++++++++++++++++++++ 6 files changed, 980 insertions(+) create mode 100644 .gitignore create mode 100644 AGENTS.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 docs/DEVELOPMENT.md create mode 100644 docs/SECURITY.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4b132b --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# Rust 构建与本地缓存 +/target/ +/.cache/ +/dist/ +/bin/ + +# 本地 tool bundle 与测试输出 +**/*.analysis.json.tmp +**/*.ast.json.tmp +*.tmp + +# 真实浏览器测试 +/tests/browser/node_modules/ +/tests/browser/artifacts/ +/tests/browser/screenshots/ + +# Python 辅助脚本(CI/测试胶水) +__pycache__/ +*.pyc + +# 本地配置与编辑器 +.env +.env.* +.cargo-home/ +.DS_Store +*.swp diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..9fd4b39 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,83 @@ +# AGENTS.md:marqdo-web-preview 维护指引 + +本文件约束在本仓库工作的维护者与 AI Coding Agent。仓库状态为 `planned`:只有文档, +没有实现源码、`Cargo.toml`/`Cargo.lock`、`tool.json` 实体、CI 入口或发布制品,也没有 +接入 `marqdo-ext-web` 的 gitlink。 + +## 开工前必须确认 + +1. 读 [README.md](README.md) 的状态与边界、[docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) + 的激活门禁、[docs/SECURITY.md](docs/SECURITY.md) 的安全合同。 +2. 唯一 Web 作者合同是 + [marqdo-ext-web 的 docs/WEB-DESIGN.md](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md); + 唯一设计解释实现是 [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design)。 + 本仓库不维护第二份作者面规范。 +3. 判断任务是否属于本仓库:本仓库负责 Tool 宿主、安全渲染、离线导出与分发;设计解释、 + Markdown 解析、链接绑定、Handoff 内容属于 Design;作者面语义与领域组合属于 Ext-Web。 + +## 责任边界 + +| 在本仓库做 | 不在本仓库做 | +| --- | --- | +| 三条 `web` 子命令、退出码、stderr 诊断/stdout 摘要 | 新增公共命令、JSON 命令协议、`web serve`/`deploy`/`agent`/`generate-react` | +| 从 Design 模型投影静态 HTML、固定主题与 CSS、固定场景 JS | 解释 `组件`/`场景`/`交互` 表格,或复制 CLI parser / Markdown 解析器 | +| 递归 Grid、390px 重排、键盘/焦点、实例隔离与重置 | 任务/页面/业务专用 renderer 分支,业务状态与真实后端 | +| 离线制品、raster 资产校验、CSP、staging 原子发布 | 启动服务、联网、真实表单提交、执行文档或 `@exec` | +| `tool.json` + 二进制 bundle 与现行 `marqdo tool` 协议 | 伪造 `entry`、版本号、CI 徽章、PASS、gitlink 或生产实现 | +| 真实 `file://` 浏览器、XSS、冷安装、确定性证据 | 把 mock、DOM snapshot 或字符串检查当浏览器/安全验收 | + +## 硬性禁止 + +- 不复制 Design 解释逻辑、Markdown/语言解析器或 CLI 私有 crate;不通过 `../design` + 路径依赖或搜索父目录定位依赖。 +- 不新增 CLI 核心语法、Web 专属关键字或第二套表头方言;作者面变更只在 Ext-Web 走 ADR。 +- 不引入 HTML 注入默认通道、`eval`/`Function`/`innerHTML`/`srcdoc`/`on*`、任意脚本资源或 + 外部网络请求。 +- 不在本仓库实现生产业务、真实登录/支付/数据库/网络,也不生成或修改生产前端源码。 +- 不修改其他仓库(Design/Ext-Web/根)的源码;跨仓改动必须在各自责任仓库提交。 +- 不提交构建产物、`target/`、`dist/`、浏览器 artifacts、凭证或本地绝对路径。 +- 不推送、不创建远端、不改根仓库 gitlink;集成晋升由领域与根维护者执行。 + +## 变更与晋升流程 + +1. 在**本仓库**建工单:按 Web 领域规范 §12.2 记录责任组件、类型、影响消费者、候选 + SHA、CLI/Design 制品 SHA-256 与平台、最小 fixture/命令/实际结果、预期结果与合同链接、 + 修复范围与验收。 +2. 计划阶段(当前)只允许改文档,且必须保持“计划 vs 现行”“已验证 vs UNVERIFIED”的区分。 +3. 激活门禁全部满足后才允许加入实现文件:Design 候选 API 与真实 CLI 夹具可用、`tool.json` + 与 `scripts/ci.sh`/`scripts/package-tool.sh` 实际存在且真实通过、冷安装与安全负例有绑定 + 候选的证据、README/AGENTS 与实现一致。激活顺序与本文件门禁见 DEVELOPMENT。 +4. 功能提交(C2)先通过组件 CI;领域 PR 更新 `marqdo-ext-web` 子 gitlink 至 C2 并通过领域 + CI(B2);根 PR 再更新领域 gitlink(A2)。先推送子仓库提交,再更新 gitlink。 +5. 合同语义变更:先在 Ext-Web 提 ADR/Issue 明确语义,再由 Design 与 Preview 配对候选 + 同候选验证;旧作者面不保留兼容探测。CLI 公共协议缺陷向 CLI 提 issue,不在本地兜底。 + +## 测试与证据纪律 + +- 只用真实输入:固定 `MARQDO_BIN`(候选锁定制品)、真实 Design 发布/锁定制品、真实 + Chromium 打开实际 `file://` 制品;mock CLI 不能作为正例证据。 +- 安全负例必须是真实浏览器执行验证(W21–W25),不能只断言字符串不在 HTML 中。 +- 冷安装验证:空 HOME、无 checkout、禁网,执行 `tool install`、实际 `web` 分发与 + `tool remove`,并核对 CLI 二进制 SHA-256 前后一致;篡改 bundle 必须被拒绝。 +- 证据 manifest 至少含:根/领域/组件 SHA、Design 依赖版本与摘要、CLI 版本与摘要、平台与 + 工具链、真实命令与退出码、fixture 摘要、制品摘要、浏览器版本、日志位置、测试范围、 + 未验证项。FAIL/UNVERIFIED 不得写成 PASS;测试不存在不等于通过。 + +## 文档纪律 + +- 中文、结论式、表格优先;区分现行合同、计划实现、已验证、UNVERIFIED、责任仓库。 +- 不复制规范整段正文;用章节号与链接引用。文件链接格式统一为 + `https://git.cflmy.cn/cflmy//src/branch/main/`。 +- 现状来源唯一:状态以 README 与本仓库文档为准,不新增第二份“当前状态”文件。 + +## 常见错误路由 + +| 现象 | 责任仓库 | +| --- | --- | +| 手机布局溢出、场景实例串扰、键盘/焦点 | 本仓库(marqdo-web-preview) | +| XSS、CSP、raster 资产校验、路径逃逸、制品泄漏 | 本仓库(marqdo-web-preview) | +| 组件表头未识别、Link 精确绑定、`not_loaded`、anchor 定位(Analysis 正确时) | marqdo-web-design | +| Analysis 字段缺失、resolver 公共合同、Tool 安装协议 | marqdo-cli | +| 作者面语义冲突、新表格/新通用能力 | marqdo-ext-web(ADR) | +| 真实生产应用渲染/状态错误 | 目标应用仓库,不归 Web 原型 | +| gitlink/领域组合装配失败 | marqdo-ext-web / 根,按第一个违反合同者判断 | diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e34754d --- /dev/null +++ b/README.md @@ -0,0 +1,137 @@ +# marqdo-web-preview + +`marqdo-web-preview` 是 Marqdo Web 原型设计领域中的**预览组件**:它消费 +`marqdo-web-design` 已经解释好的设计模型,生成不依赖服务器、可用本地浏览器直接打开的 +离线 HTML 原型,并以 `web` 命令注册为生态中唯一的 Web Tool 入口。 + +- **状态:`planned`**。本仓库目前只有文档:没有实现源码、`Cargo.toml`/`Cargo.lock`、 + `tool.json` 实体、`scripts/ci.sh`、CI 流水线或发布制品,也没有接入领域仓库 + `marqdo-ext-web` 的子 gitlink。本文中“将/目标”描述的是接入后必须满足的合同,不是 + 已实现能力,也不是已验收结果。 +- **唯一 Web 作者合同**:[`marqdo-ext-web` / docs/WEB-DESIGN.md](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md) + 定义 `.mq.md` 设计文档如何表达内容、递归组件、输入/事件、场景、依赖与验收。本仓库 + 不维护第二份作者面规范,也不复制其正文。 +- **领域治理与组合**:[marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web) + (领域聚合仓库,只做治理、合同、示例和组合验收,不含生产实现)。 +- **上游实现**:[marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) + (唯一设计解释实现,Rust library;本仓库通过其公开 API 消费设计模型)。 +- **目标远端**:`https://git.cflmy.cn/cflmy/marqdo-web-preview`。远端创建、领域 + `components.toml` 登记、gitlink 与 CI 均属于后续激活工作,当前 `planned`。 + +## 职责与禁止 + +下图是接入后的稳定边界,来自 Web 领域规范 §6.2、§10、§11;未列出的事项默认不属于 +本仓库。 + +| 本仓库负责(接入后) | 本仓库禁止 | +| --- | --- | +| `web` 命令的三条子命令 `check` / `preview` / `handoff` 的参数校验、宿主交互、退出码与摘要输出 | 自行解析或解释 `组件`/`场景`/`交互` 等设计表格;另造一套设计解释规则 | +| 把 Design 返回的递归模型安全投影为静态 HTML,使用固定 HTML shell 与固定 CSS/JS | 执行源文档、`@exec`、任意脚本或把原型当通用程序运行 | +| 通用 Grid 的递归布局、固定 light/dark 主题、有限场景切换、实例重置 | 新增任务/页面/业务专用 renderer 分支,或把业务逻辑写入 host.js | +| 离线制品导出:本地 raster 资产校验、CSP、staging 原子发布 | 启动本地服务、部署、生成生产项目源码或要求开发服务器 | +| `web` Tool bundle:`tool.json` + 二进制入口 + 固定资产,按现行 `marqdo tool` 协议分发 | 复制 Markdown/语言解析器、复制 CLI 私有 crate、依赖 `../design` 永久路径 | +| 真实 `file://` 浏览器验收:响应式、键盘/焦点、实例隔离、XSS 与离线安全 | 真实登录、支付、数据库写入、网络业务、真实表单提交 | +| 生成可复现的构建摘要与证据数据(版本、来源、制品摘要、未验证项) | 伪造 PASS、CI 徽章、版本号、`entry`、`tool.json` 实体或 gitlink | + +## 唯一入口与三条子命令 + +`web` 是 Web 领域唯一的 Tool 命令;三条子命令是唯一作者入口,不新增 +`web serve`、`web deploy`、`web agent`、`web generate-react` 等命令。下表的语义与退出码 +是接入后的合同(Web 领域规范 §10.1),当前均未实现。 + +| 命令 | 语义 | 退出码 | +| --- | --- | --- | +| `marqdo web check ENTRY --unit ANCHOR [--root DIR]` | 静态检查并输出摘要与诊断;不执行文档 | 0 成功;1 设计/静态校验失败;2 参数/环境/工具协议/IO 失败 | +| `marqdo web preview ENTRY --unit ANCHOR [--root DIR] --out DIR [--theme light\|dark]` | 生成可用本地浏览器打开的离线 `index.html` 与必要本地资源;不启动服务 | 同上 | +| `marqdo web handoff ENTRY --unit ANCHOR [--root DIR] --out FILE` | 生成 Markdown 设计交付(源引用、职责、接口、依赖、验收);不生成生产代码 | 同上 | + +约定: + +- stderr 输出诊断,stdout 输出摘要;首版不新增公共 JSON 命令结果协议。 +- `ENTRY`、`--unit`、`--root` 原样交给 Design 的加载配置;Preview 不扫描项目寻找页面、 + 不用文件名猜测设计目标、不解释 `ENTRY` 之外的文档。 +- 预览输出目录默认必须不存在;交付输出文件默认不得覆盖。失败不产生新的“成功制品”, + 也不删除用户既有目录。 + +## 消费边界:只消费 Design API + +Preview 与 Design 的依赖是**真实发布依赖**,不是父目录约定: + +- `marqdo-web-design` 使用精确发布 crate 版本或明确 Git revision,由 `Cargo.lock` + 固定真实依赖身份;最终发布组合不得把 CI 测试 override 伪装成发布依赖。 +- 独立 clone/build;不通过 `../design` 路径依赖,不直接依赖 CLI 的私有 Rust crate + (parser、AST、loader),不重新实现 anchor、`UnitId.path`、`source_digest` 的算法。 +- 设计解释、链接遍历、`not_loaded` 处理、诊断代码、Handoff Markdown 内容全部属于 + Design;Preview 只做渲染、导出与宿主接线。若模型缺字段,先向 Design 开工单或在 + `marqdo-ext-web` 走合同 ADR,不在本仓库复制解释器兜底。 + +## 安全不变量(摘要) + +详细执行合同见 [docs/SECURITY.md](docs/SECURITY.md),对应验收 W21–W25: + +- 原文 HTML 只以文本/占位显示;无 `eval`/`Function`/`innerHTML`/`srcdoc`/`on*` 属性、 + 无任意脚本资源;内容与脚本数据按上下文转义,恶意 fixture 必须真实不执行。 +- 链接 allowlist:只允许制品内锚点或用户显式触发的 `http`/`https`;拒绝 + `javascript:`/`data:`/`file:` 等协议,绝不自动发起网络请求。 +- 图片只允许明确展示的项目内普通 raster(PNG/JPEG/WebP/GIF),经路径、大小、魔数 + 校验后复制;远端图片只显示文本占位;SVG/HTML 作为代码或参考,不内联执行。 +- 离线制品默认 CSP `default-src 'none'`、`connect-src 'none'`,必要固定脚本/样式使用 + hash,禁止表单提交与嵌入;以真实浏览器行为验收,不只检查字符串。 +- 固定 `--root`、一次解码、canonical 检查,拒绝路径逃逸、符号链接和特殊文件;资产、 + 输出与静态调用均受大小/时限约束,超限确定失败。 +- 制品不包含未选择的私密模块、完整 Analysis、本地绝对路径、凭证或环境值;Tool 以 + 当前 OS 用户权限运行,不是 CLI sandbox,不调用文档、插件、进程业务。 + +## 目标构建与安装(未实现) + +下列命令是激活后的目标形态,当前不可执行,也不得在文档或 CI 中被当作已通过: + +```sh +# 目标:独立构建 +cargo build --locked --release +./scripts/package-tool.sh # 目标入口:产出 dist/marqdo-web-preview/{tool.json,bin/...} + +# 目标:冷安装为 marqdo web(不改变 CLI 二进制) +MARQDO_BIN=/absolute/path/to/frozen/marqdo +"$MARQDO_BIN" tool install "$(pwd)/dist/marqdo-web-preview/tool.json" +"$MARQDO_BIN" web check ENTRY --unit ANCHOR --root DIR +"$MARQDO_BIN" web preview ENTRY --unit ANCHOR --out out/ +"$MARQDO_BIN" tool remove web +``` + +`tool.json` 的合同示例只写在 [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) 中,作为目标清单 +(`requires {api_revision: 1, analysis: 3}`,不声明 Observation,无兼容字段)。本仓库 +当前不提交 `tool.json`,版本号 `0.1.0` 是规范建议值,不代表已发布。 + +## 文档 + +- [开发指南](docs/DEVELOPMENT.md):计划目录与 crate 结构、`tool.json` 示例、三条子命令的 + 宿主职责、Design API 消费、真实浏览器与冷安装测试、制品确定性与 evidence、 + `scripts/ci.sh` 与 `scripts/package-tool.sh` 的激活要求。 +- [安全边界执行合同](docs/SECURITY.md):转义与注入负例、link allowlist、raster 资产、 + CSP、路径/大小限制、原子 staging、隐私与 W21–W25 验收映射。 +- [维护指引](AGENTS.md):在本仓库工作的维护者与 AI Coding Agent 的责任、禁止事项、 + 变更与工单流程。 +- 作者面与领域组合:[`WEB-DESIGN.md`](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md) · + [领域开发指南](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/DEVELOPMENT.md) +- 生态台账:[docs/MIGRATION.md](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/MIGRATION.md) · + 架构:[docs/ARCHITECTURE.md](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/ARCHITECTURE.md) + +## 验收与证据状态 + +本仓库没有任何 `PASS`。接入后需在真实 CLI 制品、真实 Design 制品和真实 Chromium 上 +执行 Web 领域验收矩阵(规范 §15.3)中与 Preview 相关的项目,至少覆盖:W12(重复实例状态 +隔离)、W15–W20(真实 `file://`、390px、主题、场景切换、键盘/焦点)、W21–W25(XSS、 +无网络、raster 资产、隐私、零执行 sentinel)、W26–W28(失败无伪制品、Tool 冷安装、 +确定性)、W29–W31(单组件切片、依赖报告、三个示例共用同一 renderer)、W34–W36 +(原型诚实性、独立构建、三条命令与文档一致)。在给出绑定候选 SHA 与制品摘要的真实证据 +前,这些项目一律记为 `UNVERIFIED`,不得以测试不存在掩盖缺失。 + +## 责任与工单路由 + +发现缺陷先固定根/领域/组件 SHA、CLI 与 Design 制品摘要及最小复现,找第一个违反公开合同的 +所有者,不在本仓库为他人合同写 workaround。典型路由:手机布局溢出、场景实例串扰、XSS、 +CSP、资产校验归本仓库;表头未识别、Link 精确绑定、`not_loaded` 处理归 `marqdo-web-design`; +Analysis 字段或 resolver 公共合同缺陷归 CLI;作者面语义冲突或新增通用能力由 +`marqdo-ext-web` 走 ADR 并配对 Design/Preview 候选。工单模板与状态流以 Web 领域规范 +§12.2 与领域开发指南为准。 diff --git a/docs/DEVELOPMENT.md b/docs/DEVELOPMENT.md new file mode 100644 index 0000000..eeb8915 --- /dev/null +++ b/docs/DEVELOPMENT.md @@ -0,0 +1,300 @@ +# 开发指南:marqdo-web-preview + +本文件描述 `marqdo-web-preview` 接入后的开发、构建、测试与验收合同。仓库当前状态为 +`planned`:本文件中的目录、命令、入口和环境变量是**目标合同**,除本文档与 +[README](../README.md)、[SECURITY](SECURITY.md)、[AGENTS](../AGENTS.md) 外尚无实现文件, +任何目标命令都不得被记录为已执行或已通过。 + +权威来源: + +- 作者面与组件语义:[`marqdo-ext-web` / docs/WEB-DESIGN.md](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md) +- 领域组合与激活流程:[`marqdo-ext-web` / docs/DEVELOPMENT.md](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/DEVELOPMENT.md) +- 设计解释实现与公开 API:[marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) +- 生态分层与验收:[docs/ARCHITECTURE.md](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/ARCHITECTURE.md) · + [docs/DEVELOPMENT.md](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/DEVELOPMENT.md) · + [docs/MIGRATION.md](https://git.cflmy.cn/cflmy/marqdo/src/branch/main/docs/MIGRATION.md) + +## 1. 状态与激活门禁 + +当前 `planned`,未接入领域 gitlink。加入第一批实现文件(`Cargo.toml`/`Cargo.lock`、 +`src/`、`assets/`、`tool.json`、`scripts/`、`tests/`)前必须同时满足: + +| 门禁 | 通过条件 | +| --- | --- | +| 上游 API 可用 | WEB-01 的 Design 候选 API 已冻结到可消费程度;Preview 只用公开类型,不需要复制解释逻辑 | +| 真实输入 | 有固定 `MARQDO_BIN`(候选锁定 RC.4 及以后产品制品)与真实 Design 制品;`check --emit` 的 Analysis 3 行为已在真实夹具上确认 | +| Tool 协议 | `tool.json` 通过 CLI 现行 Tool revision 1 校验;`tool install`/分发/`remove` 在空 HOME、禁网环境真实通过(W27) | +| 安全负例 | W21–W25 至少一条真实浏览器证据绑定候选 SHA;安全合同不靠字符串检查 | +| 验收入口 | `scripts/ci.sh` 与 `scripts/package-tool.sh` 存在、可执行、真实通过,并记录命令与退出码 | +| 文档一致 | README/AGENTS/DEVELOPMENT/SECURITY 与实际实现、`tool.json`、命令和退出码一致(W36) | +| 领域接入 | 以上通过后,由 `marqdo-ext-web` 以精确提交更新子 gitlink;本仓库不自行改根仓库 | + +计划阶段只接受文档改动。不创建空 `src/`、空 `scripts/ci.sh`、占位 `tool.json` 或伪造 +`entry` 来“提前占位”;这类文件会被视为伪造实现与验收。 + +## 2. 计划目录与 crate 结构 + +单个主要 crate,不按表格、页面或子命令拆 crate。结构来自 Web 领域规范 §11,激活时按实际 +实现收敛,但必须保持“`main.rs` 只做宿主接线、渲染与导出分离、资产固定”的边界: + +```text +marqdo-web-preview/ +├── Cargo.toml / Cargo.lock # 锁定 marqdo-web-design 真实依赖身份 +├── tool.json # 激活时由 package-tool.sh 一起产出/校验,当前不存在 +├── src/ +│ ├── main.rs # 3 个子命令、参数、退出码、stdout/stderr +│ ├── cli.rs # 入口与输入配置(需要时;不解析设计文档) +│ ├── render.rs # Design 模型 → 安全静态结构投影 +│ └── export.rs # staging、资产校验、CSP、制品写出 +├── assets/ +│ ├── preview.css # 固定基础主题与 Grid 布局 +│ └── preview.js # 固定有限场景运行器(切换、焦点、重置) +├── tests/ # 真实 CLI/Design 合同、浏览器、XSS、冷安装 fixture +│ ├── browser/ # 真实 file:// 浏览器驱动与页面断言 +│ ├── fixtures/ # 正例与恶意/边界输入 +│ └── evidence/ # 绑定候选的 evidence manifest 与日志索引 +├── scripts/ +│ ├── ci.sh # 组件验收入口(激活时必须真实通过) +│ └── package-tool.sh # 生成 Tool revision 1 bundle +├── docs/ # 本目录(合同与安全文档) +└── README.md / AGENTS.md +``` + +约束: + +- `main.rs` 不解释设计表格;所有表格/章节选择在 Design 中完成。 +- `render.rs` 只消费 Design 的结构化模型(定义、实例、槽、布局、场景、来源),不读取 + 原始 Markdown,不处理 Analysis 原始 JSON 的语义。 +- `preview.js`/`preview.css` 是全部示例共享的固定资产;三个不同领域示例必须复用同一份 + renderer 资产(W31),只允许发布版本变化导致资产 hash 变化。 +- 不在 `assets/` 放业务样例数据、任务专用值或页面特定 JS;样例数据来自设计文档。 +- 测试 fixture 可以覆盖公共合同,但不得复制生产解释器作为 oracle;期望结果独立编写, + 并优先使用真实 Analysis 与真实浏览器。 + +## 3. 依赖与消费边界 + +### 3.1 依赖形式 + +| 依赖 | 允许 | 禁止 | +| --- | --- | --- | +| `marqdo-web-design` | 精确发布 crate 版本或明确 Git revision,`Cargo.lock` 固定 | `path = "../design"`、跟随 branch、测试 override 进入发布组合 | +| CLI | 通过 Design 间接消费公开 `check --emit` 结果 | 直接依赖 CLI 私有 crate(parser/AST/loader)、复制 resolver | +| Rust 生态 | 通用、有界、无网络/无脚本执行的可审计依赖 | 运行时抓取网络、嵌入浏览器执行、动态插件加载 | + +Design 与 Preview 独立 clone/build。CI 允许为配对候选使用明确的依赖 override 验证组合, +但最终发布必须以 Cargo.lock 固定真实依赖身份;不能把 CI override 当作发布依赖(W35)。 + +### 3.2 只消费 Design API,不自行解释表格 + +Preview 不重复实现以下任何一项:Markdown 解析、`.mq.md` 章节/表头识别、Link 目标绑定、 +`not_loaded` 的候选路径解析、anchor 生成、`UnitId.path`/`source_digest` 计算、场景可达性 +与图循环校验、Handoff Markdown 生成。这些都归 Design(WEB-01/WEB-03)。 + +消费的公开模型以 Design 发布的 API 为准(见其 `docs/API.md`,provisional);当前计划使用 +`Design`、`DesignGraph`、`ComponentDef`、`Instance`、`Scenario`、`SourceRef` 等公开类型。 +本地只允许做: + +- 参数组合与调用 `load`/`handoff`; +- 布局枚举(`auto`/`1fr`–`12fr`/`120px`–`1200px`)到固定 CSS Grid 的通用映射; +- 场景状态到固定 JS 运行器的通用投影; +- 安全转义、资产复制、CSP、staging、制品写出; +- 诊断与摘要的显示格式(不改写 Design 的诊断代码与来源)。 + +若 Design 模型缺字段或语义不清:在 `marqdo-web-design` 开工单;若涉及作者面语义,先在 +`marqdo-ext-web` 走 ADR,再配对候选。禁止在本仓库复制解析器、猜测 anchor、用文件名搜索 +目标或自行解释表格来兜底。 + +## 4. `tool.json` 合同(目标示例,当前不提交实体) + +按 Web 领域规范 §6.2,接入后的清单目标形态为: + +```json +{ + "schema": "marqdo.cli-tool", + "schema_version": 1, + "name": "marqdo-web-preview", + "version": "0.1.0", + "command": "web", + "entrypoint": "bin/marqdo-web-preview", + "requires": {"api_revision": 1, "analysis": 3} +} +``` + +约定: + +- 这是**目标清单示例**,`name` 与 `0.1.0` 是规范建议值,不代表已发布或已注册。 +- `command` 必须是 `web`,且生态中只能有一个 `web` Tool 入口;本仓库不声明第二个命令。 +- `requires` 只声明 `api_revision: 1` 与 `analysis: 3`;Observation 不用于首版,因此不声明。 +- 不写 `compatibility`、旧协议版本数组或迁移字段;不支持多版本作者面探测。 +- `entrypoint` 与实际 bundle 内的二进制路径一致,且是唯一入口;不增加子命令入口脚本。 +- 激活时 `tool.json` 与 `scripts/package-tool.sh` 一起进入仓库并通过 CI;本仓库在 + `planned` 阶段不创建该文件,README/本文档中的示例不得被误认为已提交清单。 + +安装与移除按现行 CLI 协议:`marqdo tool install /tool.json` → `marqdo web ...` → +`marqdo tool remove web`。冷安装验证不改变 CLI 二进制;篡改 bundle 必须被拒绝。 + +## 5. 三条子命令与宿主职责 + +三条子命令是唯一作者入口。Preview 负责**宿主侧**接线,Design 负责**设计解释**,CLI 负责 +**Tool 分发**。不新增 `web serve`/`web deploy`/`web agent`/`web generate-react`,不新增公共 +JSON 命令结果协议。退出码统一为:`0` 成功;`1` 设计/静态校验失败;`2` 参数/环境/工具协议/IO +失败(CLI 自身返回的诊断按其文档保留)。stderr 诊断,stdout 摘要。 + +| 命令 | Preview 负责 | Design 负责 | CLI(宿主)负责 | +| --- | --- | --- | --- | +| `web check ENTRY --unit ANCHOR [--root DIR]` | 解析三条参数与可选 `--root`;以 Design 配置调用 `load`;把诊断按稳定格式写 stderr、摘要写 stdout;返回对应退出码 | 真实 `check --emit`、Analysis 3 校验、设计模型、循环/可达性/限制诊断 | 发现 `tool.json`、分发 argv、按 Tool revision 1 处理 | +| `web preview ... --out DIR [--theme light\|dark]` | 主题枚举校验;调用 `load`;模型 → 静态投影;资产校验;CSP 计算;同父目录私有 staging 校验后原子发布;`--out` 默认不存在、不覆盖 | 同上,返回完整递归模型与直接输入摘要 | 同上 | +| `web handoff ... --out FILE` | 校验 `--out`、调用 `handoff`、原子写文件、默认不覆盖;不发明交付格式 | 生成 Markdown 交付内容(源引用、职责、接口、依赖、验收) | 同上 | + +行为约定: + +- `--unit` 为精确 anchor(无 `#`);Preview 原样传给 Design,不扫描整个项目寻找页面。 +- `ENTRY` 为项目内 `.mq.md`;`--root` 是显式项目范围,默认由 Design 按其公开规则处理; + Preview 不把 `--root` 假装成 CLI 的 package root,也不推断跨包路径。 +- `preview` 产物为单页离线制品:`index.html` + 必要本地资源(固定 `preview.css`/ + `preview.js` 与经校验的 raster 资产)。不生成开发服务器、热重载或网络请求。 +- `check` 只做静态检查,不写出制品;`handoff` 只写派生 Markdown 快照,源文档仍是权威。 +- 首版不承诺实时热重载;每次构建从源重新生成。改源后不重生成即显示旧原型属于使用错误, + 不是缓存协议。 + +## 6. 渲染器、制品与确定性 + +### 6.1 渲染 + +- 从 Design 的递归模型构造页面:父级只知道子槽与布局,禁止“父级渲染子级 HTML 字符串后 + 拼接”;子组件按精确文档/Unit 身份与根实例 + 槽路径获得独立实例身份。 +- 使用固定 HTML shell 与安全构造的静态标记,或 DOM `createElement`/`textContent`;通用 JS + 只做有限状态转换、焦点保持/移动与实例重置;不得执行源文本或 JSON 中的函数。 +- 场景:每实例恰有一个初始状态;点击可见按钮改变该实例状态并只更新该实例区域;每实例 + 提供重置入口,刷新回到初始状态;按钮明确标注“模拟”,不执行真实创建/提交/保存。 +- 布局:所有行以 CSS Grid 实现;`fr` 用 `minmax(0, Nfr)`,`auto` 用 `minmax(0, auto)`;固定 + px 仅在空间允许时使用;默认 768 CSS px 窄屏按声明顺序折为单列;单行最多 12 槽。 +- 可访问性:原生标题/表格/列表语义,按钮可键盘操作、可见焦点,状态提示用 `aria-live`; + 390px 下页面不得横向溢出(宽表允许组件内部明确滚动)。 +- 静态导航只指向制品中实际存在的锚点或普通安全链接;指向未打包本地文件的原始链接只显示 + 为来源提示,不从 `file://` 跳出原型范围。外部跳转必须由用户显式触发,不自动加载远端内容。 +- 制品显示清晰的“原型 / 模拟”标识与本轮构建摘要;不显示本地绝对路径或秘密。 + +### 6.2 制品内容与确定性 + +- 单页离线优先:不从 `file://` fetch 外部 JSON(避免 CORS)或依赖开发服务器;数据序列化 + 必须安全,防止 `` 与 HTML 特殊字符打断容器。 +- 若使用内嵌脚本/样式,由制品生成阶段计算 CSP hash;通用 `preview.js` 在所有示例内容不同 + 时保持相同 hash(只随发布版本变化)。 +- 相同输入 + 相同 CLI 制品 + 相同 Design 依赖身份,必须产生相同设计模型与相同交付内容 + (W28);模型与 Handoff 的内容确定性是硬要求,预览制品优先做到字节可比。若构建摘要 + 包含时间等非确定性内容,必须明确记录在证据中且不得进入安全/执行语义。 +- 构建摘要与 evidence 只列真正使用的设计输入;不把完整 Analysis、未选择模块、环境变量或 + 依赖源码打包进浏览器。 +- 构建失败不产生新的“成功制品”;`--out` 已存在、写入源文件/项目锁/清单、写符号链接目标 + 均拒绝,失败不删除用户既有目录。 + +## 7. 测试策略 + +所有正例必须使用真实 CLI 与真实 Design 制品;mock 只能用于隔离负例,不能作为合同正例。 +具体 fixture 与期望结果独立编写,不复制生产解释器。 + +### 7.1 设计/渲染合同测试 + +- 真实 CLI + Design:至少覆盖 W11–W20 中与 Preview 相关的行为:递归三层以上、视觉包含环 + 由 Design 拒绝;同组件重复实例状态独立(W12);行号/slot/宽度/预算越界由 Design 拒绝; + 场景初始/转移/可达性非法由 Design 拒绝。 +- Preview 自己的正例:多组件、多场景、两主题、单组件 `--unit` 切片、宽表/长标题;断言 + 页面结构语义、实例 HTML 标识与 slot 路径一致、构建摘要内容。 +- Preview 自己的负例:不可用 CLI、错误协议、超时、输出冲突、失败中断(W26);缺模型字段 + 或诊断不明确时明确失败并路由 Design,不部分渲染为成功。 + +### 7.2 真实浏览器(`file://`) + +- 用真实 Chromium(记录版本)打开生成制品的实际 `file://` URL;不需要开发服务器、网络或 + fetch 转接器(W15)。DOM snapshot 或字符串检查不能替代真实浏览器断言。 +- 390px 视口无页面横向溢出(宽表组件内部滚动允许,W16);桌面布局重排正确。 +- 主题切换、Markdown 标题/列表/表/图片/代码/链接展示正确(W17)。 +- 真实点击 ready→loading→failed→retry→ready,重置/刷新规则一致(W18)。 +- 复用两实例时切换一实例不修改另一实例或其焦点(W19)。 +- 键盘导航、可见焦点、`aria-live` 状态通知(W20)。 +- 安全负例按 [SECURITY.md](SECURITY.md) 的 W21–W25 用例在真实浏览器执行;观察网络请求、 + 执行错误与页面状态,不只检查 HTML 字符串。 +- 三个不同领域示例共用同一 renderer JS/CSS(W31),断言资产 hash 相同且无业务专用 JS 分支。 + +### 7.3 冷安装与分发 + +- 空 HOME、无 checkout、禁网:`tool install`、`web check/preview/handoff` 真实分发、 + `tool remove web`(W27)。 +- 记录 CLI 二进制 SHA-256:安装/移除前后一致,Tool 安装不改变 CLI。 +- 篡改 bundle(改二进制/清单/资产)必须被拒绝或至少不产生成功分发;记录实际行为。 +- 安装后不残留本仓库路径依赖;移走 build 目录后仍可运行。 + +### 7.4 确定性与性能 + +- 同输入双构建:模型、Handoff、预览制品摘要比较;固定脚本 hash;源改动后摘要与受影响 + 组件变化(W28)。 +- 性能目标按 Web 领域规范 §15.5/§9.3:记录环境(Linux x86_64、4 vCPU/8 GiB/SSD)、 + fixture 规模、样本数、CLI 启动占比、峰值 RSS、P50/P95;未达到阈值时分析瓶颈并请维护者 + 批准修订,不靠删除真实 CLI 检查提速。阈值与实测在真实执行前均为 `UNVERIFIED`。 + +## 8. `scripts/ci.sh` 与 `scripts/package-tool.sh` 激活要求 + +两个脚本当前不存在;激活时必须真实存在、可执行,并通过真实运行。不得用占位脚本或 +“跳过”分支冒充组件入口。 + +### 8.1 `scripts/ci.sh`(组件验收入口) + +- 入口合同(生态 §12.1):从**明确传入**的 `MARQDO_BIN`、Design 制品位置(精确 crate + 版本或锁定 Git revision 的 Cargo 依赖)与隔离测试输出目录读取输入;不自行拉取浮动 CLI + 或其他组件 `main`;不引入新的网络协议。 +- 建议环境变量(激活时固定名称并写入 evidence):`MARQDO_BIN`、`CARGO_HOME`、 + `CARGO_TARGET_DIR`、`PREVIEW_TEST_OUT`。未知/缺失输入或制品身份不匹配直接失败(E15 的 + 组件级等价物),不静默跳过。 +- 步骤顺序:`cargo fmt --check` → `cargo clippy --locked` → `cargo build --locked` → + 单元/合同测试 → 真实 CLI+Design 集成 → 真实 `file://` 浏览器 → 安全负例 → 冷安装/ + `tool remove` → 确定性比较 → `package-tool.sh` 产物体检。 +- 任一必需步骤非零或证据缺失则整体失败;stderr/stdout 保留真实命令与退出码;不修改 + tracked 文件,不把测试输出写入仓库根。 +- 只在 `check`/`preview`/`handoff` 三条命令上验收;发现新命令需求先回到 ext-web 合同评审。 + +### 8.2 `scripts/package-tool.sh`(Tool bundle) + +- `cargo build --locked --release`(不联网、不自动 `lock`/`install`),按 `tool.json` + 的 `entrypoint` 安装二进制到 `bin/`,把 `tool.json` 与固定资产放入 bundle;不写入 + 未声明的额外入口。 +- 校验清单:`schema == "marqdo.cli-tool"`、`schema_version == 1`、`command == "web"`、 + `requires == {api_revision: 1, analysis: 3}`、无 `compatibility`;与实际二进制路径一致。 +- 输出 bundle 目录(目标 `dist/marqdo-web-preview/`)并打印二进制与 `tool.json` 的 + SHA-256;产物可被离线 `tool install` 使用。构建可重复,记录 SOURCE_DATE_EPOCH/toolchain + 等影响输出的输入。 +- 不从源码树外部复制未跟踪文件;不把 `target/`、测试 artifact、凭证或绝对路径写入 bundle。 + +## 9. 证据与发布 + +每份组件证据至少包含:仓库与提交 SHA;Design 依赖版本/提交与制品摘要;CLI 版本与 +SHA-256、平台;工具链与浏览器版本;真实命令与退出码;fixture 与制品摘要;测试范围与 +结果;未验证项。组件可独立 SemVer 发布,但独立版本不代表维护多套现行协议;预稳定期 +破坏性变更必须与 Design/Ext-Web 同候选联调。领域与根发布只采用绑定候选 SHA 的真实证据, +FAIL/UNVERIFIED 阻止对应阶段验收。 + +## 10. 变更、工单与晋升 + +- 本仓库缺陷(手机溢出、实例串扰、键盘/焦点、XSS、CSP、资产、路径、制品泄漏)在本仓库 + 开工单并修复;Design 缺陷在 `marqdo-web-design` 修复;CLI 公共协议缺陷在 CLI 修复; + 作者面语义冲突在 `marqdo-ext-web` 走 ADR。不在本仓库为他人合同加 workaround。 +- 工单按生态 §12.2 模板记录:责任组件、类型、影响消费者、可复现候选(根/领域/组件 SHA、 + CLI/Design 制品摘要与平台)、最小 fixture/命令/实际结果、预期与合同链接、修复范围、 + 验收(正例/负例/回归/安全性能)与证据。 +- 晋升顺序:组件提交 C2 → 组件 CI;领域 PR 更新 `marqdo-ext-web` 子 gitlink 至 C2 并通过 + 领域 CI(B2);根 PR 更新领域 gitlink 至 B2 并通过受影响组合验收(A2)。失败停在对应层。 +- 文档与实现同时更新;合同语义变更新旧作者面一次切换,不保留旧表头/旧命令兼容探测。 + +## 11. 未验证事项(当前 `planned` 状态) + +以下均为 `UNVERIFIED`,不得在文档、工单或发布说明中写成已通过: + +- 无任何实现代码、Cargo 构建、`tool.json`、CI 入口或发布制品。 +- 未在真实 RC.4 CLI 上以 Design 候选 API 跑通 `load`/`handoff`;Design 公开 API 仍为 + provisional,字段可能调整。 +- 未在真实 Chromium 打开实际 `file://` 制品;W15–W20、W31 未执行。 +- 未执行 W21–W25 恶意 fixture;CSP 在 `file://` 下的具体指令效果(尤其 `img-src`)需真实 + 浏览器确认,本文给出的策略是目标基线。 +- 未执行 `tool install`/分发/`tool remove` 冷安装(W27),未核对 CLI 二进制不变。 +- 未测量确定性双构建、性能/资源阈值与浏览器版本矩阵;未固定 ARM/macOS 支持。 +- 远端仓库、领域 `components.toml` 登记、gitlink、CI 流水线与 issue 模板尚未创建。 diff --git a/docs/SECURITY.md b/docs/SECURITY.md new file mode 100644 index 0000000..05e6e99 --- /dev/null +++ b/docs/SECURITY.md @@ -0,0 +1,233 @@ +# 安全边界执行合同:marqdo-web-preview + +本文件是 `marqdo-web-preview` 的安全执行合同,细化 Web 领域规范 §10.2/§10.3 与验收 +W21–W25。仓库当前 `planned`,本文是接入后必须实现并**用真实浏览器验证**的目标合同, +不是已实现或已验收事实。 + +范围:Preview 对设计模型的安全投影、离线制品导出、本地资产复制、CSP、staging 发布与证据 +输出。不属于范围:Design 的设计解释安全(归 `marqdo-web-design`)、CLI 的 Analysis/resolver +公共合同(归 `marqdo-cli`)、生产应用的安全(归目标应用仓库)。 + +## 1. 信任模型与责任 + +- **所有输入均为不可信**:`.mq.md` 源文本、Design 模型中的文本/链接/场景/来源说明、本地 + 资产候选文件、CLI 输出的 Analysis 数据,都按敌意输入处理。 +- **Tool 不是安全沙箱**:`web` 以当前 OS 用户权限运行;安全性来自不执行文档、不联网、 + 受限路径与有界输出,而不是进程隔离。不得宣称 Preview 提供 CLI 级别的隔离或权限模型。 +- **允许的副作用**只有:一次受控静态 `check --emit`(经 Design)、读取 `--root` 内允许的 + 输入与 raster 资产、在 staging/输出目录写制品。不执行文档、`@exec`、脚本、插件、Worker、 + Foreign;不联网;不 `lock`/`install`;不启动服务或监听端口。 +- **失败即失败**:任何校验不通过、超限、来源可疑或环境异常必须非零退出;不产生新的“成功 + 制品”,不部分渲染为成功,不静默跳过组件或资产。 + +## 2. 强制控制总表(规范 §10.3) + +| 风险 | 强制控制 | 验收 | +| --- | --- | --- | +| 原文 HTML/JS 注入 | 原文 HTML 只作文本或明确占位;无 `eval`/`Function`/`innerHTML`/`outerHTML`/`insertAdjacentHTML`/`srcdoc`/`on*` 属性/`javascript:` 属性值/任意脚本资源 | W21 | +| 恶意 Markdown 链接 | 协议 allowlist(制品内锚点或显式 `http`/`https`);拒绝 `javascript:`/`data:`/`file:`/`vbscript:`/`blob:` 等;绝不自动网络请求 | W21/W22 | +| 图片/资源泄漏 | 只复制明确展示的项目内普通 raster(PNG/JPEG/WebP/GIF),路径/大小/魔数校验;远端图片文本占位;SVG/HTML 作为代码或参考,不内联执行 | W22/W23 | +| 任意 CSS | 只使用内置固定 CSS;作者 CSS 围栏与 CSS 资源仅作为设计交付显示,不自动应用 | W22 | +| 资产/源码越界 | 固定 `--root`、一次解码、canonical 检查、拒绝 symlink/路径逃逸/特殊文件;不复制完整 Analysis、环境或 server 源 | W23/W24 | +| 内容与 script 数据混合 | 上下文相关转义;``、``、Unicode、双引号等恶意 fixture 在真实浏览器中不执行 | W21 | +| 权限误解 | 明确 Tool 以 OS 用户权限运行;不执行文档/插件/进程业务;仅受控静态 `check` | W25 | +| 离线制品外联 | CSP `default-src 'none'`、`connect-src 'none'`、hash 化固定脚本/样式、受限本地图片;禁止表单提交与嵌入 | W22 | +| 资源耗尽 | 解析、图遍历、资产、输出文件/HTML 大小与静态进程均受限;超限确定失败并报来源 | W13/W23/W26 | + +## 3. HTML/文本转义与脚本上下文注入 + +### 3.1 投影规则 + +- 设计内容只能进入固定模板的**文本位置**或经过白名单属性;标记由 Preview 构造 + (静态标记或 `createElement`/`textContent`),不使用字符串拼接 HTML。 +- 源文档中的 raw HTML 节点显示为文本或明确占位(例如“原始 HTML 不渲染”),不解释为活动 + HTML。 +- 链接 `href` 只接受 allowlist 后的值(见 §4);`title`/`alt`/`aria-*` 等属性值按属性上下文 + 转义,禁止出现未转引号、换行注入或事件属性。 +- 场景按钮标签、状态名、组件职责、验收文本、诊断说明等字段一律按文本处理。 +- CSS 只来自固定资产;主题参数只接受枚举 `light|dark`,不把作者文本拼入样式。 +- 不生成 `
`、`