Files
marqdo-lint/docs/ARCHITECTURE.md
T

46 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 架构
`marqdo-lint` 只消费当前 Marqdo 公开协议:
```text
check ENTRY --emit PATH
│
├── modules[].source ────── SourceSnapshot
├── modules[].document ─── MarkdownTree(容器/载体)
├── modules[].units ────── 标题、模式、完整 section range
└── functions/references/calls/resources
│
ReadableControlTree ─ Rules ─ Diagnostics ─ human / JSON
```
## 模块职责
- `input`:唯一的 CLI 适配层。执行一次 `check --emit`,捕获 artifact 字节
与摘要,校验 SemVer 范围和协议,然后用 artifact source 构造
`SourceDocument`。不会为了读取模块重新打开 `relative_path`。
- `model`:严格、闭合的 Analysis revision 3 类型;`SourceSnapshot`;
`MarkdownTree` 只从 `document` 与 `units` 建立,不解析第二套 Markdown。
- `alignment`:以函数 id 找到 Exec H2,按 span/语句路径对齐分支臂、嵌套控制
和最近循环目标。没有版本分支,也没有对旧制品的“尽力解析”。
- `engine`:为每个函数复用同一份对齐和度量,组装诊断。
- `rules`:稳定 ID 与纯检测逻辑;规则不调用 CLI,不各自实现语言解析。
Reference 规则只读 `references[].state`,Call 规则只读
`calls[].state`。`not_loaded` 是“未核验”,不是断链。
- `metrics`:函数级叙述比例和解释覆盖,不把文字长度当作正确性证明。
- `diagnostics`:统一 human/JSON 渲染、排序、失败阈值和退出码。
- `fix`:只处理可证明等价的局部空白。写回前在临时项目中重新执行同一条
`check --emit`,比较规范化 document、执行载荷与 Analysis 指纹。
## 不变量
1. 一个入口一次 `check --emit`;`modules[].document` 是唯一 Markdown AST
来源,Lint 不运行 `inspect`。
2. `modules[].source` 是唯一源码;span 只相对该字符串解释。
3. Analysis 决定执行结构,document 决定视觉容器,units 决定标题边界和
完整 section range。三者都不能由行首正则替代。
4. `heading_span` 只是标题本身;`span` 是从标题到下一个同级/更高标题或
EOF 的完整范围,包含子标题。
5. 只有 Exec H2 创建 callable;Knowledge、namespace、section 不创建函数。
6. 旧 revision、旧字段集合、错误摘要和非法 span 在规则运行前 fail closed。
7. 自动修复先验证再写回;任何歧义都保持原文件不变。