-
Notifications
You must be signed in to change notification settings - Fork 0
wiki engine
The wiki engine is the Go package (internal/wiki) that owns:
- A wiki root directory (concepts/pages)
- A SQLite database file inside it (architecture/index-and-search)
- A per-process session ID for #page-locks
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.
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
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.
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().
- architecture/index-and-search — the database schema
- architecture/mcp-server — agent-facing wrapper
- architecture/http-api — browser-facing wrapper