merge: reconcile 2.9.0 proof release with latest native AI extension updates
This commit is contained in:
commit
c952765845
30 files changed
+3418
-67
No files matched your search
@@ -0,0 +1,140 @@
|
||||
# Marqdo native agent flow — implementation contract
|
||||
|
||||
Status: **incremental, draft**. The core orchestration now has a plugin-only
|
||||
alternative to interpreter-stack suspension: a durable finite step state machine
|
||||
with explicit safe commit boundaries. Do not claim arbitrary stack-level
|
||||
continuation or exactly-once external writes based on a checkpoint file.
|
||||
|
||||
## Author surface (implemented in this branch)
|
||||
|
||||
| Module | Function | Contract |
|
||||
|---|---|---|
|
||||
| ext/ai/context.mq.md | scope | Select a bounded source excerpt using parsed Markdown headings; ambiguous names fail closed |
|
||||
| ext/ai/context.mq.md | pack | Compact caller-provided file/class/function text via ContextPackV2 |
|
||||
| ext/ai/flow.mq.md | ask/choose/parse_choice | One short decision, allowed-choice verification, at most one format repair |
|
||||
| ext/ai/flow.mq.md | input/reply | Durable step-boundary user-input gate keyed by id + source revision and scope |
|
||||
| ext/ai/flow.mq.md | start/wait/parallel | Existing Marqdo subtask scheduler, failure-preserving parallel result aggregation |
|
||||
| ext/ai/flow.mq.md | enter | Resolve only author-supplied registered skill name, run via standard subtask path |
|
||||
| ext/ai/recovery.mq.md | decide/save/load | Native error policy and CheckpointV2; no implicit unsafe re-execution |
|
||||
| ext/ai/workflow.mq.md | open/next/commit/cancel | Durable forward-only step machine with per-step commit boundaries |
|
||||
| ext/ai/workflow.mq.md | inspect/list | Read-only progress summary and checkpoint discovery scoped by session/principal |
|
||||
| ext/ai/workflow.mq.md | tick/retry_plan/retry_commit/retry_failed | One-step execution and failed-only read-only recovery |
|
||||
|
||||
The native agent plugin provides `agent_choice_parse`, `agent_context_scope`,
|
||||
`agent_input_open`, `agent_input_resume`, `agent_parallel_report`, and the
|
||||
`agent_workflow_*` primitives including `inspect` and `list`.
|
||||
Plugin errors must be visible, never converted into a fabricated successful answer.
|
||||
All workflow wrappers accept a host-relative `resume_dir`, so tests and callers
|
||||
can isolate checkpoints instead of sharing the default `.marqdo/agent-resume`.
|
||||
|
||||
## Invariants
|
||||
|
||||
- A model choice is untrusted data until verified against an explicit option list.
|
||||
- An imported module is **not** automatically part of a model prompt.
|
||||
- The requested heading scope, not the entire source file, is the prompt source.
|
||||
- A pending user-input gate owns a persistent checkpoint, not a blocked interpreter thread.
|
||||
- The same answer may be returned repeatedly; a competing answer or stale revision conflicts.
|
||||
- A completed subtask wait is distinct from a successful child exit.
|
||||
- Existing successful siblings remain visible when one subtask fails.
|
||||
- Writes, executable effects and external writes remain under ToolSpec permissions,
|
||||
the EffectLedger and source-version checks.
|
||||
- No component may silently broaden a tool's authorization on failure.
|
||||
|
||||
## Important limitations in this branch
|
||||
|
||||
The input/reply gate stores an explicit **step boundary**. It does not yet persist
|
||||
an arbitrary bytecode interpreter frame. Applications must choose and re-enter
|
||||
their next Marqdo function explicitly after receiving a verified input answer.
|
||||
The current source selector relies on a Markdown parser plus Marqdo heading
|
||||
conventions, not on the compiler's resolved module/class/function AST and symbols.
|
||||
Host identity inputs are supplied by the caller; production applications must
|
||||
attest them from their authenticated session, never use model-generated identity.
|
||||
The parallel wrapper reuses `subtask.run_many` and does not add durable child
|
||||
lease orchestration. Live provider tests and real 1B-model benchmarking remain open.
|
||||
|
||||
## Required VM/runtime completion: suspended execution
|
||||
|
||||
1. Introduce `WaitingInput` as a scheduler state, distinct from terminal failure.
|
||||
Save the logical run, program counter at a safe suspension boundary, bound
|
||||
inputs, variable snapshot, module and tool digests, and effect watermark.
|
||||
2. Resume via a new attempt linked to the original logical run, but never
|
||||
automatically repeat committed effects. Preserve cancellation and budget.
|
||||
3. The resume endpoint must be atomic (revision CAS), authenticate principal
|
||||
and workspace, verify source and tool schema revisions, and deduplicate
|
||||
repeated reply requests. Do not trust IDs inside model text.
|
||||
4. Handle interrupted worker, partial snapshot, stale input, invalid choice and
|
||||
unknown external write as separate outcomes. Treat unknown writes as
|
||||
reconciliation-required; do not invent exactly-once guarantees.
|
||||
5. Persist only serializable language values at declared safe points. If a
|
||||
foreign kernel, socket or native handle is live, explicitly refuse
|
||||
transparent frame recovery and preserve a safe step-level restart option.
|
||||
|
||||
## Required durable parallel execution
|
||||
|
||||
A parent dispatches child `.mq.md` functions using registered paths, grants
|
||||
minimal capabilities, shares budget and rate limits, and persists a child task
|
||||
manifest. Child completion records a status, value ref, output digest and ledger
|
||||
watermark before the parent merges results. For same-resource writes, use
|
||||
serialized revisions and explicit commit order. On parent cancellation, stop
|
||||
new children and request child cancellation; do not assume remote writes rolled
|
||||
back. On recovery, reconcile child attempts and reuse successful results.
|
||||
|
||||
## Release gates
|
||||
|
||||
| Test | Required observation |
|
||||
|---|---|
|
||||
| compiler/import check | All new `.mq.md` functions pass contract checks and execute via ABI |
|
||||
| small model outputs | Exact, labeled, fenced and numeric options normalize; mixed options fail |
|
||||
| input gate crash | After checkpoint, reply is committed once; alternate reply conflicts |
|
||||
| source drift | Original gate cannot resume against changed source revision |
|
||||
| context isolation | Class/function selectors reject ambiguity and ignore fenced headings |
|
||||
| concurrent partial | Failed/uncertain child never discards successful siblings |
|
||||
| unknown write | Neither retry nor recovered child duplicates an unconfirmed effect |
|
||||
| long-run cancellation | Worker/child task termination preserves usable artifacts and receipts |
|
||||
| compatibility | Existing `agent.step/plan/run` and workbooks remain callable |
|
||||
| model evaluation | Tokens/decision, semantic validity, end-to-end completion, recovery overhead |
|
||||
|
||||
Do not merge the branch as a completed runtime refactor until the relevant
|
||||
runtime gates, including crash injection and multi-worker concurrency, pass.
|
||||
|
||||
|
||||
## Plugin-only workflow (November 18 revision)
|
||||
|
||||
The Agent ABI plugin implements
|
||||
`agent_workflow_open/next/inspect/list/commit/cancel` plus the failed-only
|
||||
retry primitives. The small `ext/ai/workflow.mq.md` library wraps these
|
||||
primitives and provides `tick` to execute exactly one safe decision or document
|
||||
task per call. `inspect` and `list` are strictly read-only: they report progress
|
||||
or discover checkpoints without advancing a cursor or running a step.
|
||||
Source definitions have only five step kinds: `model`, `input`, `skill`,
|
||||
`parallel` and `return`. Model text is verified against declared options.
|
||||
`input` intentionally returns a waiting status; the UI supplies an answer
|
||||
through `commit` on a later invocation. There is no interpreter thread to
|
||||
hold and no need for a separate qdagent orchestration server.
|
||||
|
||||
The checkpoint records the source revision, caller-provided session and
|
||||
principal scope, next step index and the completed outputs. The same step
|
||||
cannot be silently committed twice. Mixed child outcomes preserve completed
|
||||
siblings in the checkpoint and **block** further automatic execution until
|
||||
the unknown/failed child operations are reconciled.
|
||||
|
||||
The state engine does not execute arbitrary unregistered tools directly:
|
||||
`tick` delegates to existing Marqdo ABI-backed SKILL/subtask functions.
|
||||
This is an implementation of **durable step-state recovery**, not a claim
|
||||
of transparent recovery for a suspended foreign function or native call.
|
||||
It provides the practical workflow needed for short qdagent SKILLs without
|
||||
altering the Marqdo interpreter.
|
||||
|
||||
### Security/reliability boundary still required for production
|
||||
|
||||
- The host must attest source digest, principal, session, permissions and
|
||||
registry, rather than accepting values copied from an LLM response.
|
||||
- Effectful child tools must use the existing EffectLedger and external
|
||||
receipt reconciliation; no automatic re-dispatch after an uncertain write.
|
||||
- Cancelling a workflow checkpoint does not automatically cancel previously
|
||||
spawned external children; the supervisor must propagate cancellation.
|
||||
- The current task runner is step-atomic, not a durable parallel child lease
|
||||
scheduler. A future plugin-only child manifest may use the host's existing
|
||||
`runtime` query API, but must not bypass process.exec or file-root grants.
|
||||
- Cross-process locks need a lease/owner-aware stale-lock recovery path;
|
||||
a stale lock currently fails closed and requires operator review.
|
||||
+575
@@ -0,0 +1,575 @@
|
||||
我会在后续继续完成开发,接下来我比较关心marqdo的知识编译的问题,你认为我将marqdo的函数内的语句成为锚点,或者说带标记的内容都成为锚点,方便使用[]()引用,成为知识编译的一种可行吗?
|
||||
|
||||
**我认为完全可行,而且这可能是 Marqdo 实现“知识编译”最有价值的方向之一。**
|
||||
|
||||
但我建议对你的设想做一个关键调整:
|
||||
|
||||
> **所有可执行语句都成为编译器内部可定位的节点;所有具有明确标记的内容,都可以提升为稳定、可引用的知识锚点。**
|
||||
>
|
||||
> 锚点不仅用于跳转,还应该具备语义身份、依赖关系、执行能力、版本和验证状态。
|
||||
|
||||
这样,Marqdo 的函数就不再是一个只能整体调用的黑盒,而是一组能够逐层寻址、复用、验证和追溯的知识节点。
|
||||
|
||||
## **一、你的设想实际上已经有实现基础**
|
||||
|
||||
我重新查看了 Marqdo `main` 分支的代码,发现你的想法与仓库已有设计高度一致,并不需要从零开始。
|
||||
|
||||
在 [可执行知识系统设计](https://github.com/cflmy/marqdo/blob/main/doc/design/executable-knowledge-system.md?utm_source=chatgpt.com) 中,你已经提出:
|
||||
|
||||
- `#`:知识命名空间、类或知识实体。
|
||||
- `##`:具备参数和返回契约的可复用函数。
|
||||
- `[]()`:为函数内部的知识步骤命名,并保留原有执行语义。
|
||||
- 编译器将命名步骤转化为 `KnowledgeStep`,关联依赖、类型、来源和效果。
|
||||
|
||||
更重要的是,这不只是文档构想。目前 `src/sema/ir.rs` 已经实现了 `KnowledgeRef`、`KnowledgeStep` 和 `collect_named_steps`,并且能够识别部分遮蔽表达式、函数调用、循环和正文知识引用。
|
||||
|
||||
不过,现在的内部步骤 ID 采用类似 `#step-1`、`#step-2` 的序号形式。这种身份适合单次编译,却不适合长期知识引用:在函数前面插入一条新步骤,就可能改变后面所有步骤的编号。
|
||||
|
||||
因此,我认为下一阶段的重点不是“再增加一种锚点语法”,而是:
|
||||
|
||||
**将已有的 KnowledgeStep 从编译期记录,升级为具备稳定身份的知识制品。**
|
||||
|
||||
## **二、建议采用“两级锚点体系”**
|
||||
|
||||
这比“把每一条语句都暴露为知识”更合理。
|
||||
|
||||
| 层级 | 生成规则 | 作用 |
|
||||
| ------ | -------------------------- | ------------------ |
|
||||
| 内部锚点 | 所有可执行 AST 语句自动生成 | 调试、数据流、执行追踪、增量编译 |
|
||||
| 公共知识锚点 | `#`、`##`、带标记的表达式、显式标记的知识内容 | 跨函数引用、搜索、依赖分析、知识复用 |
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
|
||||
# 订单定价
|
||||
|
||||
## 计算税额
|
||||
|
||||
根据订单地区查询税率,再计算应缴税额。
|
||||
|
||||
**税率 = [查询适用税率](税率库.查询(地区))**
|
||||
|
||||
**税额 = [计算应缴税额](金额 * 税率)**
|
||||
|
||||
*税额*
|
||||
|
||||
```
|
||||
|
||||
编译器可以从这段普通 Marqdo 文档中建立以下结构:
|
||||
|
||||
**订单定价**
|
||||
|
||||
Class · 知识命名空间
|
||||
|
||||
**计算税额**
|
||||
|
||||
Function · 公开可调用知识单元
|
||||
|
||||
**查询适用税率**
|
||||
|
||||
Observe / Reuse
|
||||
|
||||
**计算应缴税额**
|
||||
|
||||
Derive
|
||||
|
||||
数据依赖:税率 → 税额
|
||||
|
||||
**返回税额**
|
||||
|
||||
Return · 函数结果
|
||||
|
||||
在这个结构中,两个标记步骤各有自己的地址,并且可以独立被查询、检查来源、进行影响分析。
|
||||
|
||||
这和普通代码索引有根本区别:它不仅知道“这个函数在哪里”,还知道**函数为什么得到这个结果,以及结果依赖哪些知识**。
|
||||
|
||||
## **三、最关键的语义区分:可引用不等于可执行**
|
||||
|
||||
我认为这里必须制定严格的语义规范。
|
||||
|
||||
假设一个函数内部存在名为“查询适用税率”的锚点。
|
||||
|
||||
那么,其他文档引用它时,实际上存在三种不同需求:
|
||||
|
||||
| 操作 | 期望行为 |
|
||||
| ---- | --------------------- |
|
||||
| 引用知识 | 找到该步骤,读取说明、实现和出处 |
|
||||
| 获取结果 | 在已知输入和执行环境中取得该步骤的计算结果 |
|
||||
| 复用执行 | 重新执行该步骤,产生新的计算结果 |
|
||||
|
||||
**不能因为一个锚点存在,就允许它在任何地方被直接执行。**
|
||||
|
||||
例如,函数内部的“计算应缴税额”依赖局部变量 `金额` 和 `税率`。假如其他函数直接引用这个步骤,编译器必须确认它需要哪些输入。
|
||||
|
||||
有两种合理的处理方式:
|
||||
|
||||
- 默认只允许引用它的定义、来源和契约。
|
||||
- 需要独立执行时,必须拥有完整输入绑定;否则将它提取为独立 `##` 函数。
|
||||
|
||||
后续可以考虑由编译器自动将满足纯度、闭包与输入条件的知识步骤提升为可调用能力。但这应是第二阶段,不能在最初就隐式执行任何锚点。
|
||||
|
||||
### **不必重新设计 **`[]()`** 的基本语法**
|
||||
|
||||
可以继续保留现有语义:
|
||||
|
||||
```
|
||||
**税额 = [计算应缴税额](金额 * 税率)**
|
||||
```
|
||||
|
||||
这里 `[]` 提供知识描述,`()` 保留表达式的执行含义。
|
||||
|
||||
另外,知识定位可以使用编译后的稳定地址,例如以下**拟议形式**:
|
||||
|
||||
```
|
||||
[查看税率依据](mq://pricing/订单定价/计算税额#查询适用税率)
|
||||
```
|
||||
|
||||
这应当被解释为知识引用,而不是自动重新执行“查询适用税率”。这里的 `mq://` 是建议的地址表示,不是说当前版本已经支持这样的写法。
|
||||
|
||||
我建议将 `KnowledgeRef` 按所在上下文分为:
|
||||
|
||||
- 正文:解析目标和展示证据,不产生副作用。
|
||||
- 可执行表达式:按原有求值语义执行,并附带引用元数据。
|
||||
- 工具或智能体调用:额外要求可调用契约、输入闭合与权限验证。
|
||||
|
||||
这样 `[]()` 就能成为统一引用形式,同时不破坏现有 Markdown 的可读性。
|
||||
|
||||
## **四、怎样让锚点稳定**
|
||||
|
||||
这是整个方案技术上最难、也最重要的地方。
|
||||
|
||||
**知识锚点不能用行号或内容哈希直接作为永久身份。**
|
||||
|
||||
因为代码修改时:
|
||||
|
||||
- 插入语句会改变行号。
|
||||
- 修改公式会改变哈希,但可能仍是同一个知识概念。
|
||||
- 修改描述名称不一定意味着知识实体改变。
|
||||
- 两个函数可能有相同的步骤名称。
|
||||
|
||||
因此,建议将三个概念拆开:
|
||||
|
||||
| 概念 | 意义 | 变化规则 |
|
||||
| ---------------- | --------- | --------- |
|
||||
| `AnchorId` | 知识单元的稳定身份 | 尽量跨版本保持 |
|
||||
| `ContentDigest` | 当前定义与实现 | 实现发生变化就更新 |
|
||||
| `EvidenceDigest` | 来源与验证证据 | 证据变化时更新 |
|
||||
|
||||
对于自动生成的锚点,可以先根据模块身份、所属函数、局部名称和结构位置确定候选身份,再通过上一版编译产物中的映射记录保持身份连续。
|
||||
|
||||
对于需要长期跨文档引用的公共知识锚点,可以允许显式稳定 ID,或者由编译器自动登记到知识索引中。**显式 ID 不必强制写在每个 **`[]()`** 中**,这样才能保持 Marqdo 的简洁性。
|
||||
|
||||
如果两个同级锚点都叫“查询适用税率”,编译器必须报告歧义,要求进一步限定,不能按出现顺序选择。
|
||||
|
||||
## **五、知识编译的最终产物应该是什么**
|
||||
|
||||
我认为一个知识锚点至少需要这些字段:
|
||||
|
||||
```
|
||||
|
||||
{
|
||||
"anchor_id": "pricing.tax.lookup",
|
||||
"owner": "订单定价.计算税额",
|
||||
"label": "查询适用税率",
|
||||
"kind": "observe",
|
||||
"inputs": ["地区"],
|
||||
"outputs": ["税率"],
|
||||
"dependencies": ["税率库.查询"],
|
||||
"effects": ["read"],
|
||||
"source_span": {
|
||||
"file": "pricing.mq.md",
|
||||
"line": 8
|
||||
},
|
||||
"content_digest": "...",
|
||||
"evidence": [],
|
||||
"verification": {
|
||||
"resolved": true,
|
||||
"tested": false,
|
||||
"source_verified": false
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
这是一份拟议的数据结构,`anchor_id` 仅为示例。
|
||||
|
||||
这里还有一项值得强调的区别:**知识可以编译成功,但并不代表知识在事实上正确。**
|
||||
|
||||
例如读取“某地区税率”,编译器可以验证依赖、参数、数据类型、调用目标,却无法仅凭这些信息证明外部税率数据仍然有效。
|
||||
|
||||
所以应当把编译状态、测试状态、来源验证状态和领域正确性分别记录,而不能用一个 `verified=true` 概括所有问题。
|
||||
|
||||
### **推荐的编译流水线**
|
||||
|
||||
1\. Parse
|
||||
|
||||
读取 Markdown 与 Marqdo AST
|
||||
|
||||
2\. Anchor
|
||||
|
||||
为语句与标记内容建立地址和身份
|
||||
|
||||
3\. Resolve
|
||||
|
||||
绑定函数、变量、知识引用和依赖
|
||||
|
||||
4\. Verify
|
||||
|
||||
检查类型、契约、权限、来源和版本
|
||||
|
||||
5\. Emit
|
||||
|
||||
生成知识图、锚点索引、引用锁与执行制品
|
||||
|
||||
这基本可以落在当前 `src/sema/` 和 `src/knowledge/` 的基础上,不需要开发第二套语言执行器。特别是现有 `SemanticProject` 已能导出 `steps.json`、`refs.json` 和 `artifacts`;真正需要扩展的是步骤的稳定身份、数据依赖、引用绑定以及验证信息。
|
||||
|
||||
## **六、我建议下一步怎么实现**
|
||||
|
||||
优先做三个阶段,而不是一下将所有 Markdown 内容变成公开知识。
|
||||
|
||||
| 阶段 | 主要工作 | 验收 |
|
||||
| ------- | ---------------------------------------- | ------------------ |
|
||||
| M1:锚点身份 | 扩展 `KnowledgeStep`,建立稳定 `AnchorId` 和增量映射 | 插入其他语句后,原引用不漂移 |
|
||||
| M2:锚点引用 | 扩展 `KnowledgeRef` 和语义解析,支持跨函数、跨文档的知识定位 | 能解析、检测歧义、建立反向依赖 |
|
||||
| M3:知识制品 | 生成可查询的知识图、版本锁、验证与影响分析 | 改一条规则,可定位受影响的结果与叙述 |
|
||||
|
||||
之后再增加局部知识步骤的独立执行、缓存、自动提取为函数,以及智能体按需发现知识的能力。
|
||||
|
||||
## **七、这对 Marqdo 的真正价值**
|
||||
|
||||
我觉得这一方向比单纯强调“Markdown 可以执行”更有研究价值。
|
||||
|
||||
传统函数提供的是函数级抽象。你现在提出的机制则能够把抽象进一步下沉:
|
||||
|
||||
**文档 → 类 → 函数 → 知识步骤 → 依赖与证据。**
|
||||
|
||||
当智能体发现某个已有知识满足任务需求时,不需要再次生成代码,也不需要复制一段函数实现。它能够先定位知识节点,查询其契约与依据,再决定是引用现有结果、调用已有函数,还是创建新的知识。
|
||||
|
||||
但需要避免一个研究上的陷阱:**把语句赋予 ID 本身,不足以构成有说服力的知识编译创新。** 它仍可能被认为只是代码索引或细粒度程序分析。
|
||||
|
||||
真正值得验证的主张是:
|
||||
|
||||
> **Marqdo 能否把自然语言标记与可执行语义编译为统一、稳定、可验证的知识节点,并在知识发生改变时,自动维护其引用、依赖和可信状态?**
|
||||
|
||||
如果能够证明这件事,就形成了一条从可读 Markdown 到可执行知识库的清晰技术路径。
|
||||
|
||||
因此,我最推荐你的方案是:**函数内所有语句可定位,带标记的内容可公开引用,经过契约验证的知识节点才可独立复用执行。**
|
||||
|
||||
这比让所有语句无差别地成为公共锚点更严谨,也更符合 Marqdo“代码即文档,文档即知识库,知识即可执行”的设计理念。
|
||||
|
||||
现在的marqdo更新到了2.8.0,我觉得自动证明和上面的知识编译有关系,你怎么看,可以给我什么建议?
|
||||
|
||||
我认为 **Marqdo 2.8.0 的自动证明,与我们此前讨论的知识锚点和知识编译,实际上是同一技术体系中缺失的两块拼图**。
|
||||
|
||||
而且在重新阅读 2.8.0 的实现之后,我认为可以提出比“把代码变成知识图,再给函数附加证明”更进一步的目标:
|
||||
|
||||
> **将 **`.mq.md`** 编译为可寻址、可执行、可组合,并携带机器可核验证据的知识制品。**
|
||||
|
||||
这与 Marqdo 原来的“代码即文档,文档即知识库,知识即可执行”并不矛盾,而是让“知识”拥有了可以接受形式化检查的语义。
|
||||
|
||||
不过,我不建议把它直接表述为“Marqdo 自动证明知识正确”。当前 2.8.0 证明的是限定语义模型下的程序性质,而不是自然语言知识的全部真实性。
|
||||
|
||||
## **一、2.8.0 已经完成了哪些关键基础**
|
||||
|
||||
我检查了 [2.8.0 发布说明](https://github.com/cflmy/marqdo/blob/main/doc/releases/v2.8.0.md?utm_source=chatgpt.com)、`src/prove/`、`src/sema/ir.rs` 和相关测试。
|
||||
|
||||
| 能力 | 2.8.0 的实际情况 | 与知识编译的关系 |
|
||||
| ---- | ---------------------------------------------- | ----------------- |
|
||||
| 语义编译 | 已有 SemanticArtifact、KnowledgeRef、KnowledgeStep | 知识的身份与结构 |
|
||||
| 自动证明 | `marqdo prove` 将定理表及函数降级为 Lean 4 | 知识的形式化约束 |
|
||||
| 离线判定 | F1–F5 符号执行;`checked` 不等于 `proved` | 快速、低成本检查 |
|
||||
| 证明证书 | 记录证明状态、源码与工具链哈希 | 知识的可核验证据 |
|
||||
| 反例 | 部分假命题能得到路径或区间见证 | 知识修复依据 |
|
||||
| 组合证明 | 同模块简单纯函数有限内联 | 已有基础,但尚未形成模块化证明体系 |
|
||||
|
||||
当前最值得注意的是:**语义编译器与证明编译器还没有围绕知识锚点形成完整的统一体系。**
|
||||
|
||||
知识编译能够生成步骤和依赖,证明编译能够生成定理和证书,但尚不能自然地表达:
|
||||
|
||||
“这个知识步骤依赖哪些已经证明的知识?证明依赖的知识修改后,哪些证书需要失效?调用者能否直接复用被调用知识的证明,而不必重新展开整个函数?”
|
||||
|
||||
我认为,这就是 Marqdo 2.9 最值得解决的问题。
|
||||
|
||||
## **二、从知识锚点到可证明知识图**
|
||||
|
||||
我建议让知识编译和证明编译共享同一套稳定的语义身份。
|
||||
|
||||
**Marqdo **`.mq.md`
|
||||
|
||||
叙述、类、函数、`[]()`、定理表
|
||||
|
||||
**统一知识语义 IR**
|
||||
|
||||
稳定身份 · 知识锚点 · 数据依赖 · 效果 · 契约
|
||||
|
||||
**知识编译**
|
||||
|
||||
知识图、引用解析、影响分析、执行绑定
|
||||
|
||||
**证明编译**
|
||||
|
||||
Proof IR、Lean、反例、证书
|
||||
|
||||
**可验证知识制品**
|
||||
|
||||
Artifact + Contract + Proof Certificate + Dependencies
|
||||
|
||||
关键变化不是简单地增加几条图上的 `proved_by` 边,而是让编译器能够基于同一份语义结构,分别生成执行内容、知识引用和证明义务。
|
||||
|
||||
我建议采用这样的分工:
|
||||
|
||||
- `#`、`##` 为知识提供作用域和可调用边界。
|
||||
- `[]()` 为内部知识步骤提供可读名称和可寻址身份。
|
||||
- 现有契约表定义输入、输出及其他约束。
|
||||
- 现有定理表表达需要成立的命题。
|
||||
- `prove` 为满足证明条件的命题生成证书。
|
||||
- 知识编译器关联上述信息,生成统一知识制品。
|
||||
|
||||
**不需要为知识证明额外发明一套 Markdown 标记。**
|
||||
|
||||
## **三、最值得实现的功能:证明能够沿知识引用传播**
|
||||
|
||||
假设有三个知识单元:
|
||||
|
||||
**A · 查询适用税率**
|
||||
|
||||
契约:根据地区和时间,返回适用税率
|
||||
|
||||
证明:在已声明的数据有效性条件下,返回值满足范围约束
|
||||
|
||||
**B · 计算税额**
|
||||
|
||||
依赖 A,并根据金额和税率进行计算
|
||||
|
||||
证明:假设 A 的契约成立,B 满足自己的计算性质
|
||||
|
||||
**C · 订单结算**
|
||||
|
||||
依赖 B,并生成最终金额
|
||||
|
||||
证明:在 B 的前提与其他结算条件成立时,满足结算约束
|
||||
|
||||
现在修改 A 的内部实现。
|
||||
|
||||
传统方式下,B、C 可能要重新进行大量测试,或者依赖开发者人工检查。
|
||||
|
||||
我希望 Marqdo 能够做到:
|
||||
|
||||
1. 重新编译 A,确认其契约与实现发生了哪些变化。
|
||||
2. 如果 A 的实现改变,但原契约仍被新证明支持,B 可以在依赖和证明上下文未变时继续复用已有证明。
|
||||
3. 如果 A 的契约不再得到支持,则 B 的相关证明变成 `stale` 或 `unverified`,并进一步影响 C。
|
||||
4. 只对受影响的证明义务重新运行 Lean,而不是重新证明所有知识。
|
||||
|
||||
**这就让知识图成为证明依赖图,同时使证明能够参与增量知识编译。**
|
||||
|
||||
它与 2.8.0 当前的证书缓存有明显区别。当前缓存主要根据源码、Proof IR、库和工具链版本等生成复合键;未来应该进一步细化为:
|
||||
|
||||
- 某个知识锚点的实现指纹。
|
||||
- 该锚点的公开契约。
|
||||
- 证明依赖的其他知识及其契约指纹。
|
||||
- 使用的假设和证明规则。
|
||||
- Lean 内核接受的证明及其环境身份。
|
||||
|
||||
这样才能精确控制哪些结果可以复用。
|
||||
|
||||
## **四、证明不一定只属于函数,也可以属于知识步骤**
|
||||
|
||||
这是我认为你原先“所有带标记的内容成为锚点”构想最有价值的延伸。
|
||||
|
||||
2.8.0 的定理表目前属于函数级声明,位于函数首条可执行语句之前。这很合理,也应该保留为默认的公开契约。
|
||||
|
||||
例如:
|
||||
|
||||
```
|
||||
# 审批
|
||||
|
||||
## 审批订单
|
||||
|
||||
| 定理 | 结论 | 前提 | 策略 |
|
||||
|---|---|---|---|
|
||||
| 大额必经人工 | 包含(轨迹, "人工审核") | 金额 > 10000 | auto |
|
||||
|
||||
1. `金额` > 10000
|
||||
**回执 = [提交人工审核](人工审核(金额=`金额`))**
|
||||
2. *
|
||||
**回执 = [小额自动处理](自动处理(金额=`金额`))**
|
||||
|
||||
*回执*
|
||||
```
|
||||
|
||||
这个示例主要展示已有的定理表与遮蔽表达式如何结合,具体调用仍需要项目中的函数定义和类型契约。
|
||||
|
||||
现在证明的对象主要是 `## 审批订单` 的行为性质。
|
||||
|
||||
我认为将来可以增加一步:
|
||||
|
||||
**把函数证明所涉及的知识步骤,映射到相应的锚点与依赖边。**
|
||||
|
||||
例如,“大额必经人工”定理可以关联到“提交人工审核”知识锚点,同时记录证明是在什么输入条件和语义模型下成立的。
|
||||
|
||||
但是这里必须非常严格:
|
||||
|
||||
- 证明整个函数满足某个性质,不意味着函数内部每个步骤都被单独证明正确。
|
||||
- `[提交人工审核]` 这个自然语言标签,不能自动当成形式化命题。
|
||||
- 证明轨迹包含“人工审核”,也不能证明外部审核服务真的完成了审核。
|
||||
|
||||
因此,**先做函数级证明向锚点的精确关联,再考虑锚点级局部证明**,会更稳妥。
|
||||
|
||||
## **五、建议的统一知识制品结构**
|
||||
|
||||
我建议在现有 `SemanticArtifact`、`KnowledgeStep`、`KnowledgeRef` 之上增加证明关联层,而不是让 `src/prove` 生成第二套互不相认的知识身份。
|
||||
|
||||
下面是建议结构,并非 2.8.0 已有的完整 Schema。
|
||||
|
||||
```
|
||||
|
||||
{
|
||||
"anchor_id": "pricing.tax.calculate",
|
||||
"symbol_id": "mq://project/pricing/function/calculate",
|
||||
"kind": "derive",
|
||||
"contract": {
|
||||
"inputs": ["amount", "rate"],
|
||||
"outputs": ["tax"]
|
||||
},
|
||||
"dependencies": [
|
||||
"pricing.tax.lookup"
|
||||
],
|
||||
"verification": {
|
||||
"parse": "valid",
|
||||
"resolve": "valid",
|
||||
"proof": {
|
||||
"status": "proved",
|
||||
"claims": ["tax_formula"],
|
||||
"certificate": "sha256:...",
|
||||
"assumptions": [],
|
||||
"scope": "function"
|
||||
},
|
||||
"source": "unverified"
|
||||
},
|
||||
"hashes": {
|
||||
"interface": "...",
|
||||
"implementation": "...",
|
||||
"proof_dependencies": "..."
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
一个很重要的设计是:`proof`** 不应该只是一个全局布尔值**。
|
||||
|
||||
不同知识锚点可能有不同性质:某个命题已经证明,另一个命题尚未证明,还有一个证明依赖不可靠的外部假设。
|
||||
|
||||
因此最小证明单元应当是:
|
||||
|
||||
`(AnchorId, ClaimId, Assumptions, SemanticDigest, ProofCertificate)`
|
||||
|
||||
而不是:
|
||||
|
||||
`AnchorId → proved: true`
|
||||
|
||||
这样调用者才能明确知道自己究竟复用了什么保证。
|
||||
|
||||
## **六、2.9 最应该优先实现的四项工作**
|
||||
|
||||
| 优先级 | 工作 | 为什么重要 |
|
||||
| --- | ----------------------------------------- | -------------- |
|
||||
| P0 | 统一 `SymbolId`、`AnchorId`、定理身份 | 解决知识与证明的长期稳定绑定 |
|
||||
| P1 | 将证明证书关联到 SemanticArtifact / KnowledgeStep | 建立知识与证明的直接关系 |
|
||||
| P2 | 跨模块 assume-guarantee 证明组合 | 使证明可以跨知识引用传播 |
|
||||
| P3 | 证明依赖图与增量失效分析 | 使大型知识库不必每次全量重证 |
|
||||
|
||||
我尤其强调 P2。
|
||||
|
||||
因为从 2.8.0 发布说明可以看到,**跨模块调用目前仍视为不透明操作,而 assume-guarantee 后置条件复用明确延期到 2.9**。
|
||||
|
||||
这恰好是知识编译与自动证明结合的突破点。
|
||||
|
||||
假设 Marqdo 有两个函数:
|
||||
|
||||
- `A` 已经证明后置条件 \\(Q_A\\)。
|
||||
- `B` 调用 `A`,希望证明自己的后置条件 \\(Q_B\\)。
|
||||
|
||||
那么 B 不必知道 A 的完整实现,只需要建立调用点的输入满足 A 前置条件,并利用 A 已经证明的后置条件完成自己的证明。
|
||||
|
||||
这正是契约组合推理的基本思路。
|
||||
|
||||
但证明必须明确依赖:A 的证书、其适用条件、A 与 B 的语义模型是否一致,以及任何外部假设。不能把未经验证的函数描述当作公理。
|
||||
|
||||
### **还需要优先修复两个证明语义边界**
|
||||
|
||||
2.8.0 有两项已记录的差异,我建议不要在强化知识证明时忽略:
|
||||
|
||||
- **i64 溢出**:解释器按有界整数处理并可能报错,而当前 Lean 模型使用无界 `Int`。
|
||||
- **除零/模零**:解释器产生运行时错误,Lean 底座目前存在返回 `.int 0` 的建模差异。
|
||||
|
||||
这意味着证明证书必须记录实际覆盖的数值范围和语义前提。未修复或没有证明等价的部分,不能被上层知识引用当成无条件可信的计算保证。
|
||||
|
||||
## **七、与智能体结合后,会产生什么变化?**
|
||||
|
||||
这部分可能最符合你未来做科研智能体的方向。
|
||||
|
||||
过去智能体调用知识库时,主要依据名字、描述、检索相似度来选择已有能力。
|
||||
|
||||
未来可以让它先查询知识图,获得知识制品的:
|
||||
|
||||
- 可执行入口与输入契约。
|
||||
- 形式化证明过的性质。
|
||||
- 来源与版本。
|
||||
- 未证明的假设和适用边界。
|
||||
- 是否受到近期源码或依赖修改的影响。
|
||||
|
||||
于是智能体不再只是“找到一个看起来相关的 SKILL”,而是可以选择一个**在当前任务条件下,拥有足够验证依据的知识能力**。
|
||||
|
||||
例如,量子科研智能体在寻找电路优化方法时,可以优先寻找具有等价性证明的电路变换,而不是每次重新生成并尝试未经验证的优化。
|
||||
|
||||
当然,这需要专门定义量子电路语义、等价关系和可信的验证过程;现有 2.8.0 的控制流证明还不能直接证明任意量子电路等价。
|
||||
|
||||
## **八、研究上怎样证明这条路线有价值?**
|
||||
|
||||
我建议至少设计三个实验,不要只展示“Lean 可以证明 Marqdo”。
|
||||
|
||||
**实验 E1:知识修改与证明增量失效**
|
||||
|
||||
在拥有大量相互引用的知识函数的项目中,修改其中某个函数,对比全量重新证明和基于锚点依赖的增量重新证明。
|
||||
|
||||
指标:重新证明的命题数、证明耗时、失效检测准确率,以及错误复用证书的次数(目标为零)。
|
||||
|
||||
**实验 E2:跨函数与跨文档证明复用**
|
||||
|
||||
与 2.8.0 通过内联或不透明调用处理函数的方案相比,验证契约组合是否显著提升可证覆盖率。
|
||||
|
||||
指标:proved 比例、unverified/rejected 比例、证明时间、需要人工声明的假设数量。
|
||||
|
||||
**实验 E3:证明感知的智能体知识复用**
|
||||
|
||||
让相同模型完成知识检索、函数复用与程序修改任务,对比普通语义检索、只使用知识图、知识图加证明证书三种方案。
|
||||
|
||||
指标:错误知识复用率、任务成功率、人工审核量、输入 Token 和总执行成本。
|
||||
|
||||
这三个实验分别验证“知识编译”、“证明组合”和“智能体使用价值”,能够避免把三个研究主张混成一个难以检验的宏大叙事。
|
||||
|
||||
## **我的总体判断**
|
||||
|
||||
如果按照技术潜力排序,我会这样看:
|
||||
|
||||
| 方向 | 评价 |
|
||||
| ----------------- | ---------------- |
|
||||
| 给所有语句生成锚点 | 必要的基础设施,但单独创新性有限 |
|
||||
| 让 `[]()` 成为稳定知识引用 | 很有价值,能形成统一知识身份 |
|
||||
| 让知识锚点携带可验证契约和证书 | 更有研究深度 |
|
||||
| 让证明沿知识依赖传播并支持增量复用 | 我认为是最值得集中攻关的核心 |
|
||||
|
||||
而且现在你拥有了一个很好的技术条件:**2.8.0 已经实现了真正的 Lean 证明路径,不再只是设计中的设想。**
|
||||
|
||||
我建议将 Marqdo 2.9 的主线收敛成:
|
||||
|
||||
**Proof-Carrying Executable Knowledge(携带证明的可执行知识)**
|
||||
|
||||
但需要注意,Proof-Carrying Code、契约式程序验证和模块化证明本身都是已有研究。Marqdo 真正需要体现的区别,是它如何把 Markdown 原生描述、稳定知识锚点、可执行语义、证明义务与增量知识依赖统一编译为同一个制品体系,而非仅仅给代码加上证明。
|
||||
|
||||
一句话总结我的建议:
|
||||
|
||||
**2.8.0 实现了“文档中的程序可以被证明”;2.9 应当实现“证明可以成为知识的一部分,并随着知识被引用、组合、验证和复用”。**
|
||||
|
||||
我认为,这比单纯继续扩展 `marqdo prove` 可支持的表达式范围,更符合 Marqdo 的长期方向。
|
||||
@@ -0,0 +1,64 @@
|
||||
# Ext pack v2.8.1 发布说明 · Release Notes(AI native flow)
|
||||
|
||||
## 1. 一句话
|
||||
|
||||
独立拓展包 **2.8.1**(CLI 仍为 **2.8.0**):`ext/ai` 交付插件侧持久化工作流——显式
|
||||
`open/next/commit/cancel`、有界模型选择、作用域上下文、只读失败恢复,以及
|
||||
`inspect/list` 与可隔离的 `resume_dir`。Windows `extension-release` 使用原生
|
||||
`path.join` 根路径与 `C:\Windows\System32\tar.exe`(bsdtar)打包。不改解释器栈
|
||||
挂起语义,也不宣称外部写的 exactly-once。
|
||||
|
||||
Independent extension pack **2.8.1** (CLI remains **2.8.0**): `ext/ai` ships a
|
||||
plugin-only durable workflow — explicit `open/next/commit/cancel`, bounded model
|
||||
choice, scoped context packing, failed-only read-only recovery, plus
|
||||
`inspect/list` and isolatable `resume_dir`. Windows `extension-release` packs
|
||||
with native `path.join` roots and `C:\Windows\System32\tar.exe` (bsdtar). No
|
||||
interpreter-stack suspension and no exactly-once external-write claim.
|
||||
|
||||
## 2. 亮点(Highlights)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 持久步骤机 | `plugins/agent` `workflow`:`open/next/commit/cancel/retry_*`,CheckpointV2,逐步提交边界 |
|
||||
| 作者面 | `ext/ai/workflow` · `flow` · `context` · `recovery`;`tick` 单步执行,等待输入不阻塞解释器线程 |
|
||||
| 选择解析 | 精确 / 编号 / 标签 / 短中英句 / JSON 信封;歧义与未知路径失败关闭 |
|
||||
| 作用域上下文 | Markdown 感知的 file/class/function 摘录;歧义拒绝;不把整库 import 塞进提示 |
|
||||
| 安全并行恢复 | 保留成功兄弟结果;仅重试已分类为只读的失败子任务;写/未知效应不自动派发 |
|
||||
| 可观测性 | `inspect`/`list` 只读进度;测试与调用方可传入 host-relative `resume_dir` |
|
||||
| Windows CI | engineering root 用 `path.join`;ZIP 用 `System32\tar.exe --format=zip` |
|
||||
|
||||
设计契约:[native-agent-flow-v3.md](../design/native-agent-flow-v3.md)。
|
||||
|
||||
## 3. 安装(Install)
|
||||
|
||||
```bash
|
||||
marqdo ext add agent # CDN / Releases → 2.8.1
|
||||
# 或:MARQDO_EXT_VERSION=2.8.1 marqdo ext add agent
|
||||
marqdo ext add llm
|
||||
```
|
||||
|
||||
产物:`marqdo-2.8.1-ext.zip` 与双平台 native ZIP(含 agent / llm 等既有原生库)。
|
||||
|
||||
## 4. 验证(Validation)
|
||||
|
||||
```bash
|
||||
cargo test -p marqdo_plugin_agent --locked
|
||||
cargo run --locked -- check ext/ai/flow.mq.md
|
||||
cargo run --locked -- check ext/ai/context.mq.md
|
||||
cargo run --locked -- check ext/ai/recovery.mq.md
|
||||
cargo run --locked -- check ext/ai/workflow.mq.md
|
||||
cargo run --locked -- run tests/ext/ai-native-flow.mq.md
|
||||
cargo run --locked -- run tests/ext/ai-native-workflow.mq.md
|
||||
```
|
||||
|
||||
CI:`.github/workflows/native-ai-flow.yml` 与 `extension-release.yml`(`ext-v2.8.1`)。
|
||||
|
||||
## 5. 已知限制(Known limitations)
|
||||
|
||||
- 输入闸门保存的是**步骤边界**,不是任意字节码解释器帧;回复后须显式进入下一 Marqdo 函数。
|
||||
- 作用域选择依赖 Markdown 标题约定,不是编译器已解析的 AST 符号表。
|
||||
- 调用方提供的 principal/session/source revision 须由已认证宿主证明,不能来自模型文本。
|
||||
- 并行复用 `subtask.run_many`;跨进程子任务租约与已在跑外部进程的取消传播仍待专项注入验证。
|
||||
- 实时大模型与目标 1B 本地模型评测仍开放;写效应自动重试仍被拒绝,直至 EffectLedger 对账完成。
|
||||
|
||||
**核心表面 Δ**:无增删——19 个核心构造不变;本包为 Extension / Agent Runtime。
|
||||
Reference in new issue
Block a user