Skip to content

wiki engine

aniongithub edited this page May 19, 2026 · 1 revision

title: Wiki engine type: component

Wiki engine

The wiki engine is the Go package (internal/wiki) that owns:

It exposes a small API (Open, GetPage, CreatePage, UpdatePage, DeletePage, MovePage, Search, Context, Reindex, AllLinks) that the architecture/http-api and architecture/mcp-server both call.

Indexing

On every read/write the engine keeps the index in sync. On Open() it runs an incremental Reindex that compares disk mtimes (nanosecond precision) against indexed mtimes and only touches changed rows.

sequenceDiagram
    participant Agent
    participant MCP
    participant Engine
    participant FS as File system
    participant DB as SQLite
    Agent->>MCP: update_page("foo", body)
    MCP->>Engine: UpdatePage(ctx, "foo", body)
    Engine->>Engine: normalizePagePath("foo")
    Engine->>Engine: acquireLock("foo")
    Engine->>FS: write foo.md
    Engine->>DB: INSERT OR REPLACE into pages + links
    Engine->>Engine: releaseLock("foo")
    Engine-->>MCP: ok
    MCP-->>Agent: ok
Loading

Path normalization

Every public method normalizes its pagePath argument:

  • Trim leading / and ./
  • Collapse //, ./, trailing /
  • Strip a trailing .md
  • Reject .. traversal

This prevents design/rationale where /foo and foo resolve to the same on-disk file but get stored under different primary keys.

Page locks {#page-locks}

A page_locks table holds (path, holder, acquired) rows. Each write acquires a lock for its path before touching disk. Locks survive across processes — if two mind-map processes share a wiki dir, only one can write to a given page at a time. Stale locks older than 5 minutes are evicted on Open().

See also

Clone this wiki locally