> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch44-design-themes/44.3-files-as-truth-tables-as-truth.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 44.3 Files as the Source of Truth, Declaration Tables as the Single Truth

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~192,000 tokens, Output \~11,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

This section covers Themes Four and Five. Both answer the same question: **when one piece of knowledge must stay consistent in multiple places, what do you do?**

Theme Four's answer: let files be the single source of truth, and make everything else a rebuildable derivative. Theme Five's answer: let one declaration table be the single source of truth, and make everything else generated or validated against it. Same instinct — one applied to runtime state, one applied to code structure.

## 44.3.1 Theme Four: Files First, Indexes Derived

Here's where OpenClaw's state actually lives:

| State             | Storage form                               | Can you `cat` it?    |
| ----------------- | ------------------------------------------ | -------------------- |
| Long-term memory  | `MEMORY.md` + daily `memory/YYYY-MM-DD.md` | ✅ Markdown           |
| Session history   | `sessions/<id>.jsonl`                      | ✅ one JSON per line  |
| Config            | `openclaw.json` (JSON5)                    | ✅ JSON with comments |
| Agent personality | `SOUL.md` / `IDENTITY.md` / `USER.md`      | ✅ Markdown           |
| Skills            | `SKILL.md`                                 | ✅ Markdown           |
| Node pairing      | `nodes/paired.json` / `pending.json`       | ✅ JSON               |
| Vector index      | SQLite / LanceDB                           | ❌ binary             |

The last row is the point. **The vector index is the only binary state, and it's explicitly defined as a rebuildable derivative** — delete it, rebuild it, lose nothing. The real source of truth is always those Markdown files.

This principle buys three things:

**Portability.** Moving machines is copying a directory. No migration scripts, no export/import feature.

**Versionability.** The workspace is an ordinary directory; you can `git init` it. Personality changes have diffs, memory growth has history, accidental deletions are a `git checkout` away. For the experience of *raising an agent*, this matters enormously — you can watch it change day by day.

**Human auditability.** Want to know what the agent remembers? Open `MEMORY.md` and read. Want to delete a wrong memory? Edit the file. No admin UI required, no database schema to understand.

> A contrast worth noting: many comparable systems store memory in a vector database, then build a UI so users can view and manage it. OpenClaw inverts this — memory *is* files, the UI is just a view over files, and the vector store is only an accelerator. **When "the form humans can read and write" and "the form programs use efficiently" conflict, make the former the source of truth and the latter a derivative.**

### A more radical move: let the model write its own memory

OpenClaw pushes this theme further than *files as state*.

Just before context fills and compaction triggers, it runs a **silent flush turn** — no user-visible reply, just the model **writing what's worth keeping into memory files itself**.

The implication is worth chewing on:

```
Conventional: the framework decides what to remember → extract → write to store
OpenClaw:     the framework only decides "time to flush" → the model decides what → write to file
```

The framework handles **scheduling and gatekeeping** (when to flush, where, how much); **the cognitive work goes to the model** (which information matters, how to summarize).

This is a contested choice. Those who trust model judgment argue that *what's worth remembering* is inherently a task requiring semantic understanding, and rules will never beat letting the model decide. Skeptics point out the model may misremember, omit, or be induced by injected content to write garbage. OpenClaw picked the former and placed risk control elsewhere — at the permission boundary (Chapter 32) — consistent with its overall trust posture (§44.4).

> See Chapter 28 (memory system), §17.4 (context compaction).

## 44.3.2 Theme Five: Declarative Single Source + Multi-End Projection

Theme Four governs runtime state. Theme Five governs **knowledge in code that must be consistent in multiple places**.

### Case 1: One chat command, five frontends

Slash commands like `/new`, `/reset`, `/compact`, `/model` must appear in five places simultaneously:

```
              one declaration table (name, args, permissions, description)
                          │
    ┌──────────┬──────────┼──────────┬──────────┐
    ↓          ↓          ↓          ↓          ↓
 Discord    Telegram    Slack    text parsing   TUI
 native     native      native   (universal     completion
 commands   commands    commands  fallback)
```

Discord has a native slash-command registration API, Telegram has `setMyCommands`, Slack has its own, plus you must support typing `/compact` in any channel, plus TUI needs tab completion.

**Five hand-written copies would inevitably drift** — add a command and Discord has it while Telegram doesn't; rename an argument and TUI completion still shows the old one.

OpenClaw drives all five frontends from one declaration table, **and self-checks at build time**: if any frontend's projection disagrees with the table, CI fails. Drift is caught before merge, not after a user reports a bug.

> See §33.3.

### Case 2: Protocol schema, three-end codegen

Covered in §44.1: TypeBox schema → JSON Schema (runtime validation) + Swift models (native apps). Same shape.

### Case 3: Plugin manifest / execution separation

The plugin system cleanly separates *declaration* from *running*:

```
manifest (pure data, describes what the plugin wants)
    ↓ validation phase: reads data only, zero code execution
    ↓ on pass
runtime (jiti loads TypeScript source)
```

The security implication is in Chapter 32: **"validating config never becomes running code."** Checking a plugin's manifest doesn't execute any of its code — which is what makes *scan this plugin for safety* a safe operation.

### Case 4: Channel dock table vs. plugin runtime — light/heavy separation

The channel system has two registries:

| Registry           | Contents                                                    | Dependencies          |
| ------------------ | ----------------------------------------------------------- | --------------------- |
| **dock table**     | Pure data: channel ID, display name, icon, capability flags | none                  |
| **plugin runtime** | Actual connection and send/receive implementation           | heavy (platform SDKs) |

Listing "which channels are supported" in the UI needs only the dock table — no loading Discord.js, Baileys, or other tens-of-megabytes SDKs. **Separating light metadata from heavy implementation** keeps a high-frequency light operation (enumerate capabilities) from being dragged down by the heavy dependencies of implementing them.

> See Chapter 19.

## 44.3.3 Distilled: When to Use This Pattern

The shape shared by all four cases:

> **Any knowledge that must be consistent in multiple places should collapse into a data table plus generation or validation.**

The test is simple. Ask yourself:

> "If I add one new item, how many places do I have to change?"

Any answer greater than 1 is a candidate. Then there are two routes:

* **Generate (codegen)**: produce the other representations from the source automatically. Good when the target format is well-defined and automatable (protocol → Swift models).
* **Validate (self-check)**: allow multiple hand-written copies but compare them at build time. Good when target formats differ too much to generate uniformly (five command frontends with five different registration APIs).

Either works. **What never works is relying on "remember to change it in both places."** At 500,000 lines, "remembering" does not exist.

One counter-lesson: don't over-apply this. If two places are consistent only *coincidentally* rather than *essentially*, forcing convergence manufactures the wrong coupling — and when they should eventually diverge, you'll have to dismantle the abstraction first. The test is **whether they're semantically the same knowledge**, not whether they currently look alike.

***

## Section Summary

1. **Theme Four: files first, indexes derived.** Memory is Markdown, sessions are JSONL, config is JSON5, skills are Markdown; **the vector index is the only binary state and is defined as a rebuildable derivative**. Buys portability, git versionability, and human auditability.
2. OpenClaw goes further: **a silent flush turn before compaction lets the model write its own memory** — the framework schedules and gatekeeps, the cognitive work goes to the model.
3. **Theme Five: knowledge requiring multi-place consistency collapses into a data table plus generation/validation.** Four cases: one command table driving five frontends (build-time self-check against drift), three-end protocol codegen, plugin manifest/execution separation (validation executes zero code), and channel dock/runtime light-heavy separation.
4. The test is "how many places change when I add one item?" — greater than 1 means collapse it. **Pick codegen or build-time self-check; never rely on remembering.**
5. Counter-lesson: converge only when the pieces are **semantically the same knowledge**, or you manufacture the wrong coupling.
