diff --git a/docs/MARQDO_3_0_PRERELEASE_PLAN.md b/docs/MARQDO_3_0_PRERELEASE_PLAN.md index 8833151..2d54728 100644 --- a/docs/MARQDO_3_0_PRERELEASE_PLAN.md +++ b/docs/MARQDO_3_0_PRERELEASE_PLAN.md @@ -38,7 +38,7 @@ 3. 冻结 CLI 的外部仓库黑盒验收在**发布 SHA**重新执行,至少 pure pinned-Git 包、Callable Worker、陌生 Foreign Kernel、Provider v2、Tool/Analysis/Trace、权限负例及工件改动负例全部 PASS;生成并校验 `docs/evidence/extension//manifest.json`。 4. 冷安装、离线 `--version`/`--help`、`check/run/call`、lock/sync、Tool 安装与分发、Provider Worker 启动、错 SHA/错目标/未授权拒绝全部由发布归档中的**实际二进制**完成;不得依赖开发源码目录。 5. **不得虚假宣传安全隔离。** 发布包若保留并开放 Linux `strict`,必须有该 SHA 的真实 G3 隔离负例证据;若暂无证据,需采用明确经过测试的 fail-closed 禁用方式并在公告中写 `strict: unsupported`。不允许仅改 README 却继续将未验证的 `strict` 描述为安全保障。Beta 的这一策略必须经维护者明确签字并由 CI 可复查。 -6. G4 基准不得造假;若当期固定节点仍是 WARN,可由维护者批准 **Beta-only WARN** 并公开环境和限制;必须通过 9 个正确性基准,不允许数值漂移或已确认的灾难性回退。 +6. G4 基准不得造假;若当期固定节点仍是 WARN,可由维护者批准 **Beta/RC-only WARN** 并公开环境和限制;必须通过正确性基准,不允许数值漂移或已确认的灾难性回退。RC 允许经维护者批准的共享节点 WARN;最终 stable/LTS 必须使用专用固定节点,该共享节点例外不延续到 LTS。 7. 明确产品版本 `3.0.0-beta.1` 与协议独立版本;工具 SemVer 协商在真实测试版上可安装、拒绝不兼容范围、不会误把 `<1` 当成支持 3.x。 8. `README`、`CHANGELOG`、`COMPATIBILITY`、`docs/STATUS`、`docs/releasing`、协议入口页、迁移说明,均更新至同一事实基线;无“未实现却声称已发布”或“已实现仍称 Proposed”的矛盾。 9. 不发布未经实际构建/烟测的平台二进制;产物附 SHA256、SOURCE_SHA、构建工具链信息和已知限制。 diff --git a/docs/developers/analysis-consumers.md b/docs/developers/analysis-consumers.md new file mode 100644 index 0000000..47820f0 --- /dev/null +++ b/docs/developers/analysis-consumers.md @@ -0,0 +1,255 @@ +# Public Analysis consumers after issue #10 + +Applies to `marqdo.analysis` revision 3 as defined by +[ADR-0069](../adr/0069-public-analysis-boundary.md), [spec/analysis.md](../../spec/analysis.md) +and [the schema](../../spec/schemas/analysis.schema.json). This page is the +integration guide for downstream static tools, in particular `marqdo-lint` and +`marqdo-view`. + +The revision number did not change, but the shape did. An old revision-3 +artifact is **not** accepted: current required fields are missing, and the +current schema and consumer semantics reject it. Rebuild the artifact and +update the consumer; do not add a compatibility reader or a second Analysis +shape. + +## 1. What the CLI already provides + +Run one command per program entry: + +```sh +marqdo check path/to/index.mq.md --emit analysis.json +``` + +The artifact contains everything a document/lint/knowledge reader needs, from +the same static preparation as `check`, `inspect`, `run` and `call`: + +- exact UTF-8 `modules[].source` and its SHA-256 `source_digest`; +- the Markdown AST in `modules[].document`; +- heading scopes in `modules[].units` and anchors in `modules[].anchors`; +- functions, imports, calls and resources; +- Markdown references with explicit resolution states; +- project context: `entry_module_id`, `identity_kind`, `root_id`, + `manifest_digest`, captured `lock_digest`, stdlib and extension identities; +- deterministic diagnostics. + +`inspect --ast` and `inspect --units` now project the **same** AST and unit +shape. They remain human/debug selections; a machine consumer should read +`check --emit` and stop running a second `inspect --ast` process per module. + +## 2. Required consumer changes + +### 2.1 Read the source from the artifact + +`modules[].source` is the exact text the loader read. Every span is a half-open +UTF-8 byte offset into that string. + +- Do not reopen the file from `relative_path` for spans or digests; package + caches, stdlib and dependencies have no stable consumer-facing physical path. +- Verify `sha256(source.encode("utf-8")) == source_digest` before trusting a + span. +- `relative_path` remains package-relative and useful for display and project + layout, not for reconstructing an absolute path. + +### 2.2 Document AST + +`modules[].document` is the public AST described by +[`spec/markdown-profile.md`](../../spec/markdown-profile.md). Every node has +`kind`, `span` and `children` (`[]` for leaves); attributes/literals follow the +profile. The root `document` span now covers the whole source, including a BOM. + +- Parse `document` directly; do not parse Markdown again for program + annotations. +- Renderers may keep their own rendering parser, but any *semantic* decision + (executable region, heading scope, function ownership) must use Analysis. +- Literal payloads are not guaranteed byte-equal to their span (entities, + escapes and code whitespace are normalised). + +### 2.3 Heading scope: `span` changed meaning + +For every non-root unit: + +| Field | Meaning | +|---|---| +| `heading_span` | The original heading AST node span. Use this to locate the heading itself. | +| `span` | **Complete section range** from the heading through the next heading of the same or higher level, or EOF. It includes child headings. | +| `path` | Canonical structured heading path. Do not split `id` to recover it. | +| `parent_id` | Nearest real ancestor unit; root is `null`. | +| `mode` | Effective `exec` or `knowledge`. | +| `mode_origin` | `explicit` (ATX declaration), `inherited`, or `default` for the root. | +| `mode_source_unit_id` | The unit that supplied the mode; self-or-ancestor. | +| `kind` | `root`, `namespace`, `function`, `knowledge`, `section`. | +| `function` | Owning function id for Exec sections; `null` otherwise. | + +Do not infer section ends from the next heading's text or from the old +short-span assumption. Use `heading_span` for heading UI; use `span` for the +whole section body. + +`anchors` is `[{anchor, unit_id}]`, sorted by anchor. Anchors are navigation +names, not identities; a missing anchor is not a missing document. + +### 2.4 References: boolean `resolved` is gone + +`modules[].references[]` now always carries: + +```json +{ + "source": "root:x@0.1.0::index.mq.md", + "source_unit": "root:x@0.1.0::index.mq.md#数学", + "url": "./theory.mq.md#formula", + "span": {"start": 20, "end": 50}, + "state": "not_loaded", + "target_kind": null, + "target_module": null, + "target_unit": null, + "candidate_package_instance_id": "root:x@0.1.0", + "candidate_path": "theory.mq.md", + "fragment": "formula", + "candidates": [] +} +``` + +| `state` | Consumer meaning | +|---|---| +| `resolved` | Exact module/unit or explicitly verified local file. `target_kind` is `module` or `file`. | +| `not_loaded` | The loaded catalog did not cover the local candidate. It is **not** missing; do not auto-create it. | +| `missing` | A known catalog module lacks the fragment, or explicit `--refs` verification proved absence. | +| `ambiguous` | Multiple exact canonical-name candidates; `target_unit` is null and `candidates` lists them. Never choose the first. | +| `external` | External URI scheme. No network access; not an error. | +| `outside_scope` | Absolute/drive/UNC/file URI, or a package-root escape. Never read it. | +| `invalid` | Malformed URI/percent encoding/unsupported address. | + +Ordinary Analysis resolves only the loaded program. If a consumer needs to +verify unimported local files, use the CLI's explicit check: + +```sh +marqdo check entry.mq.md --refs --json +marqdo inspect entry.mq.md --refs --json +``` + +Do not use the `--refs` artifact as the Observation binding input: `--refs` +adds diagnostics and changes the exact bytes. Run/call bind to the ordinary +`check --emit` bytes with the same static options. + +### 2.5 Calls, functions and resources + +- `functions[]` still has `id`, `unit_id`, `local_name`, `namespace`, `span`, + `heading_span`, `signature`, `effects`, `body`. +- `calls[]` now has `target_kind`, `target_owner` and `reason`. A plugin target + names the static owner (package/digest); it is never a Marqdo function. + `unresolved` with `reason: dynamic|unbound` is honest, not an error. +- `resources[]` carries `display: null` for code and a boolean for formulas; + verify its `content_digest` against the AST payload if you need integrity. +- The schema is closed: unknown required kinds/fields must be rejected, not + ignored. + +### 2.6 Project context and freshness + +- Load `project.entry_module_id`; it must occur once in `modules`. +- `root_id` is a logical manifest identity or a content snapshot, not a + cross-project permanent id. +- `manifest_digest` and `lock_digest` are the captured bytes; a changed file on + disk means a new check, not a retry of the old artifact. +- Verify the exact bytes with the published JSON Schema + semantic checks; keep + rejecting stale artifacts whose `source_digest` no longer matches the source + you display. + +## 3. `marqdo-view` integration + +Current View behavior to replace: + +1. It runs `check --json --emit` and separately calls `inspect --ast --json` + per document. Replace the machine path with one `check --emit`; the AST is + `modules[].document`. Keep `inspect` only for human debug output. +2. It re-reads files and compares `source_digest`. Prefer `modules[].source` + directly; if it must use its own file snapshot, compare the artifact digest + and reject a mismatch. +3. Its `RawProject` ignores new required fields. Make + `entry_module_id`, `manifest_digest` and `extensions` required (or validate + with the schema) and remove the v2 acceptance branch. View must accept only + the current revision-3 shape. +4. `RawUnit.span` now means the complete section. For annotation placement use + `heading_span`; for source highlighting use the complete `span`. +5. `RawReference` already reads `state`; remove any remaining `resolved` + boolean mapping and map `not_loaded` as *unverified*, not as a broken link. + For a local candidate the View catalog does not know, show "未加载/未核验"; + only `missing`/`ambiguous`/`invalid`/`outside_scope` are actionable errors. +6. Keep validating `source.analysis_digest` for Observation binding. The digest + remains SHA-256 of the exact `--emit` bytes; `--refs` diagnostics change it. + +Suggested request/render flow: + +```text +check --emit -> verify schema + source_digest -> document AST + -> units (complete span + heading_span) for annotations + -> references (state) for link presentation + -> calls/functions for executable markers +run/call + observation -> verify analysis_digest == sha256(artifact bytes) +``` + +## 4. `marqdo-lint` integration + +Current Lint behavior to replace: + +1. It performs one `inspect --ast` per module and then matches it with + Analysis. Use `modules[].source` and `modules[].document` from the same + `check --emit`; this removes a second process and any AST/span drift. +2. Its `AnalysisModule` model only requires the old fields and silently ignores + the new ones. Make `source`, `document`, `anchors` and the new unit fields + required; reject old same-revision artifacts. Prefer generating types from + the published schema rather than `Vec` for units/references. +3. Heading-boundary rules must use `units[].span` as the complete section and + `heading_span` as the heading itself. This is the authoritative range; do + not infer boundaries from Markdown siblings. +4. Link/reference lint: iterate `references[].state`. Report: + - `missing`/`ambiguous`/`invalid`/`outside_scope` as errors with + `source_unit` + `span`; + - `not_loaded` as an honest "unverified" notice, not a broken reference; + - `external` as informational. + Use the explicit `check --refs --json` run only when the user asks to verify + direct unimported targets. +5. `calls[]` can report static call targets and dynamic/unbound reasons; do not + infer a target from the display string. Plugin/builtin targets are not + Marqdo functions. +6. Continue using `--json` for diagnostic summaries; `--emit` is the only full + Analysis producer. + +Suggested lint flow: + +```text +check --emit -> verify schema + semantic invariants + -> per module: document + units(full span/heading_span) + -> rules: narrative/executable boundaries, calls, links, docs + -> diagnostics projected from Analysis + local rules +``` + +## 5. Shared rules for both consumers + +- One current contract. Do not add a v2/v3 reader, field probing, fallback AST + from a second parser, or `try old shape then new shape`. +- Reject malformed/old artifacts with a corrective message: regenerate with the + current CLI, reinstall the Tool manifest, rebuild the consumer. +- Tool manifests keep `requires.analysis: 3`; the revision is unchanged, so + reinstall/rebuild is required because the old same-revision bytes are + rejected by the current schema. +- No private Rust crate, no `inspect --ir`, no package-cache path, no writing + to the analyzed project. +- The source in Analysis may contain secrets from the document. Do not log or + upload it by default; store artifacts with owner-only permissions. +- Keep the three independent fixture flows green: document rendering, lint with + diagnostics, and multi-entry knowledge linking. + +## 6. Verification commands + +On the current CLI: + +```sh +marqdo check entry.mq.md --emit analysis.json +python3 tests/consumers/validate_protocols.py analysis.json observation.json tool.json +python3 tests/consumers/analysis_consumer.py analysis.json +marqdo inspect entry.mq.md --refs --json +``` + +For a downstream checkout, pin the CLI archive and run its real fixtures +against `MARQDO_BIN`; record the CLI SHA and the Analysis schema hash in the +consumer's evidence. See the issue accompanying this document for the exact +downstream acceptance items. diff --git a/docs/performance.md b/docs/performance.md index 65aa9d5..79f0265 100644 --- a/docs/performance.md +++ b/docs/performance.md @@ -4,6 +4,15 @@ Status: the sampler and correctness corpus are implemented; **no release performance baseline exists yet**. Do not cite a development-container or TCG/QEMU number as a release gate. +## Release-class policy + +- **RC candidates** may use a maintainer-approved shared node. The environment, + load, limits, paired baseline/candidate comparison and approval are recorded + in the release notes; the result remains `WARN`, never a dedicated-node PASS. +- **Stable/LTS** releases require a dedicated fixed node and the full paired-run + protocol. The shared-node exception is RC-only and must not be reused for + LTS evidence. + ## Three separate measurements | Class | Goal | Host | diff --git a/docs/releasing.md b/docs/releasing.md index efb57f3..60e8d6a 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -75,17 +75,19 @@ Use the frozen-SHA build and archive checks above. Additionally: - Strict L1 requires a same-SHA PASS on a disposable VM as a non-root user. Record the strict evidence and verify the archived binary on that guest. -- Measure the packaged CLI on a dedicated fixed node with 5 warmups and - 20 samples or more for each of the nine workloads. Compare against a - correctness-verified baseline on the same node, CPU affinity, governor, - kernel and toolchain. Record investigation and resolution for any p50 - increase of at least 15% or median peak RSS increase of at least 20%. - A dedicated node is the default. For a prerelease approved by the - maintainer to use a shared node, take at least three paired beta/RC runs - under the same measured conditions and keep all reports. Verify all nine - workloads and investigate threshold breaches or unstable samples before - accepting a `WARN`. Record the approval, runner environment and limits in - the release notes. This exception applies to the named RC only. +- Measure the packaged CLI with 5 warmups and 20 samples or more for each of + the nine workloads, or for the changed boundary's representative fixture when + the gate is scoped by an accepted ADR. Compare against a correctness-verified + baseline on the same node, CPU affinity, governor, kernel and toolchain. + Record investigation and resolution for any p50 increase of at least 15% or + median peak RSS increase of at least 20%. + **RC candidates may use a shared node.** The maintainer approves the shared + node for that named RC, the environment/load/limits and the comparison are + recorded in the release notes, and the result stays a `WARN`; it is never + promoted to a dedicated-node PASS. A final stable/LTS release requires a + dedicated fixed node with the full paired-run protocol; the shared-node + exception does not carry over to it. Verify correctness before timing and do + not accept results from an unmeasured or unexplained environment. - Version compatibility covers the locked Rust minimum, CLI and Analysis product identity, Tool/project prerelease ranges, and beta migration. - Use Ubuntu 24.04 (glibc 2.39) for the independent archive-only runtime