analysis: publish one schema for every project

This commit is contained in:
Codex committed 2026-11-24 14:16:56 +08:00
1 parent 8bd33a4615
commit 8bfe0c36ee
19 files changed
+93 -500

No files matched your search

-140
View File
@@ -1,140 +0,0 @@
# Marqdo Analysis v1
Status: **superseded by [Analysis v2](analysis-v2.md); never released, do not
write v1.** Kept as history. This was the M0.6 R4 read-only projection; it is
not a dump of `marqdo-ir`.
## 1. Invariants
`check --emit`:
* never executes the document, loads a plugin shared library, starts a foreign
kernel or imports a module implicitly;
* validates the loaded program first; on a compile error it writes no artifact
and removes a stale file at the target path;
* writes atomically (temporary file + rename) only after a successful check;
* is deterministic: the same source, tool version and project path produce
byte-identical JSON (no timestamps, no random ids);
* exposes no private Rust layout, optimization instruction or host pointer.
## 2. Top-level shape
```json
{
"schema": "marqdo.analysis",
"schema_version": 1,
"producer": {"name": "marqdo", "version": "0.1.0", "markdown_profile": "marqdo.md.v1"},
"project": {"root_id": "sha256:...", "lock_digest": "sha256:..."},
"modules": [],
"diagnostics": []
}
```
* `root_id` is a digest of the normalized project root used for this run.
* `lock_digest` is a digest of `marqdo.lock`, or `""` when absent.
* Modules are sorted by canonical `id`; arrays keep source order.
* `schema_version` is a major version. Additive optional fields are allowed;
removing/renaming fields or changing units/types requires a major bump.
## 3. Modules
```json
{
"id": "root:default::index.mq.md",
"package_instance_id": "root:default",
"relative_path": "index.mq.md",
"source_digest": "<sha256 hex>",
"units": [],
"functions": [],
"imports": [],
"references": [],
"calls": [],
"resources": 0
}
```
Module identity is the package-aware `ModuleId` from
`spec/references.md` §2.1. `source_digest` hashes the exact source bytes.
### 3.1 Units
Each unit has `id`, `kind` (`root`/`namespace`/`function`/`section`), `name`,
`level`, `span` (`{start,end}` byte offsets) and optionally `function`.
### 3.2 Functions and signatures
```json
{
"id": "root:default::index.mq.md::数学.阶乘",
"unit_id": "root:default::index.mq.md#数学/阶乘",
"local_name": "阶乘",
"namespace": "数学",
"span": {"start": 0, "end": 100},
"heading_span": {"start": 0, "end": 10},
"signature": {
"kind": "inferred",
"params": [{"name": "n", "required": true, "type": null, "default": null, "span": {"start": 0, "end": 0}}]
},
"effects": ["unknown"],
"body": []
}
```
`kind` is `explicit` or `inferred`. Inferred signatures only accept named
arguments. `effects` is a **conservative** summary; `unknown` is not a proof of
purity. Dynamic ABI/Foreign targets remain unknown unless a descriptor says
otherwise.
### 3.3 Normalized body nodes
Body nodes use a small stable language, never internal IR serialization:
* `literal` (`type`: `int`/`float`/`text`/`bool`/`none`, `value` when present);
* `variable`, `list`, `record`, `member`, `index`;
* `unary` (`not`/`neg`/`pos`) and `binary` (`or`, `and`, `eq`, `ne`, `lt`,
`le`, `gt`, `ge`, `add`, `sub`, `mul`, `div`, `floor_div`, `mod`, `pow`);
* `call` with `callee` and `args`;
* `assign`, `expression`, `call_site`, `branch` (ordered arms), `loop`,
`return`. (`call_site` existed for the pre-RFC link-form block-quote call and
is not produced by the current language; this document is historical.)
Every node carries a byte `span`. Nodes outside the supported public subset
must be marked `unsupported` (future extension), never silently given invented
semantics.
### 3.4 Imports, references and calls
* `imports[]`: `{alias, target, span, resolved}`; `resolved` is a module id or
null. Imports stay explicit.
* `references[]`: Markdown link edges with `{source, url, span, state,
target_module, target_unit}`. `state` is `resolved`, `unresolved` or
`external`; a failed resolution is never disguised as bound.
* `calls[]`: `{function, span, callee, state, target}` where `state` is
`function`, `builtin`, `plugin` or `unresolved`.
Reference edges never execute anything and grant no capability.
## 4. Diagnostics
`diagnostics[]` uses the same stable codes/JSON shape as `marqdo check --json`.
An analysis emitted after a successful check normally has no error diagnostics
(warnings may remain).
## 5. Consumer contract
An independent consumer (Python/Go/JavaScript, without linking Rust crates)
must be able to:
* find a function by `id` and read its signature/body;
* find recursive/forward calls and `ref` edges;
* map every body node back to `source_digest` + byte span;
* reject `schema_version` it does not understand.
`tests/consumers/analysis_consumer.py` is one such black-box consumer and
`crates/cli/tests/analysis_trace.rs` runs it when Python is available.
## 6. Not included
Internal optimization IR, host pointers, plugin handles, proof status and
execution results are deliberately absent. Analysis does not claim that a
document runs successfully or that any function is proved.
-27
View File
@@ -1,27 +0,0 @@
# Marqdo Analysis v3
Analysis v3 extends the public [Analysis v2](analysis-v2.md) contract with
structured loop control. Its envelope keeps `schema: "marqdo.analysis"` and
sets `schema_version: 3`. The writer emits v3 if any emitted function body
contains either new statement, including inside a nested body or an imported
module. Other projects still emit v2. Multi-arm branches fit both versions.
## Statement additions
```json
{"kind": "break", "span": {"start": 30, "end": 37}}
{"kind": "continue", "span": {"start": 39, "end": 49}}
```
Both spans are half-open UTF-8 byte ranges covering the carrier in the
containing module. Walk the enclosing statement bodies to find the nearest
loop. `break` transfers to the statement after that loop. `continue`
transfers to its condition. There are no operands, labels or call edges.
Call and resource projections retain their v2 shapes.
Consumers check the major version before traversing any function body. A v2
reader rejects v3, while a reader that accepts both versions can share its
v2 decoding and add two statement kinds. Trace v2 binds to the version
automatically emitted for the same input via `source.analysis_digest`.
JSON Schema: [analysis-v3.schema.json](schemas/analysis-v3.schema.json).
+21 -46
View File
@@ -1,8 +1,7 @@
# Marqdo Analysis v2
# Marqdo Analysis
Status: **implemented by `marqdo check --emit <path>` (S2); ADR-0022 adds an
additive index target shape.** Supersedes
Analysis v1. v1 was never released; it is kept as history and is not written.
Current public contract for `marqdo check --emit PATH`. Every project emits
`marqdo.analysis` with `schema_version: 3`.
## 1. Invariants
@@ -22,7 +21,7 @@ Analysis v1. v1 was never released; it is kept as history and is not written.
```json
{
"schema": "marqdo.analysis",
"schema_version": 2,
"schema_version": 3,
"producer": {
"name": "marqdo",
"version": "<crate version>",
@@ -99,7 +98,7 @@ conservative summary, not a purity proof).
(`spec/callable-resolution.md` §6): `state` remains
`function`/`builtin`/`plugin`/`unresolved`, and official stdlib aliases such as
`打印` are reported as `function` targets because that is the implementation
that runs. The private `CallBindingTable` is not serialized; Analysis v2's
that runs. The private `CallBindingTable` is not serialized; Analysis's
schema and version are unchanged.
An `assign` node keeps the v1 string `target` for a local rebinding. Addressable
@@ -181,48 +180,24 @@ location exists.
The `code` value is an open, stable string: the current language revision adds
the `sem.*` family (`spec/mapping.md` §8) and removes the old
`markdown.inert_executable` warning. This is a diagnostic-value change, not an
Analysis schema change; `schema_version` stays 2.
`markdown.inert_executable` warning. Diagnostic codes may be added without changing the structure.
## 6. Compatibility
## 6. Loop transfers
* Writers emit `schema_version: 2`. There is no v1 writer and no
`--emit-version` flag; v1 was experimental.
* Consumers must reject unknown `schema_version` values and unknown resource
kinds rather than silently accepting them.
* Changing `root_id`, resource fields, diagnostic fields or the digest
definition is a protocol break requiring a new version and an ADR.
* JSON Schema: `spec/schemas/analysis-v2.schema.json` (Draft 2020-12).
Schema validation is structural; cross-record checks (span inside source,
call targets, digest verification) remain semantic tests.
Conditional arms appear in source order. Both `break` and `continue` are
statements with a `kind` and the half-open UTF-8 `span` of their carrier.
They have no operands or call edges. Walk the enclosing bodies to find
the nearest loop. `break` transfers past that loop and `continue` transfers
to its condition.
## 7. Tests
## 7. Validation
* `analysis_is_deterministic_and_has_stable_semantic_nodes`
* `analysis_v2_identity_is_location_independent`
* `analysis_v2_projects_addressable_formula_and_code_resources`
* `failed_check_removes_stale_analysis`
* `tests/consumers/analysis_consumer.py` (independent Python consumer)
Require exactly `schema: "marqdo.analysis"` and `schema_version: 3` before
traversing the document. The [JSON Schema](schemas/analysis.schema.json)
validates record shapes. Check source digests, spans, ownership and
reference targets separately. Its full branch and loop structure applies
equally to simple projects and imported modules.
## 8. Versioning and future heading metadata
`units[]` keeps its v2 fields and semantics: `id/kind/name/level/span/function`.
The effective core mode and origin of a `section` unit are deliberately **not**
added to v2, and neither are heading annotations.
The language still has exactly two Core Modes (`@exec`/`@knowledge`); unmarked
headings inherit from the nearest ancestor and the root default is Knowledge
(`spec/mapping.md` §1.2, including the H-06 sibling fix). A future declarative,
metadata-only Heading Annotation index is Proposed under
[ADR-0060](../docs/adr/0060-heading-modes-and-extensible-annotations.md) and is
**not implemented in this build**.
When that work ships (target `3.1.x`), it must use a new protocol version
(Analysis v3) or a separate `heading-annotations.v1` sidecar, bound to both the
source digest and the exact Analysis bytes digest; it must not rewrite v2 `units[]`.
Consumers that only know v2 must keep passing the existing schema/version contract,
and must reject an unknown sidecar/v3 version rather than silently ignoring it.
Projects containing structured loop transfers use [Analysis v3](analysis-v3.md).
A v2 projection never contains those transfer statements. Multiple conditional
arms use the existing ordered `branch.arms` array.
Source digests cover the original bytes. Preserve UTF-8 byte offsets for
BOM, CRLF, CJK and emoji. Observation binds to the SHA-256 of the exact
emitted Analysis JSON bytes.
-52
View File
@@ -1,52 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/analysis-v1.schema.json",
"title": "Marqdo Analysis v1",
"type": "object",
"required": ["schema", "schema_version", "producer", "project", "modules", "diagnostics"],
"properties": {
"schema": {"const": "marqdo.analysis"},
"schema_version": {"const": 1},
"producer": {
"type": "object",
"required": ["name", "version", "markdown_profile"],
"properties": {
"name": {"type": "string"},
"version": {"type": "string"},
"markdown_profile": {"const": "marqdo.md.v1"}
},
"additionalProperties": true
},
"project": {
"type": "object",
"required": ["root_id", "lock_digest"],
"properties": {
"root_id": {"type": "string"},
"lock_digest": {"type": "string"}
},
"additionalProperties": true
},
"modules": {
"type": "array",
"items": {
"type": "object",
"required": ["id", "package_instance_id", "relative_path", "source_digest", "units", "functions", "imports", "references", "calls"],
"properties": {
"id": {"type": "string", "pattern": "::"},
"package_instance_id": {"type": "string"},
"relative_path": {"type": "string"},
"source_digest": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
"units": {"type": "array"},
"functions": {"type": "array"},
"imports": {"type": "array"},
"references": {"type": "array"},
"calls": {"type": "array"},
"resources": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
}
},
"diagnostics": {"type": "array"}
},
"additionalProperties": true
}
-103
View File
@@ -1,103 +0,0 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/analysis-v2.schema.json",
"title": "Marqdo Analysis v2",
"type": "object",
"required": ["schema", "schema_version", "producer", "project", "modules", "diagnostics"],
"properties": {
"schema": {"const": "marqdo.analysis"},
"schema_version": {"const": 2},
"producer": {
"type": "object",
"required": ["name", "version", "markdown_profile"],
"properties": {
"name": {"type": "string"},
"version": {"type": "string"},
"markdown_profile": {"const": "marqdo.md.v1"}
},
"additionalProperties": true
},
"project": {
"type": "object",
"required": ["root_id", "identity_kind", "lock_digest"],
"properties": {
"root_id": {"type": "string", "minLength": 1, "pattern": "^(root:|sha256:[0-9a-f]{64}$)"},
"identity_kind": {"enum": ["manifest", "workspace_snapshot"]},
"lock_digest": {"type": "string", "pattern": "^(sha256:[0-9a-f]{64})?$"}
},
"additionalProperties": true
},
"modules": {
"type": "array",
"items": {
"type": "object",
"required": ["id", "package_instance_id", "relative_path", "source_digest", "units", "functions", "imports", "references", "calls", "resources"],
"properties": {
"id": {"type": "string", "pattern": "::"},
"package_instance_id": {"type": "string", "minLength": 1},
"relative_path": {"type": "string", "minLength": 1, "pattern": "^(?!/)(?!.*\\.\\.)"},
"source_digest": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
"units": {"type": "array"},
"functions": {"type": "array"},
"imports": {"type": "array"},
"references": {"type": "array"},
"calls": {"type": "array"},
"resources": {
"type": "array",
"items": {
"type": "object",
"required": ["id", "module_id", "unit_id", "kind", "span", "content_digest"],
"properties": {
"id": {"type": "string", "pattern": "#resource:(formula|code)-[0-9]+$"},
"module_id": {"type": "string", "pattern": "::"},
"unit_id": {"type": "string", "minLength": 1},
"kind": {"enum": ["formula", "code"]},
"span": {
"type": "object",
"required": ["start", "end"],
"properties": {
"start": {"type": "integer", "minimum": 0},
"end": {"type": "integer", "minimum": 0}
},
"additionalProperties": true
},
"content_digest": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
"language": {"type": ["string", "null"]},
"display": {"type": "boolean"}
},
"additionalProperties": true
}
}
},
"additionalProperties": true
}
},
"diagnostics": {
"type": "array",
"items": {
"type": "object",
"required": ["module", "relative_path", "severity", "code", "message"],
"properties": {
"module": {"type": "string", "pattern": "::"},
"relative_path": {"type": "string", "minLength": 1},
"span": {
"type": ["object", "null"],
"required": ["start", "end"],
"properties": {
"start": {"type": "integer", "minimum": 0},
"end": {"type": "integer", "minimum": 0}
}
},
"line": {"type": ["integer", "null"], "minimum": 1},
"column": {"type": ["integer", "null"], "minimum": 1},
"severity": {"enum": ["error", "warning"]},
"code": {"type": "string", "minLength": 1},
"message": {"type": "string", "minLength": 1},
"hints": {"type": "array", "items": {"type": "string"}}
},
"additionalProperties": true
}
}
},
"additionalProperties": true
}
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/analysis-v3.schema.json",
"title": "Marqdo Analysis v3",
"$id": "https://marqdo.dev/schemas/analysis.schema.json",
"title": "Marqdo Analysis",
"type": "object",
"required": [
"schema",