> 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/appendices/appendix-d-source-code-navigation-map.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# Appendix D: Source Code Navigation Map

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~355,000 tokens, Output \~9,000 tokens **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`) — every path verified individually

***

This appendix is a two-way index: *from code, find the chapter* and *from chapter, find the code*.

Use it with **§43.2** (subsystem table sorted by line count) and **§43.4** (four recommended reading paths).

## D.1 Dependency Map

```
                          ┌──────────────────┐
                          │   src/entry.ts   │
                          │ (process entry)  │
                          └────────┬─────────┘
                                   │
                    ┌──────────────┼──────────────┐
                    ▼              ▼              ▼
            ┌───────────┐  ┌──────────────┐  ┌──────────┐
            │  CLI cmds │  │   Gateway    │  │   TUI    │
            │  src/cli/ │  │ src/gateway/ │  │ src/tui/ │
            └───────────┘  └──────┬───────┘  └────┬─────┘
                                  │                │
              ┌───────────────────┼────────────┐   │
              ▼                   ▼            ▼   │
      ┌───────────────┐  ┌───────────────┐ ┌─────┐ │
      │ Inbound       │  │ Channel系统    │ │HTTP │ │
      │ pipeline      │  │ src/channels/ │ │ face│ │
      │src/auto-reply/│  │ + src/telegram│ └─────┘ │
      │ + src/routing/│  │   /discord/…  │         │
      │ + src/sessions│  └───────┬───────┘         │
      └───────┬───────┘          │                 │
              │                  │                 │
              ▼                  ▼                 │
      ┌──────────────────────────────────────┐     │
      │            Agent runtime              │◄────┘
      │            src/agents/                │
      │  ┌────────────────────┐ ┌──────────┐ │
      │  │ pi-embedded-runner/│ │  tools/  │ │
      │  │ (outer retry state │ │ (tool    │ │
      │  │  machine + attempt)│ │  family) │ │
      │  └─────────┬──────────┘ └────┬─────┘ │
      │            │                 │       │
      │  ┌─────────▼─────────────────▼─────┐ │
      │  │ @mariozechner/pi-*  (external)   │ │
      │  │ + src/providers/ (provider auth) │ │
      │  └──────────────────────────────────┘ │
      └──────────────────────────────────────┘
              │        │         │        │
     ┌────────┘        │         │        └────────┐
     ▼                 ▼         ▼                 ▼
┌──────────┐  ┌──────────────┐ ┌────────────┐ ┌──────────┐
│  Memory  │  │    Skills    │ │  Sandbox   │ │  Config  │
│src/memory│  │src/agents/   │ │src/agents/ │ │src/config│
│          │  │  skills/     │ │  sandbox/  │ │          │
└──────────┘  └──────────────┘ └────────────┘ └──────────┘
```

> **One thing that's easy to misread**: `src/channels/` in the diagram is the **abstraction layer and registries**; each platform's implementation lives in a **top-level directory of the same name** (`src/telegram/`, `src/discord/`, `src/slack/`…). And `src/web/` is actually **WhatsApp** (a historical name from the Baileys web protocol — see §19.4.6).

## D.2 Sequence Diagram: One Message's Full Path

```
User          Telegram      Gateway      Inbound pipeline   Agent      LLM API     Tools
 │                │            │               │             │           │          │
 │  send message  │            │               │             │           │          │
 │───────────────►│            │               │             │           │          │
 │                │ long poll  │               │             │           │          │
 │                │───────────►│               │             │           │          │
 │                │            │ debounce/gate/route          │           │          │
 │                │            │──────────────►│             │           │          │
 │                │            │               │ two-tier lane queue     │          │
 │                │            │               │────────────►│           │          │
 │                │            │               │             │ API call  │          │
 │                │            │               │             │──────────►│          │
 │                │            │               │             │ reply w/ tool calls  │
 │                │            │               │             │◄──────────│          │
 │                │            │               │             │ run tool  │          │
 │                │            │               │             │─────────────────────►│
 │                │            │               │             │ tool result          │
 │                │            │               │             │◄─────────────────────│
 │                │            │               │             │ API call again       │
 │                │            │               │             │──────────►│          │
 │                │            │               │             │ final reply          │
 │                │            │               │             │◄──────────│          │
 │                │            │ ReplyDispatcher serial chain │           │          │
 │                │            │◄────────────────────────────│           │          │
 │                │sendMessage │               │             │           │          │
 │                │◄───────────│               │             │           │          │
 │  receive reply │            │               │             │           │          │
 │◄───────────────│            │               │             │           │          │
```

Detailed breakdowns: §14.5 (seven inbound gates), §13.6 (queueing), §15.5 (agent run), §18.6 (outbound).

## D.3 Directory → Chapter Quick Reference

**Numbered per this book's 45-chapter structure.** 🔬 marks chapters with a "Source Deep Dive" section.

| Directory                                                                                                   | Chapters      | Core files                                                          |
| ----------------------------------------------------------------------------------------------------------- | ------------- | ------------------------------------------------------------------- |
| `src/entry.ts` / `src/cli/`                                                                                 | 33 🔬         | `run-main.ts`, `route.ts`, `program/command-registry.ts`            |
| `src/gateway/`                                                                                              | 11–12 🔬      | `server.impl.ts`, `server-methods.ts`, `protocol/schema/`           |
| `src/gateway/server/ws-connection/`                                                                         | 12 🔬         | `message-handler.ts` (1,242 lines; where four auth layers converge) |
| `src/gateway/node-registry.ts`                                                                              | 27 🔬         | Reverse RPC and pendingInvokes                                      |
| `src/routing/`                                                                                              | 14 🔬         | `resolve-route.ts`, `session-key.ts`, `bindings.ts`                 |
| `src/auto-reply/`                                                                                           | 13–14, 18 🔬  | `dispatch.ts`, `inbound-debounce.ts`, `command-auth.ts`, `reply/`   |
| `src/auto-reply/commands-registry.data.ts`                                                                  | 33 🔬         | Chat-command single source of truth (777 declaration lines)         |
| `src/sessions/`                                                                                             | 13 🔬         | `input-provenance.ts`, `send-policy.ts`, `session-key-utils.ts`     |
| `src/process/command-queue.ts`                                                                              | 13 🔬         | The system's only execution queue (two-tier lanes)                  |
| `src/agents/`                                                                                               | 15–17, 22 🔬  | `pi-embedded-runner/`, `pi-tools.ts`, `pi-embedded-subscribe.ts`    |
| `src/agents/pi-embedded-runner/run/attempt.ts`                                                              | 15 🔬         | 2,096-line assembly site (**don't start here**)                     |
| `src/agents/pi-extensions/`                                                                                 | 17 🔬         | `compaction-safeguard.ts`, `context-pruning/pruner.ts`              |
| `src/agents/auth-profiles/`                                                                                 | 16 🔬         | `order.ts`, `usage.ts` (rotation and cooldown curves)               |
| `src/agents/model-fallback.ts`                                                                              | 16 🔬         | `resolveCooldownDecision`                                           |
| `src/providers/`                                                                                            | 16            | `github-copilot-auth.ts` and other per-provider auth                |
| `src/agents/tools/`                                                                                         | 22 🔬         | `message-tool.ts`, `browser-tool.ts`, `memory-tool.ts`              |
| `src/agents/bash-tools.exec*.ts`                                                                            | 22 🔬         | exec's three dimensions and two-phase approval                      |
| `src/agents/sandbox/`                                                                                       | 22 🔬, 32     | `docker.ts`, `fs-bridge.ts`, `validate-sandbox-security.ts`         |
| `src/channels/`                                                                                             | 19 🔬         | `dock.ts` (light), `plugins/` (heavy), `mention-gating.ts`          |
| `src/telegram/` `src/discord/` `src/slack/` `src/web/`(=WhatsApp) `src/signal/` `src/imessage/` `src/line/` | 20 🔬         | `polling-session.ts`, `monitor/`, `draft-stream.ts`                 |
| `extensions/`                                                                                               | 21 🔬         | 40 packages; start with `mattermost` or `llm-task`                  |
| `src/plugins/` `src/plugin-sdk/`                                                                            | 21 🔬         | `loader.ts`, `manifest.ts`, `types.ts`                              |
| `src/browser/`                                                                                              | 24 🔬         | `pw-session.ts`, `navigation-guard.ts`, `chrome.ts`                 |
| `src/canvas-host/`                                                                                          | 25            | `server.ts`, `a2ui.ts`, `file-resolver.ts`                          |
| `src/cron/`                                                                                                 | 26 🔬         | `service/timer.ts`, `isolated-agent/run.ts`, `heartbeat-policy.ts`  |
| `src/infra/heartbeat-runner.ts`                                                                             | 26 🔬         | The heartbeat's yielding and traceless design                       |
| `src/node-host/`                                                                                            | 27 🔬, App. F | `runner.ts`, `exec-policy.ts`, `invoke-system-run.ts`               |
| `src/memory/`                                                                                               | 28 🔬         | `manager.ts`, `hybrid.ts`, `search-manager.ts`                      |
| `src/agents/skills/`                                                                                        | 29 🔬         | `types.ts`, `config.ts`, `env-overrides.runtime.ts`                 |
| `src/hooks/`                                                                                                | 30 🔬         | `internal-hooks.ts`, `fire-and-forget.ts`, `bundled/`               |
| `src/config/`                                                                                               | 31 🔬         | `io.ts`, `validation.ts`, `paths.ts`, `legacy*.ts`                  |
| `src/secrets/`                                                                                              | 32 🔬         | `resolve.ts`, `runtime.ts` (dual snapshot), `audit.ts`              |
| `src/security/`                                                                                             | 32 🔬         | `audit.ts`, `dm-policy-shared.ts`, `external-content.ts`            |
| `src/pairing/`                                                                                              | 32 🔬         | `pairing-store.ts`, `pairing-challenge.ts`                          |
| `src/logging/`                                                                                              | 34            | `redact.ts`, `subsystem.ts`                                         |
| `src/media/` `src/media-understanding/` `src/link-understanding/` `src/tts/`                                | 34 🔬         | `apply.ts`, `runner.ts`, `detect.ts`                                |
| `ui/`                                                                                                       | 35            | `ui/src/main.ts`, `ui/src/ui/gateway.ts`, `ui/src/ui/storage.ts`    |
| `apps/`                                                                                                     | 36            | `macos/`, `ios/`, `android/`, `shared/OpenClawKit/`                 |
| `src/daemon/`                                                                                               | 37, App. F    | `service.ts`, `launchd.ts`, `systemd.ts`, `schtasks.ts`             |
| `src/agents/subagent-*.ts`                                                                                  | 39 🔬         | `subagent-spawn.ts`, `announce-idempotency.ts`                      |
| `src/acp/`                                                                                                  | 40 🔬         | `server.ts`, `translator.ts`, `session-manager.ts`                  |
| `src/tui/`                                                                                                  | 41            | `commands.ts`, `gateway-chat.ts`                                    |

## D.4 Key Documents at the Repo Root

Read these before the code (§43.4.1's Path One):

| File                            | Read it to answer                                                                           |
| ------------------------------- | ------------------------------------------------------------------------------------------- |
| `VISION.md`                     | What the project wants — and explicitly doesn't                                             |
| `docs/concepts/architecture.md` | Gateway star topology; control/data plane split                                             |
| `docs/concepts/agent.md`        | Personality files, sessions, workspace model                                                |
| **`SECURITY.md`**               | **Required.** The trust model dictates why all the code looks the way it does (§44.4)       |
| `AGENTS.md`                     | How this repository actually gets developed (§43.3)                                         |
| `docs/pi.md`                    | The division of labor between OpenClaw and the pi engine                                    |
| `docs/concepts/queue.md`        | The official definition of the three queueing semantics                                     |
| `CHANGELOG.md`                  | When a feature was added or removed (**very useful** — e.g. the `soul-evil` removal record) |

## D.5 Three Verification Techniques

**1. Use test filenames as the spec.** When a branch confuses you, `ls` the sibling `.test.ts` files first — all 1,935 test names are deliberately written as behavior descriptions (§43.2.1, §43.4.4).

**2. Use `CHANGELOG.md` to check whether a feature is alive.** That's how the revision of this book discovered the `soul-evil` hook had been removed (§32.5.2). Anything the docs describe but the code doesn't contain: search the changelog first.

**3. Watch out for `.js` in imports.** The source is TypeScript, but ESM import statements are written with `.js`:

```ts
import { resolveCommandAuthorization } from "../command-auth.js";  // the file is .ts
```

Looking for a `.js` file on disk won't find anything — drop the extension and look again.

***

## Appendix Summary

* **`src/channels/` is the abstraction layer**; platform implementations live in top-level directories of the same name. **`src/web/` is WhatsApp, not WebChat.**
* The quick reference is numbered per this book's 45-chapter structure; 🔬 marks chapters with a Source Deep Dive.
* Read `SECURITY.md` before the code; use `CHANGELOG.md` to check whether a feature is alive; use test filenames to learn why a branch exists.
