diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e13a145 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +/target/ +/dist/ +/tests/.cache/ +/tests/browser/node_modules/ +/tests/browser/artifacts/ +*.swp +.DS_Store diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,202 @@ + + 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/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..28772dd --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 Marqdo contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 4ca4470..5adb194 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,59 @@ -# marqdo-view 开发规范交付包(不是已实现的源码仓库) +# marqdo-view -此目录包含实施新独立 `marqdo-view` 所需的完整架构规范和用户提供的旧界面截图。两者须一起提交到未来的 `marqdo-view` 独立仓库,并在正式实现时逐步补齐 `docs/STATUS.md`、ADR、测试、独立 bundle。 +Marqdo View 是一个独立的可执行文档阅读器:以**原始 Markdown 为阅读主体**,把冻结 `marqdo` CLI 的静态语义(Analysis v2)与用户显式触发的真实运行轨迹(Trace v2)附着回原文,而不是把文档翻译成另一套语言。 -- `docs/RFC-VIEW-0001.md`:总体架构、历史取证、语义/协议、安全、目录、PR、验收。 -- `docs/design/reference-old-view-reader.png`:1664×920 的旧 View 视觉参考。并非已验证的旧仓库 HEAD 页面截图。 +- 设计总规范:[`docs/RFC-VIEW-0001.md`](docs/RFC-VIEW-0001.md) +- 实际实施状态(唯一现状来源):[`docs/STATUS.md`](docs/STATUS.md) +- 旧 View 取证审计:[`docs/audits/legacy-render-paths.md`](docs/audits/legacy-render-paths.md) +- 关键决策:[ADR-0001](docs/ADR/0001-single-package-single-pipeline.md) / [ADR-0002](docs/ADR/0002-embedded-assets-tool-protocol.md) +- 视觉基准:`docs/design/reference-old-view-reader.png` 与 [`docs/design/visual-tokens.md`](docs/design/visual-tokens.md) -新项目应从空仓库开发,禁止直接把旧 `marqdo/src/view/` 复制为运行代码,禁止修改或编译 `marqdo-cli` 核心。实施证据由实际开发者生成,规范文件本身不代表已有代码已实现。 +## 当前状态 + +**开发中,尚未可运行。** PR-00(基线、旧 View 静态取证、视觉/状态设计基准)已完成;后续按 PR-01→PR-06 交付 Tool Protocol v1 安装闭环、只读浏览、Reader 视觉、Trace 可视化、Live/Export 安全与端到端验收。任何未完成能力都必须在 `docs/STATUS.md` 与 CHANGELOG 明确标注,不以占位功能冒充已实现。 + +## 架构约束(摘要) + +```text +Browser / static HTML + │ +Reader UI(唯一 reader.css + reader.js) + │ +ReaderRenderer(唯一模板) + │ +PresentationModel(唯一模型) ── DocumentModel / SemanticProjection / RunProjection + │ +PublicCoreClient ── MARQDO_BIN 子进程 + 公开 JSON(check --emit / run --trace-file) + │ +冻结发布版 marqdo CLI(不修改、不重编译、不链接) +``` + +- 单一 Rust package、单一渲染入口、单一主题文件;Live 与 Export 共用同一份渲染字节。 +- 不依赖旧 `marqdo` 仓库或 `marqdo-cli` 的私有 crate/源码;仅通过 `MARQDO_BIN` 与公开协议交互。 +- 默认纯只读、不自动执行;执行必须由用户在 UI 中显式确认,最低权限首选 `--mode pure`。 +- Trace v2 不提供逐语句变量值/内存快照;新 View 一律标 `UNSUPPORTED`,绝不伪造。 + +## 开发 + +```bash +export PATH="$HOME/.cargo/bin:$PATH" +cargo fmt --all -- --check +cargo clippy --all-targets -- -D warnings +cargo test --locked +cargo build --release --locked +``` + +安装到冻结 CLI(开发期): + +```bash +MARQDO_BIN=/absolute/path/to/marqdo +./tools/package.sh +"$MARQDO_BIN" tool install "$(pwd)/dist/marqdo-view/tool.json" +"$MARQDO_BIN" view --help +``` + +完整安装/验收步骤见 RFC §18,脚本位于 `tools/`。 + +## 许可 + +代码按 MIT / Apache-2.0 双许可发布(见 `LICENSE-MIT`、`LICENSE-APACHE`)。复用的旧 View 视觉资产授权与来源见 `assets/licenses/`。 diff --git a/docs/ADR/0001-single-package-single-pipeline.md b/docs/ADR/0001-single-package-single-pipeline.md new file mode 100644 index 0000000..6001b68 --- /dev/null +++ b/docs/ADR/0001-single-package-single-pipeline.md @@ -0,0 +1,30 @@ +# ADR-0001:单 Package、单管线、单一 ReaderRenderer + +- 状态:Accepted +- 日期:2026-11-22 +- 关联:RFC-VIEW-0001 §6、§7、§14;`docs/audits/legacy-render-paths.md` + +## 背景 + +旧 View 至少存在三类文档呈现入口(Reader `serve`、Workbench `ViewAction::Document`、Debug `serve_debug`)与三层叠加 CSS(`stylesheet()` → `notebook_ui()` → `reader.css`)。其中深色 Notebook 层通过 `body.reader-page.notebook-page` 覆盖但 body class 从未被设置,属于携带而无效的死层。静态导出路径默认还会执行文档以抓取输出快照。 + +新 `marqdo-view` 必须在只有发布版 `marqdo` 二进制、没有旧仓库源码的机器上独立构建运行,并且不允许出现第二套渲染/语义管线。 + +## 决策 + +1. **单一 Rust package**(`Cargo.toml` 只有一个 `[package]`,无 workspace、无内部 crate)。 +2. **唯一依赖方向**: + `CLI/Server → Application → Domain → ProtocolAdapter`,以及 + `Application → Presentation → Renderer → Assets`。 + `Domain` 不得引用 HTTP 请求;`Renderer` 不得启动子进程;`reader.js` 不得解释 Marqdo 语义。 +3. **唯一渲染入口**:`render.rs::ReaderRenderer::render(&PresentationModel, LinkPolicy)`。Live 与 Export 只差 `LinkPolicy` 与控件可用性;`Command` 层不得自己拼 HTML。 +4. **唯一呈现模型**:`presentation.rs::PresentationModel { document, semantic, run, overlays, source_status }`,由 `PresentationBuilder` 从**已验证**类型构建;未验证 JSON 不进入渲染端。 +5. **唯一前端主题**:`assets/reader.css`(`@layer reset,tokens,layout,typography,semantics,overlays,interactions,responsive`)+ `assets/reader.js`(只操作 `[data-action]`/`[data-source-id]`/`data-*`)。禁止 `legacy.css`/`new.css` 并行、禁止 `!important` 覆盖链。 +6. **唯一用户可见命令层**:`cli.rs` 用 clap 解析 `view` 自身的 `browse/export/verify`;`main.rs` 只做分发。 +7. **唯一核心交互**:`core_client.rs::PublicCoreClient` 通过 `MARQDO_BIN` 子进程与公开 JSON 交互;`check --emit` 生成 Analysis v2,`run --trace-file` 生成 Trace v2。禁止链接 CLI crate、读取 CLI 源码、`inspect --ir`。 + +## 后果 + +- 正面:Live/Export 内容天然一致(同一字节源);协议校验集中在 `semantic.rs`/`trace.rs`;可对 `PublicCoreClient` 注入假核心做负向测试。 +- 负面:首版无法提供旧版的 Notebook/调试面板;这些能力必须以 `UNSUPPORTED` 显式降级,而不是塞第二套 UI。 +- 门禁:`tests/contract/` 静态扫描 `Cargo.toml`/`Cargo.lock`/`src/`,拒绝 `marqdo`/`marqdo-cli`/`marqdo_ir` 等依赖与 `../marqdo` 路径读取;拒绝第二个 `render`/`stylesheet` 入口。 diff --git a/docs/ADR/0002-embedded-assets-tool-protocol.md b/docs/ADR/0002-embedded-assets-tool-protocol.md new file mode 100644 index 0000000..1e57a6f --- /dev/null +++ b/docs/ADR/0002-embedded-assets-tool-protocol.md @@ -0,0 +1,37 @@ +# ADR-0002:资产内嵌与 Tool Protocol v1 分发 + +- 状态:Accepted +- 日期:2026-11-22 +- 关联:RFC-VIEW-0001 §4.1、§7、§11.3、§14.5、§17.3 + +## 背景 + +Tool Protocol v1 安装时复制整个 bundle,并对每个文件做 SHA-256、启动前重算整包清单。View 需要同一份 CSS/JS/图片同时服务 Live 与离线 Export。若 Live 读源码目录、Export 读另一份文件,就会出现 RFC §3.3 禁止的“两套资产来源”。 + +## 决策 + +1. 首版把 `assets/reader.css`、`assets/reader.js`、`assets/logo.svg`、`assets/blossom.webp`、`assets/feather.webp` 通过 `include_bytes!` **编译内嵌**为 `src/assets.rs::AssetBundle`;每个资产带 SHA-256,Live 路由 `/assets/.` 与 Export 写盘使用同一份字节。 +2. 发布 bundle 只包含运行必需文件: + + ```text + dist/marqdo-view--/ + tool.json + bin/marqdo-view + README.md + COMPATIBILITY.md + LICENSE-MIT + LICENSE-APACHE + SOURCE_SHA + RELEASE_INFO.json + ``` + + CSS/JS/图片不额外放在 bundle 根(已内嵌),避免“内嵌 + 外部”双来源。 +3. `tool.json` 由源码模板 `tool.json` 固定,`compatibility.marqdo = ">=3.0.0-beta.1,<4.0.0"`、`analysis: [2]`、`trace: [2]`;bundle 目录内 `bin/marqdo-view` 是 release 构建产物。 +4. 开发时允许 `marqdo-view --marqdo-bin PATH` 直启;安装态必须以 `MARQDO_BIN` 为准,且不向核心传自定义参数格式。 +5. `tools/package.sh` 负责:`cargo build --release --locked` → 校验工具协议/SHA → 组装 dist → 写 `SHA256SUMS`/`SOURCE_SHA`/`RELEASE_INFO.json` → 用冻结 CLI 做一次 `tool install` + `view --help` 烟测。 + +## 后果 + +- 正面:离线 Export 与 Live 字节一致;Tool 协议能校验唯一二进制;无运行时资产丢失风险。 +- 负面:修改 CSS/JS 必须重新编译二进制(可接受,前端资产规模小;由 `build.rs` 在资产变化时触发重编)。 +- 门禁:`tests/rendering/asset_tests.rs` 断言 `AssetBundle` 摘要与磁盘源文件一致;`tests/contract` 断言 bundle 内无未声明文件、`entrypoint` 指向可执行文件。 diff --git a/docs/STATUS.md b/docs/STATUS.md new file mode 100644 index 0000000..feb50be --- /dev/null +++ b/docs/STATUS.md @@ -0,0 +1,36 @@ +# marqdo-view 现状(STATUS) + +> 唯一现状来源。其他文档描述设计;本文件只记录**实际完成、证据与限制**。 +> 最后更新:2026-11-22(PR-00 完成) + +## 版本与基线 + +| 项 | 值 | +|---|---| +| View 版本 | `0.1.0`(开发中) | +| 目标 CLI 产品范围 | `>=3.0.0-beta.1,<4.0.0` | +| 冻结 CLI 二进制 | `/root/work/marqdo-cli/dist/marqdo-3.0.0-beta.1-x86_64-unknown-linux-gnu/marqdo` | +| 冻结 CLI SHA-256 | `062cb56e226bee55c21d238e195920caa985e62bb3877ba7b07abcc04dc0fe3f` | +| CLI 源码 SHA | `2c7c4f31e7a388d3fcfa717a77067e696ed13854`(tag `v3.0.0-beta.1`) | +| 协议 | Tool v1 / Analysis v2 / Trace v2 / markdown profile `marqdo.md.v1` | +| 目标平台 | Linux x86_64 glibc(正式);其他平台未验证 | +| 视觉基准 | `docs/design/reference-old-view-reader.png`(1664×920) | + +## 分阶段进度 + +| 阶段 | 状态 | 证据 | +|---|---|---| +| PR-00 基线与旧 View 取证 | **完成** | `docs/audits/legacy-render-paths.md`、`docs/design/visual-tokens.md`、`docs/design/state-matrix.md`、ADR-0001/0002 | +| PR-01 Tool v1 安装闭环 | 未开始 | — | +| PR-02 DocumentModel + Analysis v2 浏览 | 未开始 | — | +| PR-03 Reader 视觉重建 | 未开始 | — | +| PR-04 Trace v2 运行可视化 | 未开始 | — | +| PR-05 Live 安全 + 静态导出 | 未开始 | — | +| PR-06 冻结 CLI 端到端验收 | 未开始 | — | + +## 证据与限制 + +- 旧 View 运行时状态:`LEGACY_RUNTIME_UNVERIFIED`(旧仓库无预编译产物,且任务禁止修改/编译旧仓库;只做只读静态审计)。 +- 本仓库尚未包含可运行实现;在 PR-01 之前 `marqdo view` 不存在。 +- 已核对旧视觉资产许可(旧仓库 Apache-2.0):logo/blossom/feather 可复用,KaTeX 不引入。 +- 已知非目标:变量运行值、内存快照、调试器、Prove/Knowledge/Lint 引擎(均标 `UNSUPPORTED`)。 diff --git a/docs/audits/legacy-render-paths.md b/docs/audits/legacy-render-paths.md new file mode 100644 index 0000000..61f4fa4 --- /dev/null +++ b/docs/audits/legacy-render-paths.md @@ -0,0 +1,180 @@ +# 旧 View 渲染路径审计(PR-00) + +> 状态:**静态审计完成,运行时验证未执行(`LEGACY_RUNTIME_UNVERIFIED`)** +> 审计对象:`cflmy/marqdo` `main@1c55baabd570e18b9da8f9057cef2f848e176690`(下称“旧仓库”) +> 审计方式:只读源码检查(`git status` 干净;**没有**编译、没有写入、没有移动旧仓库任何文件) +> 审计日期:2026-11-22 +> 结论用途:决定新 `marqdo-view` 可复用/必须重写/必须丢弃的视觉与结构素材。旧语义、旧执行模型、旧私有 API **一律不复用**。 + +## 0. 审计边界与可信度声明 + +1. 旧仓库为 Apache-2.0(`/root/work/marqdo/LICENSE`),其视觉资产可在保留许可声明的前提下筛选复用(§6)。 +2. 旧仓库**没有已编译产物**(无 `target/`),且本任务明令禁止修改旧仓库。因此本次**未启动旧 View 服务、未抓取 DOM/Computed Style/Network/HAR**。所有结论均来自可复核的静态源码行号,属于 RFC §3.1 允许的“结构证据”。 +3. 随 RFC 保存的 `docs/design/reference-old-view-reader.png`(1664×920)是**用户提供的视觉基准**,不是本审计运行得到的截图。旧仓库 HEAD 实际渲染结果是否与截图一致**未验证**。 +4. 标记规则沿用 RFC:`OBSERVED`=源码直接可见;`INFERRED`=由源码组合可推断但未运行验证;`UNVERIFIED`=无法静态确认。 +5. 旧版语法/旧 `ViewExecutionReport`/旧知识制品都**不是** 3.0 契约;本审计只提取“视觉语言”和“曾经犯过的结构错误”,不提取任何运行时语义。 + +## 1. 命令 → 函数 → 模板 → CSS/JS → HTML 路径 + +| 用户命令 | 入口 | 渲染函数 | 模板 | 注入 CSS/JS | 产物 | +|---|---|---|---|---|---| +| `marqdo view [PATH]`(无子命令) | `src/main.rs:1657` `Commands::View` → `None` 分支 `src/main.rs:1737` | `view::serve`(`src/view/mod.rs:74`)→ `handle` → `page_file`(`src/view/html.rs:4111`) | `html::layout`(`src/view/html.rs:1667`) | `layout` 内 ``、``、``;`page_file` 的 `main` 中再插入 `notebook_ui()` ` + +(旧变量快照 UI) + +``` + +对应旧行为(`reader.js:88` 的 `action(name)`): + +- `run` → `POST /api/run`(`src/view/mod.rs:805`),执行并流式返回 `bindings_html`/`structure_html`/`trace_json`; +- `variables`/`memory` → 展示旧 `ViewExecutionReport` 的变量/内存快照(Trace v2 **不提供**这些数据,新 View 不得复刻); +- `functions` → 把旧结构面板移入 dialog; +- `settings` → 浅/深色、正文字号、标注显隐(深色依赖 `#nb-theme`,即休眠的 notebook 皮肤); +- `clear` → 隐藏旧输出; +- `search` → 在当前页面文本内搜索,并混入文件导航(`reader.js:69`–`82`)。 + +**主阅读区(`page_file`,`src/view/html.rs:4111`–`4330`):** `h1.page` + `.status-pill`、`.meta` 路径、`notebook_ui` 样式、文档 `structure_block`、可选知识块、执行块(stdin 表单/流式面板/结果 `
`/plot)、`
` 完整源码。**它不是“连续 Markdown 长文”,而是“文档 + 运行结果 + 完整源码”的多段拼接页**,与 RFC §2.2 的目标形态不同。 + +## 4. Welcome Hero 的生成方式(OBSERVED,必须重写) + +`src/view/reader.js:568`–`575`: + +```js +var path = window.MARQDO_FILE_PATH || ''; +if (/(^|\/)(00[-_])?(welcome|欢迎)/i.test(path)) { + document.body.classList.add('reader-welcome'); + var hero = document.createElement('section'); hero.className = 'reader-hero'; ... + hero.innerHTML = '

WELCOME TO

Marqdo

代码即文档 · 文档即知识库 · 知识即可执行

'; + document.querySelector('main.panel').prepend(hero); +} +``` + +**结论:旧版按文件名正则(`00-welcome` / `welcome` / `欢迎`)在客户端插入 Hero,且用 `innerHTML` 拼字符串。** 新 View 要求由**显式 `view.json` 配置**选择 Welcome 页面,由服务端 `ReaderRenderer` 输出,JS 不得按文件名插入 UI(RFC §9.4、§7.1)。 + +## 5. 静态导出与执行副作用(OBSERVED,新实现必须纠正) + +`write_static`(`src/view/output.rs:266`–`338`): + +1. 默认(未传 `--no-exec`)为每个文件调用 `build_file_view_with_exec(..., !opts.no_exec)`; +2. 未提供 `--snapshot` 时调用 `static_page_data(&root, &abs, &vm.preset_stdin)`(`src/view/output.rs:67`),即**导出过程中执行文档**以获得输出快照; +3. 再把输出注入 HTML(`inject_cell_outputs` / `inject_static_session`,`src/view/output.rs:147,172`)。 + +**结论:旧 `view output` 的默认路径存在“导出时执行”的语义,只有显式 `--no-exec`/`--snapshot` 才能避免。** 新 View 的 `export` **无条件纯只读**(RFC §11.3),并且该差异必须写成对抗测试(`tests/security`),而不是仅靠文档说明。 + +另外旧 `/api/run`(`src/view/mod.rs:805`–`880`)只做 body JSON 解析与 `resolve_rel`,**没有** CSRF token、`Origin`/`Host` 校验或一次性会话确认;`/api/foreign-run` 同样存在。新 View 不得继承此模型(RFC §11.2)。 + +## 6. 旧视觉资产清单与复用决策(OBSERVED + 许可核对) + +| 资产 | 大小 | SHA-256 | 来源/许可 | 决策 | +|---|---|---|---|---| +| `src/view/assets/logo.svg` | 4 KiB | `52b2338468c62a7da86178ecec86cbb7ea44a996cd1bc4275ebb56f16f2244fe` | 旧仓库自绘 SVG,Apache-2.0 | **KEEP_VISUAL,复制为 `assets/logo.svg`**(保留新旧 IR 差异说明与许可) | +| `src/view/assets/blossom.webp` | 84 KiB | `901fd6b37ebb20d1dfc3bf4d265a063308605350fd317e41914fa35b06f46e00` | 旧仓库 `assets/README.md`:imagegen 生成的原始透明插画;Apache-2.0 | **KEEP_VISUAL,复制为 `assets/blossom.webp`** | +| `src/view/assets/feather.webp` | 12 KiB | `fbd787174be1e8027ae4661b99f7f2cc01b824d8fc875a1d2d39cbd0c052e5de` | 同上 | **KEEP_VISUAL,复制为 `assets/feather.webp`** | +| `src/view/assets/blossom.png` / `feather.png` | 950 KiB / 1.7 MiB | `2189f61b...` / `1b933940...` | 旧仓库设计原图 | **DROP**(新仓库不携带未进入构建的大图) | +| `assets/vendor/katex.min.*` | ~1 MiB+ | 见 `vendor/KATEX-LICENSE` | KaTeX 0.16.22,MIT | **不复制**:首版公式以保守可读文本 + 可选本地渲染,不引入 1 MiB vendor 与自动渲染脚本 | +| `reader.css` | 268 行 | — | 旧仓库自写,Apache-2.0 | **REWRITE**(只提炼令牌与视觉关系,不复制选择器/覆盖链) | +| `reader.js` | 594 行 | — | 同上 | **REWRITE**(只保留交互职责边界;Welcome 正则、旧 trace/变量面板、`innerHTML` 一律丢弃) | +| `html.rs` 的 `stylesheet()` / `notebook_ui()` | ~2800 行 | — | 同上 | **DROP**(新仓库从零写单一 `reader.css`) | +| `debug_page.rs` + 调试 API | 973 行 + API | — | 同上 | **DROP**(首版无 debug,见 RFC §1.3/§3.1) | +| 旧 `knowledge_*` 制品 | 477 行 | — | 旧 `sema::SemanticProject` | **DROP**(不是 Analysis v2 / Proof 3.0) | + +资产权利说明:旧仓库根 `LICENSE` 为 Apache-2.0;KaTeX 为 MIT(未复制)。复制进新仓库的三个文件在 `assets/licenses/` 记录来源 commit、SHA-256 与 Apache-2.0 归属。 + +## 7. 截图元素清单与实现归属 + +由 `docs/design/reference-old-view-reader.png`(1664×920)与 RFC §2.1 拆解,逐元素指定新实现归属: + +| 截图元素 | 归属 | 新实现 | +|---|---|---| +| 暖纸/米色画布、低对比边界 | KEEP_VISUAL | `assets/reader.css` `tokens` 层唯一令牌 | +| 左上樱花枝 | KEEP_VISUAL | `blossom.webp`,`aria-hidden="true"`,仅装饰 | +| 顶栏三横线 / 品牌 / `EXECUTABLE KNOWLEDGE` / 搜索 | KEEP_VISUAL | 服务端模板 + `[data-action]` | +| 顶部分段导航 `文档/函数/变量/内存/运行` | REWRITE | 首版 `文档/函数/运行`;`变量` 只显示静态参数/赋值目标;`内存` 明确 UNSUPPORTED 并从主 Tab 移除 | +| Welcome:`WELCOME TO` + 金色斜体 `Marqdo` + 羽毛 + 口号 | KEEP_VISUAL | 仅 `view.json` 显式 welcome 页面,服务端渲染 | +| 文件名 + 叙述折叠块 + 导入/引用椭圆标签 | REWRITE | 文件身份条 + Analysis imports/references 标签(无旧语法) | +| `main` 大标题 + 左侧细金斜竖线 + 说明小字 | KEEP_VISUAL | `[data-semantic="exec"]` 标题样式,来源 Analysis `functions[]` | +| GFM 表、英文正文 | KEEP_VISUAL | Comrak 渲染 + 净化 | +| 底部胶囊 Dock(刷新/设置/金色运行/清理/更多) | KEEP_VISUAL | 每个按钮必须有真实动作;Export 中运行按钮变说明文字 | +| 右侧黑色短线/竖线 | DROP(原因不明,UNKNOWN) | 不复刻;新页面不产生无来源装饰线 | + +## 8. 旧版结构失误 → 新架构硬约束 + +| 旧版事实 | 新架构约束 | +|---|---| +| `stylesheet()` + `notebook_ui()` + `reader.css` 三层叠加、`body.reader-page.notebook-page` 高特异性覆盖 | 单一 `assets/reader.css`,`@layer reset,tokens,layout,typography,semantics,overlays,interactions,responsive`,禁止遗留皮肤文件与 `!important` 覆盖链 | +| `serve`/`write_static` 共用模板(好)但 `ViewAction::Document` 另有一套 HTML | 只允许一个 `ReaderRenderer::render()`;Live/Export 仅 `LinkPolicy` 与控件可用性不同 | +| Welcome Hero 由 JS 文件名正则 + `innerHTML` 插入 | 显式 `view.json` + 服务端渲染,无文件名正则 | +| 静态导出默认执行文档以抓快照 | `export` 永不执行;`--no-annotations` 只影响标注 | +| `/api/run` 无 CSRF/Origin/Host 校验 | 一次性 CSRF token + 严格同源/Host 校验 + 显式确认 | +| 旧 `ViewExecutionReport` 提供逐句变量值/内存快照 | Trace v2 不提供;新 UI 状态矩阵显式 `UNSUPPORTED`,绝不伪造 | +| `notebook_ui()` 深色 skin 进入每页字节却不生效 | 资产按实际进入构建;CSS/JS 单一入口与 SHA-256 记录 | + +## 9. 运行时验证状态与复现步骤 + +- 状态:**`LEGACY_RUNTIME_UNVERIFIED`**。 +- 原因:旧仓库无预编译产物;本任务禁止修改/编译旧仓库;在本机从头构建旧 2.9.1 工程不符合“新项目只依赖发布版 CLI”的验收前提,且会污染只读审计对象。 +- 复现(在**旧仓库副本**中、不覆盖原始工作树时)应执行: + +```bash +cp -a /path/to/marqdo /tmp/legacy-marqdo-audit && cd /tmp/legacy-marqdo-audit +cargo build --release --features cli,view +./target/release/marqdo view --no-open examples/ # 记录 URL +# 用 Chromium DevTools 保存 DOM、Computed Style、style rule 命中源、Network、截图 +rg -n 'reader-hero|reader-dock|reader-connectors|annot-band|notebook-page' src/view +``` + +- 若将来完成上述步骤,应把 DOM/Computed Style/HAR 证据补进 `docs/evidence/legacy-/`,并把本文 §2 的“休眠”结论更新为实际观测。**在补齐前,不得声称旧 HEAD 页面与随包截图一致。** + +## 10. 审计结论摘要 + +1. 旧 Reader 的**视觉语言**(暖纸、衬线、金色点缀、樱花、羽毛、Dock、侧注曲线)值得延续;实现细节必须重写为单一主题。 +2. 旧 Reader 的**结构**是“基础壳 + 深色 Notebook 死层 + 后加载 Reader 皮肤”,并混有 Workbench/Debug 第二套模板 —— 全部禁止移植。 +3. 旧版**运行/导出安全模型**不满足 3.0 要求(导出可执行、Run API 无 CSRF),必须按 RFC §11 重新设计。 +4. 旧版**执行数据模型**(逐句值、内存快照、旧知识制品)与 Trace v2 不兼容,必须显式 `UNSUPPORTED`。 +5. 三个视觉资产(logo/blossom/feather)许可与哈希已核对,可复制进新仓库的 `assets/` 并由 `AssetBundle` 统一内嵌。 diff --git a/docs/design/state-matrix.md b/docs/design/state-matrix.md new file mode 100644 index 0000000..3c80092 --- /dev/null +++ b/docs/design/state-matrix.md @@ -0,0 +1,54 @@ +# 运行状态矩阵(PR-00 设计基准) + +> 状态:**设计基准**。实现真源:`src/presentation.rs` 的 `RunDisplayState` 与 `assets/reader.css` 的 `[data-run-state]`。 +> 来源:RFC-VIEW-0001 §4.4、§12.2–§12.3。 + +## 1. 静态来源状态(文档头部 `source_status`) + +| 值 | 触发条件 | 文档正文 | 语义标注 | 运行按钮 | 文案(中文) | +|---|---|---|---|---|---| +| `CORE_UNAVAILABLE` | 无 `MARQDO_BIN`/核心不可执行 | 完整可读 | 无(“语言语义未验证”) | 禁用 + 说明 | 找不到冻结核心,语义未验证 | +| `STATIC_OK` | `check` 退出 0 且 Analysis v2 校验通过 | 完整可读 | 有效 | 可用(需确认) | 静态检查已通过 · 未运行 | +| `CORE_ERROR` | `check` 退出非 0,但 Markdown 可读 | 完整可读 | 全部撤销,显示 Core diagnostics | 禁用 | Core 检查失败,语义标注不可用 | +| `STALE` | 源码变化或 Analysis digest 不匹配 | 完整可读 | 不绑定旧 Analysis | 可用(重新检查) | 分析已过期,请刷新 | +| `PROTOCOL_INCOMPATIBLE` | 未知 schema major / 产品版本不兼容 | 完整可读 | 无 | 禁用 | 核心协议不兼容(analysis vN) | +| `SOURCE_MISMATCH` | Analysis `source_digest` ≠ 当前字节 | 完整可读 | 不展示 | 禁用 | 源码与 Analysis 不一致 | + +## 2. 运行状态(`RunDisplayState`) + +| 值 | 触发条件 | 视觉 | 说明 | +|---|---|---|---| +| `NOT_RUN` | 未点击运行 | 中性 outline | “未运行”;不出现任何结果 | +| `STATIC_ONLY` | 只有 `check` 成功 | 中性 | “仅静态检查通过” | +| `RUNNING` | 用户已确认,Core 子进程运行中 | 金色脉冲(reduced-motion 时静态) | 显示入口/模式/预算,可取消(若实现) | +| `SUCCEEDED` | `run` 退出 0 + Trace v2 校验通过 | `--mq-ok` | 显示真实事件与 stdout;不显示返回值具体内容(除非公开 JSON 提供) | +| `FAILED` | `run` 退出非 0/运行错误码 | `--mq-error` | 显示 Core 错误码与 stderr 文本(转义) | +| `STALE` | Trace `source.analysis_digest` 与当前 Analysis 不符 | `--mq-warn` | “结果已过期”,不叠到当前正文 | +| `TRUNCATED` | `trace.truncated != null` | `--mq-warn` | “Trace 被截断,仅显示已记录事件” | +| `UNSUPPORTED` | 需要的字段/能力不在公开协议 | 中性 + 明确说明 | 绝不伪造:无变量值、无逐句赋值、无内存快照、无证明状态 | + +## 3. 事件 → UI 映射(保守) + +| Trace v2 事件 | 允许显示 | 禁止显示 | +|---|---|---| +| `call.enter` | 函数 id/名称、顺序、来源 span | 参数实际值 | +| `call.exit` | 退出类型/错误码 | 最终变量表 | +| `branch.eval` | 真/假 + 来源 span | “所有分支已覆盖” | +| `loop.iteration` | continue/exit 次数(以事件完整性为界) | 由静态结构推测总迭代数 | +| `return` | 发生返回 + 值类型名 | 具体返回值(除非公开 JSON 明确提供) | +| `effect` | operation、结果摘要、耗时 | “权限安全/已证明” | +| `trace.truncated` | 明确截断原因与上限 | 把缺失事件说成未执行 | +| 未知 kind | 忽略(记入 `ignored_event_kinds`) | 猜测语义 | + +## 4. 能力边界(首版硬性) + +| 旧 UI 能力 | 新 View 首版 | 理由 | +|---|---|---| +| 每个语句执行后的变量值 | **UNSUPPORTED** | Trace v2 不提供 | +| 参数实际值 / 内存快照 | **UNSUPPORTED** | Trace v2 不提供 | +| 知识“已证明” | **UNSUPPORTED** | 需要独立 Prove 协议与证书 | +| 调试断点/单步 | **不实现** | 首版非目标 | +| 函数大纲/签名 | 支持(来自 Analysis `functions[]`) | 公开静态事实 | +| 静态变量信息(params/赋值目标) | 支持但明确标注“静态” | 来自 Analysis,不冒充运行值 | +| 静态导入/引用标签 | 支持 | 来自 Analysis `imports[]`/`references[]` | +| 运行 Trace 事件侧注 | 支持 | Trace v2 + digest 校验 | diff --git a/docs/design/visual-tokens.md b/docs/design/visual-tokens.md new file mode 100644 index 0000000..bb9d3e2 --- /dev/null +++ b/docs/design/visual-tokens.md @@ -0,0 +1,85 @@ +# 视觉令牌与阅读布局(PR-00 设计基准) + +> 状态:**设计基准,实现以 `assets/reader.css` 的 `tokens` 层为唯一真源。** +> 来源:RFC-VIEW-0001 §2、`docs/design/reference-old-view-reader.png`、`docs/audits/legacy-render-paths.md` §6–§7。 +> 本文只描述“视觉语言”,不复制旧 CSS 原文;实现时任何数值以 CSS 为准,本文件与 CSS 冲突时以 CSS 为唯一实现真源并更新本文。 + +## 1. 色彩令牌 + +| Token | 值 | 用途 | +|---|---|---| +| `--mq-paper` | `#fcf9f5` | 页面底色(暖纸) | +| `--mq-surface` | `#fffcf8` | 浮起表面(Dock、代码围栏、弹层) | +| `--mq-surface-2` | `#f7f0e5` | 次级填充(标签、行内 code) | +| `--mq-ink` | `#29251f` | 正文墨色 | +| `--mq-strong` | `#1f1b16` | 标题/强调墨色 | +| `--mq-muted` | `#847565` | 次要文字、元信息 | +| `--mq-line` | `#e7ddce` | 轻分隔线 | +| `--mq-line-strong` | `#c9b79c` | 需要可见的边界 | +| `--mq-gold` | `#b88a45` | 黄金点缀:品牌、激活态、运行强调 | +| `--mq-gold-soft` | `#e8c78f` | 金色渐变高光 | +| `--mq-olive` | `#52603a` | 运行/知识侧注、次级语义色 | +| `--mq-ok` | `#52603a` | 运行成功 | +| `--mq-warn` | `#996b28` | 截断/待确认 | +| `--mq-error` | `#a63e30` | 运行失败/Core 错误 | +| `--mq-focus` | `#8a622e` | 键盘焦点环、激活 Tab 文字 | + +对比度要求:正文 `--mq-ink` on `--mq-paper` ≥ 10:1;`--mq-muted` 仅用于辅助信息且 ≥ 4.5:1 于 `--mq-paper`。状态色不单独承担语义,必须同时有文字标签(色盲可读)。 + +## 2. 字体令牌 + +```css +--mq-serif: "Iowan Old Style", "Palatino Linotype", "Noto Serif CJK SC", + "Source Han Serif SC", "Songti SC", SimSun, Georgia, serif; +--mq-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; +--mq-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", sans-serif; +``` + +- 只使用**本地系统栈**,禁止 CDN / `@font-face` 远程加载。 +- 正文 serif;UI 控件与状态标签 sans;代码/源码 mono。 +- 基准正文字号 18–19px,行高 1.72;`prefers-reduced-motion` 时禁用位移/缩放动画。 + +## 3. 布局令牌 + +| 维度 | 值/规则 | +|---|---| +| 阅读主栏 | `min(100% - 2*var(--mq-gutter), 820px)`;720–900px 区间内 | +| 页面外边距 | `--mq-gutter: clamp(20px, 5vw, 64px)` | +| 顶栏高度 | ~72px,品牌居中,左右各一个 icon 按钮 | +| 分段导航 | 居中、gap `clamp(20px, 5vw, 64px)`、金色 2px 下划线激活 | +| Hero(仅显式 Welcome) | 金色斜体 `Marqdo`,`clamp(56px, 9vw, 96px)`;羽毛右侧装饰 | +| 函数标题 | 34px/1.35 衬线 + 左侧 5px 金色斜竖线 | +| 侧注 | ≥1440px 可左右侧注(宽 170px);900–1439px 单侧或内联;≤899px 内联;≤600px 单栏 | +| Dock | `position: sticky` 底部居中胶囊;安全区 `env(safe-area-inset-bottom)`;不遮正文末段 | +| 内容节奏 | 段落间距 18px;标题上 32px/下 14px;不用重卡片堆砌 | + +## 4. 组件外观 + +- **顶栏**:透明纸底;品牌 `Marqdo` 32px 衬线 + 9px `EXECUTABLE KNOWLEDGE` 字距 3px;左右 icon 按钮 40px 圆形 hover 填充 `--mq-surface-2`。 +- **Dock**:胶囊(radius 999px)、`--mq-surface` 底、细 `--mq-line` 边、轻阴影;5 个按钮图标 + 小字标签;运行按钮金色实心。禁用按钮有 `aria-disabled` 与说明,不显示可点击空按钮。 +- **函数/知识标题**:Exec 标题左金斜线;Knowledge 标题前书卷图标(`aria-hidden`);标题旁 `EXEC`/`KNOWLEDGE` 小号大写标签;原文前缀在 Source 态完整保留。 +- **导入/引用标签**:椭圆 chip,`◇`/`⟶` 前缀,mono 12px。 +- **GFM 表**:横向可滚动容器;表头 `--mq-surface-2`;1px `--mq-line` 分隔。 +- **代码围栏**:`--mq-surface` 底、1px 边、圆角 10px;横向滚动;无行号(源码态除外)。 +- **公式**:首版以等宽/衬线文本呈现原文(`$...$` 与 `$$...$$`),标注“未渲染数学”;不引入 vendor。 +- **侧注**:正文右侧 170px;金色/橄榄 1px 贝塞尔曲线,起点为真实语义锚点;无来源不画线;拥挤时退化为内联 keyed 注释。 +- **装饰**:樱花 `blossom.webp` 左上、羽毛 `feather.webp` 仅 Welcome Hero;`aria-hidden="true"`;打印隐藏。 + +## 5. 状态视觉 + +见 `docs/design/state-matrix.md`。所有状态必须同时具备:文字标签 + 颜色 + `data-run-state` 属性;不得只靠颜色。 + +## 6. 响应式与无障碍 + +| 宽度 | 行为 | +|---|---| +| ≥1440px | 左右侧注区域可用,Dock 居中 | +| 900–1439px | 侧注收缩为单侧或内联 | +| ≤899px | 侧注全部内联于锚点下方 | +| ≤600px | 单栏;隐藏次级导航文字只留图标;Dock 不覆盖末尾(正文底部预留 Dock 高度) | +| 打印 | 隐藏顶栏/Dock/装饰/曲线,保留正文与内联注释;强制黑白友好对比 | + +- 键盘:Tab 顺序 = 顶栏 → 导航 → 正文链接/折叠 → Dock;Esc 关闭 dialog;焦点环 2px `--mq-gold` + 2px offset。 +- 无 JS:文档正文、标题、表格、链接、内联注释、源码态全部可读;执行控件退化为说明文字。 +- 屏幕阅读器:装饰 `aria-hidden`;侧注与锚点用 `aria-describedby`;状态 `role="status"` 播报。 +- `prefers-reduced-motion: reduce` 关闭侧注动画与 smooth scroll。