---
title: "驱动层"
---

> Documentation Index
> Fetch the complete documentation index at: https://koine.systems/llms.txt
> Use this file to discover all available pages before exploring further.

# 驱动层

驱动层不是第二门语言，是场景加查询。

```mermaid
flowchart LR
  Start[起点] -->|do| Step1[世界 1]
  Step1 -->|do| Step2[世界 2]
  Step2 -->|observe / diff| Result[观测与差异]
```

## 场景

> 特性：K-023

```koine
scenario refund_flow {
  start s0
  do place(o1)
  do pay(o1)
  do refund(o1)
}
```

规则：

- `start s0` 引用 init 或 state；也可以 `start { ... }` 直接声明世界。
- `do T(args)` 执行一条 transition。
- 场景是线性的，没有分支、循环、变量。
- 每一步的绑定必须明确。

场景就是一条路径：

```text
s0 | place(o1), pay(o1), refund(o1)
```

## 执行语义

1. 从 `start` 世界开始。
2. 依次执行 `do`。
3. 每一步检查 require 和 axiom。
4. 任何一步失败，报告第几步、哪条 transition、哪个绑定。
5. 成功时返回世界序列和每步差异。

运行时 trace 记录每一步的 index、transition、binding、actor、time、accepted/rejected 和 diff。被拒绝的 step 不产生新世界，但可以进入 trace；完整历史见 [ADR-0015](https://koine.systems/notes/decisions/0015-history-as-snapshot-sequence/)。

## 回放失败

```text
error[koine.run.step-rejected]: 第 3 步被拒绝
  --> refund_flow:5:3
   |
 5 |   do refund(o1)
   |      ^^^^^^^^^^ refund 的 require 不成立
   = note: status(o1) = Placed，不是 Paid
```

回放不猜、不跳过。失败就停。

## 查询

查询包括 `successors`、`predecessors`、`path`、`diff`、`observe`、`find`、`explore`。世界和边的结构见[观察接口](https://koine.systems/reference/spec/observations/#观察接口)；命令行用法见 [CLI](https://koine.systems/reference/cli/)。

`find` 与 `explore` 的分工见[观察](https://koine.systems/reference/spec/observations/#find-与-explore)。

## 探索边界

| 边界 | 含义 | 默认 |
| --- | --- | --- |
| `--depth n` | 最多走 n 步 | 10 |
| `--max-worlds n` | 最多访问 n 个世界 | 1000 |
| `--timeout ms` | 最多花多少时间 | 无 |

超过边界时报告“未完成”，不假装完整。

Source: https://koine.systems/reference/spec/driving/index.mdx
