Files
marqdo-cli/spec/schemas/analysis.schema.json
T
cflmy 88d7cd3414 docs: define the closed public Analysis boundary
Add ADR-0069 and replace the program-only Analysis v3 shape in place with the
one public projection consumed by independent static tools: project entry and
snapshot identity, exact source, document AST, heading scope facts, anchors,
functions, calls, resources and stateful references. Update the Markdown
profile, reference and observation specs to point at the single resolver and
the same encoder/digest rule.
2026-11-25 09:39:26 +08:00

716 lines
25 KiB
JSON

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://marqdo.dev/schemas/analysis.schema.json",
"title": "Marqdo Analysis",
"type": "object",
"additionalProperties": false,
"required": [
"schema",
"schema_version",
"producer",
"project",
"modules",
"diagnostics"
],
"properties": {
"schema": {"const": "marqdo.analysis"},
"schema_version": {"const": 3},
"producer": {"$ref": "#/$defs/producer"},
"project": {"$ref": "#/$defs/project"},
"modules": {
"type": "array",
"items": {"$ref": "#/$defs/module"}
},
"diagnostics": {
"type": "array",
"items": {"$ref": "#/$defs/diagnostic"}
}
},
"$defs": {
"span": {
"type": "object",
"additionalProperties": false,
"required": ["start", "end"],
"properties": {
"start": {"type": "integer", "minimum": 0},
"end": {"type": "integer", "minimum": 0}
}
},
"producer": {
"type": "object",
"additionalProperties": false,
"required": ["name", "version", "markdown_profile"],
"properties": {
"name": {"const": "marqdo"},
"version": {"type": "string", "minLength": 1},
"markdown_profile": {"const": "marqdo.md.v1"}
}
},
"project": {
"type": "object",
"additionalProperties": false,
"required": [
"root_id",
"identity_kind",
"entry_module_id",
"lock_digest",
"manifest_digest",
"stdlib",
"extensions"
],
"properties": {
"root_id": {
"type": "string",
"pattern": "^(root:[A-Za-z0-9_.@+/-]+|sha256:[0-9a-f]{64})$"
},
"identity_kind": {"enum": ["manifest", "workspace_snapshot"]},
"entry_module_id": {"type": "string", "minLength": 1},
"lock_digest": {
"type": "string",
"pattern": "^(sha256:[0-9a-f]{64})?$"
},
"manifest_digest": {
"type": "string",
"pattern": "^(sha256:[0-9a-f]{64})?$"
},
"stdlib": {
"type": ["object", "null"],
"additionalProperties": false,
"required": ["version", "digest", "instance_id"],
"properties": {
"version": {"type": "string", "minLength": 1},
"digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"},
"instance_id": {"type": "string", "minLength": 1}
}
},
"extensions": {
"type": "array",
"items": {"$ref": "#/$defs/extension"}
}
}
},
"extension": {
"type": "object",
"additionalProperties": false,
"required": [
"kind",
"name",
"version",
"logical_owner",
"source",
"manifest_digest",
"artifact_digest",
"selected_target"
],
"properties": {
"kind": {"enum": ["plugin", "kernel", "provider"]},
"name": {"type": "string", "minLength": 1},
"version": {"type": "string", "minLength": 1},
"logical_owner": {"type": "string", "minLength": 1},
"source": {"type": "string", "minLength": 1},
"manifest_digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"},
"artifact_digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"},
"selected_target": {"type": "string", "minLength": 1}
}
},
"module": {
"type": "object",
"additionalProperties": false,
"required": [
"id",
"package_instance_id",
"relative_path",
"source_digest",
"source",
"document",
"units",
"anchors",
"functions",
"imports",
"references",
"calls",
"resources"
],
"properties": {
"id": {"type": "string", "pattern": "::"},
"package_instance_id": {"type": "string", "minLength": 1},
"relative_path": {
"type": "string",
"minLength": 1,
"pattern": "^(?!/)(?!.*::)(?!.*(^|/)\\.\\.?(/|$))(?![A-Za-z]:)(?!.*\\\\)(?!.*//).*$"
},
"source_digest": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
"source": {"type": "string"},
"document": {"$ref": "#/$defs/node"},
"units": {"type": "array", "items": {"$ref": "#/$defs/unit"}},
"anchors": {"type": "array", "items": {"$ref": "#/$defs/anchor"}},
"functions": {"type": "array", "items": {"$ref": "#/$defs/function"}},
"imports": {"type": "array", "items": {"$ref": "#/$defs/import"}},
"references": {"type": "array", "items": {"$ref": "#/$defs/reference"}},
"calls": {"type": "array", "items": {"$ref": "#/$defs/call"}},
"resources": {"type": "array", "items": {"$ref": "#/$defs/resource"}}
}
},
"node": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "span", "children"],
"properties": {
"kind": {
"enum": [
"document", "front_matter", "block_quote", "list", "item",
"heading", "paragraph", "text", "strong", "emph", "strikethrough",
"code", "code_block", "math", "math_block", "link", "image",
"table", "table_row", "table_cell", "thematic_break",
"soft_break", "line_break", "html_block", "html_inline", "other"
]
},
"span": {"$ref": "#/$defs/span"},
"children": {"type": "array", "items": {"$ref": "#/$defs/node"}},
"literal": {"type": "string"},
"tag": {"type": "string", "minLength": 1},
"level": {"type": "integer", "minimum": 1, "maximum": 6},
"setext": {"type": "boolean"},
"ordered": {"type": "boolean"},
"start": {"type": ["integer", "null"], "minimum": 0},
"tight": {"type": "boolean"},
"task": {"type": ["boolean", "null"]},
"ticks": {"type": "integer", "minimum": 1},
"fenced": {"type": "boolean"},
"info": {"type": "string"},
"display": {"type": "boolean"},
"url": {"type": "string"},
"title": {"type": "string"},
"alignments": {
"type": "array",
"items": {"enum": ["none", "left", "center", "right"]}
},
"header": {"type": "boolean"}
},
"allOf": [
{"if": {"properties": {"kind": {"const": "front_matter"}}},
"then": {"required": ["literal"], "properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "text"}}},
"then": {"required": ["literal"], "properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "code"}}},
"then": {"required": ["literal", "ticks"], "properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "code_block"}}},
"then": {"required": ["literal", "fenced", "info"], "properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "math"}}},
"then": {"required": ["literal", "display"], "properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "math_block"}}},
"then": {"required": ["literal"], "properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "html_block"}}},
"then": {"required": ["literal"], "properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "html_inline"}}},
"then": {"required": ["literal"], "properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "thematic_break"}}},
"then": {"properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "soft_break"}}},
"then": {"properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "line_break"}}},
"then": {"properties": {"children": {"maxItems": 0}}}},
{"if": {"properties": {"kind": {"const": "heading"}}},
"then": {"required": ["level", "setext"]}},
{"if": {"properties": {"kind": {"const": "list"}}},
"then": {"required": ["ordered", "start", "tight"]}},
{"if": {"properties": {"kind": {"const": "item"}}},
"then": {"required": ["task"]}},
{"if": {"properties": {"kind": {"const": "link"}}},
"then": {"required": ["url", "title"]}},
{"if": {"properties": {"kind": {"const": "image"}}},
"then": {"required": ["url", "title"]}},
{"if": {"properties": {"kind": {"const": "table"}}},
"then": {"required": ["alignments"]}},
{"if": {"properties": {"kind": {"const": "table_row"}}},
"then": {"required": ["header"]}},
{"if": {"properties": {"kind": {"const": "other"}}},
"then": {"required": ["tag"]}}
]
},
"unit": {
"type": "object",
"additionalProperties": false,
"required": [
"id", "path", "parent_id", "kind", "name", "level", "mode",
"mode_origin", "mode_source_unit_id", "heading_span", "span", "function"
],
"properties": {
"id": {"type": "string", "minLength": 1},
"path": {
"type": "array",
"items": {"type": "string", "minLength": 1}
},
"parent_id": {"type": ["string", "null"]},
"kind": {"enum": ["root", "namespace", "function", "knowledge", "section"]},
"name": {"type": "string"},
"level": {"type": "integer", "minimum": 0, "maximum": 6},
"mode": {"enum": ["exec", "knowledge"]},
"mode_origin": {"enum": ["default", "explicit", "inherited"]},
"mode_source_unit_id": {"type": "string", "minLength": 1},
"heading_span": {"oneOf": [{"$ref": "#/$defs/span"}, {"type": "null"}]},
"span": {"$ref": "#/$defs/span"},
"function": {"type": ["string", "null"]}
}
},
"anchor": {
"type": "object",
"additionalProperties": false,
"required": ["anchor", "unit_id"],
"properties": {
"anchor": {"type": "string", "minLength": 1},
"unit_id": {"type": "string", "minLength": 1}
}
},
"function": {
"type": "object",
"additionalProperties": false,
"required": [
"id", "unit_id", "local_name", "namespace", "span", "heading_span",
"signature", "effects", "body"
],
"properties": {
"id": {"type": "string", "minLength": 1},
"unit_id": {"type": "string", "minLength": 1},
"local_name": {"type": "string", "minLength": 1},
"namespace": {"type": ["string", "null"]},
"span": {"$ref": "#/$defs/span"},
"heading_span": {"$ref": "#/$defs/span"},
"signature": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "params"],
"properties": {
"kind": {"enum": ["explicit", "inferred"]},
"params": {"type": "array", "items": {"$ref": "#/$defs/param"}}
}
},
"effects": {
"type": "array",
"items": {"enum": ["unknown"]}
},
"body": {"type": "array", "items": {"$ref": "#/$defs/statement"}}
}
},
"param": {
"type": "object",
"additionalProperties": false,
"required": ["name", "required", "type", "default", "span"],
"properties": {
"name": {"type": "string", "minLength": 1},
"required": {"type": "boolean"},
"type": {"type": ["string", "null"]},
"default": {
"oneOf": [{"$ref": "#/$defs/expression"}, {"type": "null"}]
},
"span": {"$ref": "#/$defs/span"}
}
},
"statement": {
"oneOf": [
{"$ref": "#/$defs/stmt_assign"},
{"$ref": "#/$defs/stmt_expression"},
{"$ref": "#/$defs/stmt_branch"},
{"$ref": "#/$defs/stmt_loop"},
{"$ref": "#/$defs/stmt_return"},
{"$ref": "#/$defs/stmt_break"},
{"$ref": "#/$defs/stmt_continue"}
]
},
"stmt_assign": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "target", "value", "span"],
"properties": {
"kind": {"const": "assign"},
"target": {"$ref": "#/$defs/place"},
"value": {"$ref": "#/$defs/expression"},
"span": {"$ref": "#/$defs/span"}
}
},
"stmt_expression": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "value", "span"],
"properties": {
"kind": {"const": "expression"},
"value": {"$ref": "#/$defs/expression"},
"span": {"$ref": "#/$defs/span"}
}
},
"stmt_branch": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "arms", "span"],
"properties": {
"kind": {"const": "branch"},
"arms": {
"type": "array",
"minItems": 1,
"items": {
"type": "object",
"additionalProperties": false,
"required": ["condition", "condition_span", "body", "span"],
"properties": {
"condition": {"$ref": "#/$defs/expression"},
"condition_span": {"$ref": "#/$defs/span"},
"body": {"type": "array", "items": {"$ref": "#/$defs/statement"}},
"span": {"$ref": "#/$defs/span"}
}
}
},
"span": {"$ref": "#/$defs/span"}
}
},
"stmt_loop": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "condition", "condition_span", "body", "span"],
"properties": {
"kind": {"const": "loop"},
"condition": {"$ref": "#/$defs/expression"},
"condition_span": {"$ref": "#/$defs/span"},
"body": {"type": "array", "items": {"$ref": "#/$defs/statement"}},
"span": {"$ref": "#/$defs/span"}
}
},
"stmt_return": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "value", "span"],
"properties": {
"kind": {"const": "return"},
"value": {"$ref": "#/$defs/expression"},
"span": {"$ref": "#/$defs/span"}
}
},
"stmt_break": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "span"],
"properties": {
"kind": {"const": "break"},
"span": {"$ref": "#/$defs/span"}
}
},
"stmt_continue": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "span"],
"properties": {
"kind": {"const": "continue"},
"span": {"$ref": "#/$defs/span"}
}
},
"place": {
"oneOf": [
{"type": "string", "minLength": 1},
{
"type": "object",
"additionalProperties": false,
"required": ["kind", "base", "index", "span"],
"properties": {
"kind": {"const": "index"},
"base": {"$ref": "#/$defs/expression"},
"index": {"$ref": "#/$defs/expression"},
"span": {"$ref": "#/$defs/span"}
}
}
]
},
"expression": {
"oneOf": [
{"$ref": "#/$defs/expr_literal"},
{"$ref": "#/$defs/expr_variable"},
{"$ref": "#/$defs/expr_list"},
{"$ref": "#/$defs/expr_record"},
{"$ref": "#/$defs/expr_unary"},
{"$ref": "#/$defs/expr_binary"},
{"$ref": "#/$defs/expr_member"},
{"$ref": "#/$defs/expr_index"},
{"$ref": "#/$defs/expr_call"}
]
},
"expr_literal": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "type", "span"],
"properties": {
"kind": {"const": "literal"},
"type": {"enum": ["int", "float", "text", "bool", "none"]},
"value": {"type": ["string", "number", "boolean"]},
"span": {"$ref": "#/$defs/span"}
},
"allOf": [
{"if": {"properties": {"type": {"const": "int"}}},
"then": {"required": ["value"], "properties": {"value": {"type": "string", "pattern": "^-?[0-9]+$"}}}},
{"if": {"properties": {"type": {"const": "float"}}},
"then": {"required": ["value"], "properties": {"value": {"type": "number"}}}},
{"if": {"properties": {"type": {"const": "text"}}},
"then": {"required": ["value"], "properties": {"value": {"type": "string"}}}},
{"if": {"properties": {"type": {"const": "bool"}}},
"then": {"required": ["value"], "properties": {"value": {"type": "boolean"}}}},
{"if": {"properties": {"type": {"const": "none"}}},
"then": {"not": {"required": ["value"]}}}
]
},
"expr_variable": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "name", "span"],
"properties": {
"kind": {"const": "variable"},
"name": {"type": "string", "minLength": 1},
"span": {"$ref": "#/$defs/span"}
}
},
"expr_list": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "items", "span"],
"properties": {
"kind": {"const": "list"},
"items": {"type": "array", "items": {"$ref": "#/$defs/expression"}},
"span": {"$ref": "#/$defs/span"}
}
},
"expr_record": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "entries", "span"],
"properties": {
"kind": {"const": "record"},
"entries": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": ["key", "key_span", "value"],
"properties": {
"key": {"type": "string", "minLength": 1},
"key_span": {"$ref": "#/$defs/span"},
"value": {"$ref": "#/$defs/expression"}
}
}
},
"span": {"$ref": "#/$defs/span"}
}
},
"expr_unary": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "op", "operand", "span"],
"properties": {
"kind": {"const": "unary"},
"op": {"enum": ["not", "neg", "pos"]},
"operand": {"$ref": "#/$defs/expression"},
"span": {"$ref": "#/$defs/span"}
}
},
"expr_binary": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "op", "left", "right", "span"],
"properties": {
"kind": {"const": "binary"},
"op": {
"enum": [
"or", "and", "eq", "ne", "lt", "le", "gt", "ge",
"add", "sub", "mul", "div", "floor_div", "mod", "pow"
]
},
"left": {"$ref": "#/$defs/expression"},
"right": {"$ref": "#/$defs/expression"},
"span": {"$ref": "#/$defs/span"}
}
},
"expr_member": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "base", "field", "span"],
"properties": {
"kind": {"const": "member"},
"base": {"$ref": "#/$defs/expression"},
"field": {"type": "string", "minLength": 1},
"span": {"$ref": "#/$defs/span"}
}
},
"expr_index": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "base", "index", "span"],
"properties": {
"kind": {"const": "index"},
"base": {"$ref": "#/$defs/expression"},
"index": {"$ref": "#/$defs/expression"},
"span": {"$ref": "#/$defs/span"}
}
},
"expr_call": {
"type": "object",
"additionalProperties": false,
"required": ["kind", "callee", "args", "span"],
"properties": {
"kind": {"const": "call"},
"callee": {"$ref": "#/$defs/expression"},
"args": {"type": "array", "items": {"$ref": "#/$defs/arg"}},
"span": {"$ref": "#/$defs/span"}
}
},
"arg": {
"type": "object",
"additionalProperties": false,
"required": ["name", "value", "span"],
"properties": {
"name": {"type": ["string", "null"]},
"value": {"$ref": "#/$defs/expression"},
"span": {"$ref": "#/$defs/span"}
}
},
"import": {
"type": "object",
"additionalProperties": false,
"required": ["alias", "target", "span", "resolved"],
"properties": {
"alias": {"type": "string", "minLength": 1},
"target": {"type": "string", "minLength": 1},
"span": {"$ref": "#/$defs/span"},
"resolved": {"type": ["string", "null"]}
}
},
"reference": {
"type": "object",
"additionalProperties": false,
"required": [
"source", "source_unit", "url", "span", "state", "target_kind",
"target_module", "target_unit", "candidate_package_instance_id",
"candidate_path", "fragment", "candidates"
],
"properties": {
"source": {"type": "string", "minLength": 1},
"source_unit": {"type": "string", "minLength": 1},
"url": {"type": "string"},
"span": {"$ref": "#/$defs/span"},
"state": {
"enum": [
"resolved", "not_loaded", "missing", "ambiguous",
"external", "outside_scope", "invalid"
]
},
"target_kind": {"enum": ["module", "file", null]},
"target_module": {"type": ["string", "null"]},
"target_unit": {"type": ["string", "null"]},
"candidate_package_instance_id": {"type": ["string", "null"]},
"candidate_path": {"type": ["string", "null"]},
"fragment": {"type": ["string", "null"]},
"candidates": {
"type": "array",
"items": {"type": "string", "minLength": 1}
}
}
},
"callee": {
"oneOf": [
{
"type": "object",
"additionalProperties": false,
"required": ["kind", "name"],
"properties": {
"kind": {"const": "ident"},
"name": {"type": "string", "minLength": 1}
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["kind", "base", "field"],
"properties": {
"kind": {"const": "member"},
"base": {"$ref": "#/$defs/callee"},
"field": {"type": "string", "minLength": 1}
}
},
{
"type": "object",
"additionalProperties": false,
"required": ["kind", "span"],
"properties": {
"kind": {"const": "expression"},
"span": {"$ref": "#/$defs/span"}
}
}
]
},
"target_owner": {
"oneOf": [
{
"type": "object",
"additionalProperties": false,
"required": ["kind", "package", "digest"],
"properties": {
"kind": {"const": "plugin"},
"package": {"type": "string", "minLength": 1},
"digest": {"type": "string", "pattern": "^sha256:[0-9a-f]{64}$"}
}
},
{"type": "null"}
]
},
"call": {
"type": "object",
"additionalProperties": false,
"required": [
"function", "span", "callee", "state", "target", "target_kind",
"target_owner", "reason"
],
"properties": {
"function": {"type": "string", "minLength": 1},
"span": {"$ref": "#/$defs/span"},
"callee": {"$ref": "#/$defs/callee"},
"state": {"enum": ["function", "builtin", "plugin", "unresolved"]},
"target": {"type": ["string", "null"]},
"target_kind": {"enum": ["function", "builtin", "plugin", null]},
"target_owner": {"$ref": "#/$defs/target_owner"},
"reason": {"enum": ["dynamic", "unbound", null]}
}
},
"resource": {
"type": "object",
"additionalProperties": false,
"required": [
"id", "module_id", "unit_id", "kind", "span", "content_digest",
"language", "display"
],
"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": {"$ref": "#/$defs/span"},
"content_digest": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
"language": {"type": ["string", "null"]},
"display": {"type": ["boolean", "null"]}
}
},
"diagnostic": {
"type": "object",
"additionalProperties": false,
"required": [
"module", "relative_path", "span", "line", "column",
"severity", "code", "message", "hints"
],
"properties": {
"module": {"type": "string", "pattern": "::"},
"relative_path": {"type": "string", "minLength": 1},
"span": {"oneOf": [{"$ref": "#/$defs/span"}, {"type": "null"}]},
"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"}}
}
}
}
}