本页目录
编译期
编译器把 .prime 源文件变成磁盘上的运行时产物。
它只在构建时跑;运行时永远不会重新解析源。
编译流水线

* L2 可选,需要 ANTHROPIC_API_KEY 或 DEEPSEEK_API_KEY 才会启用。
L1 —— schema(强制)
校验必填字段、引用是否存在、装饰器约束、各种 kind 特定 schema。纯结构校验 —— 不调 LLM。每个原子毫秒级。
L3 —— 跨原子(强制)
在解析后的边图上走一遍:标出 requires 中的环、暴露 contradicts 对、
校验 validates-with 与 extends 上的 kind 兼容性。
也是纯逻辑 —— 在 L1 之后的内存图上跑。
L2 —— 语义(可选)
调一个小 LLM(默认 DeepSeek,每个原子约 $0.0001)抓语义漂移 ——
比如一条 rule 的 severity 写 low,但 remediation 描述的却是关键阻断。
需要 API key 才启用;没 key 时编译器会打一行 notice,然后跳过 L2。
Chunker —— 按 kind 投影
按原子走 AST,输出 summary.md / core.md / full.md。
切分规则按 kind 不同(见 Projection)。
发射器
每次构建产出两类产物:
- 每个原子一个目录,路径
compiled/<prefix>/<short-id>/, 里面有atom.yaml(metadata)、graph.yaml(解析后的边)、 以及chunks/{summary,core,full}.md。 - 一个全局 index,路径
compiled/_index.xml—— 就是常驻加载的那一面;每个 domain 一个<cluster>;<atom>项内联 summary,子节点是边。
幂等 + 缓存
同一份源编译两次产出字节级一致的输出。L2 的结果按内容 hash 缓存到
.l2-cache.json,没改动的原子在重新编译时不会再付一次 LLM 成本。
CLI 表面
# Compile one file (smoke test).
prime compile path/to/atom.prime
# Compile a whole sources tree to compiled/.
bun scripts/build-atom-dirs.ts \
--src primes/sources \
--out primes/compiled
# Compile + run L2 + show all errors.
prime compile primes/sources/*.prime --deep --strict
# Validate without emitting.
prime check --registry