-
Notifications
You must be signed in to change notification settings - Fork 4
Architecture Overview
Language: English · 简体中文
LWC is a local-first Rust CLI organized around one rule: SQLite owns knowledge; every other representation is derived or deployment-local. This boundary lets Agents use richer retrieval and graph capabilities without making an optional service the source of truth.
Read this page when evaluating a change that crosses storage, indexing, graph, Agent integration, or recovery boundaries.
Agent / human / script
|
v
Clap CLI dispatcher -------- stdio MCP server -------- AgentTarget installer
| | |
+----------- bounded commands and typed JSON --------+
|
v
canonical Store (SQLite)
Sources · Pages · links
ingest · tags · retrieval
operations · changesets
|
+----------------------+----------------------+
v v v
generated Markdown document graph search projections
human-readable Grafeo/SurrealDB FTS5 + spans
|
v
durable Work
Project source files --------------------------> CodeGraph index
separate, project-local
The binary has three front-door layers:
-
cli::definitionsdeclares the public command grammar with Clap. -
cli::dispatchresolves scope, enforces live/draft boundaries, opens the required store mode, and routes the command. -
store,work,external_graph,codegraph,agent,mcp,trans, andviewimplement domain behavior.
Commands return structured JSON on standard output and structured errors on standard error. Human-readable text is kept inside fields rather than replacing the machine contract.
Hidden worker execution is an internal transport. Users operate it only through work list, status, watch, cancel, and resume.
Each Wiki has one wiki.db. Canonical writes use SQLite transactions and update all inseparable records together:
- Source snapshot and pending ingest job;
- Page body, citations, provenance, links, search document, spans, and operation record;
- tag policy and membership;
- retrieval weights or query-fingerprint feedback;
- changeset state and inverse metadata.
Source content is immutable and content-addressed. Pages are maintained mutable knowledge. Their relationship is explicit through page_sources; neither representation silently replaces the other.
Store identity contains a stable store ID and a changing revision fingerprint. Changesets, checkpoints, spans, and concurrent restore checks use these identities to detect stale or mismatched state.
Contentless SQLite FTS5 tables hold normalized Page, Source, passage, and sentence terms. Exact span records store UTF-8 byte ranges and content fingerprints. Reindexing can recreate this state from canonical documents.
The .lwc/wiki/ tree is generated for people and Markdown-aware tooling. It is not an alternate write path. Materialization uses staged files and replacement semantics so a failure is recoverable without redefining canonical state.
Grafeo and SurrealDB sidecars receive projections of canonical Page, Source, link, citation, and semantic-relation facts. Mutations append dirty document keys to durable Work. graph verify compares the selected sidecar with canonical projection keys and fingerprints.
CodeGraph indexes checked-out project files, not Wiki records. LWC pins and verifies one runtime version in the user's global cache while keeping each project's database under .lwc/codegraph. It remains a separate evidence plane even though MCP exposes it through the same lwc_explore tool.
The following state controls one installation rather than Wiki knowledge:
-
.lwc/config.jsonand the global~/.lwc/config.json; - Work request and progress files;
- document-graph sidecars;
- CodeGraph runtime and project index;
- AgentTarget receipts and host configuration;
- generated Viewer assets embedded in the binary.
Checkpoint restore therefore replaces wiki.db, then rebuilds or requeues derived projections under the current deployment configuration.
A changeset is a sparse SQLite overlay bound to one live store and base revision:
.lwc/wiki.db live canonical store
.lwc/changesets/<name>.db sparse draft records
.lwc/changesets/draft-<name>/ isolated Work and graph runtime
Draft reads compose live baseline with touched draft entities. Commit does not replace the whole live database; it validates fingerprints and merges one exact patch under the live write lock. This preserves unrelated live writes and supports a touched-entity inverse.
Read commands open current-format stores read-only. A store that requires a supported migration is opened through the writable migration path before the requested command proceeds.
Mutations reject --scope all. Deployment-local configuration, Viewer, checkpoint, CodeGraph lifecycle, and conversion also reject changeset selectors when they cannot participate in the draft's atomic contract.
MCP deliberately stays read-only. Missing indexes become readiness guidance or typed unavailable states; an MCP request never downloads a runtime, enables a graph, or mutates memory.
LWC distinguishes three outcomes:
- No canonical write: validation, conflict, or lock acquisition failed.
- Canonical success: the transaction committed and every required projection completed or was queued.
- Canonical partial success: knowledge committed, but graph queueing, cleanup, or materialization failed.
The third case returns explicit fields such as canonical_committed or checkpoint_restored plus an exact recovery command. Retrying a higher-level operation is safe only when its documented idempotent recovery path says so.
Derived failure does not roll back valid canonical knowledge by pretending it never committed. Conversely, a successful Work does not prove the graph is consistent until verification passes.
Architecture-level safeguards include:
- canonical path checks and symlink rejection for stores, drafts, Work, config, and sidecars;
- project-root containment for explicit project selection and CodeGraph paths;
- create-new or atomic replacement for owned files;
- secret scanning before Source ingest, conversion arguments, and selected integration writes;
- loopback-only, GET/HEAD Viewer routes;
- one read-only MCP tool with explicit project path validation;
- ownership receipts and marker-bounded edits for Agent hosts.
These controls do not make an untrusted local account safe. LWC assumes the user authorizes the current process to read the selected project and user-level integration files.
| Component | Owns | Does not own |
|---|---|---|
| Store | Canonical knowledge and transactional invariants | External graph availability |
| Work | Durable execution state for long mutations | Canonical business decisions |
| External graph adapter | Projection, queries, and verification | Source truth |
| CodeGraph adapter | Runtime pinning and project code index boundary | Wiki memory |
| MCP | Bounded read-only exploration | Initialization or mutation |
| AgentTarget adapter | Official host files and LWC-owned fragments | UI-only settings or broad trust approval |
| Viewer | Local inspection | Editing, migration, or index construction |
| Trans adapter | Safe subprocess conversion | Automatic Source ingest |
Before adding a capability, answer:
- Which canonical record proves the fact?
- Is the new state canonical, derived, or deployment-local?
- What transaction makes inseparable writes atomic?
- How is derived state rebuilt and verified?
- What happens after canonical commit but before projection finishes?
- Which scope and project boundary authorize the operation?
- Can the same need be served by an existing Store, Work, or AgentTarget path?
If these answers are unclear, the change is not ready to cross the architecture boundary.
Next: Storage and data model
LWC Wiki
- Home · 首页
- Project overview · 项目简介
- Basic concepts · 基本概念
- Use cases · 应用场景
- Installation and upgrades · 安装与升级
- Quick start · 快速开始
- Persistent memory · 持久记忆体系
- Agent workflow and memory policy · Agent 工作流与主动记忆策略
- Sources and ingestion · 来源与知识整合
- Wiki pages and provenance · Wiki 页面与来源证明
- Search and context · 搜索与上下文载入
- Document knowledge graph · 文档知识图(记忆图网)
- Code graph · 代码图
- Word graph · 词图
- Tags and strong context · 标签与强上下文
- Document conversion · 文档转换
-
MCP server and
lwc_explore· MCP 服务与lwc_explore - Skills, Hooks, and Instructions · Skills、Hooks 与 Instructions
- AgentTarget installation · AgentTarget 安装与集成
- Changesets · Changeset 原子变更
- Work system · Work 任务系统
- Checkpoints and rollback · Checkpoint、恢复与回滚
- Read-only Viewer · 只读可视化界面
- Architecture overview · 总体架构
- Storage and data model · 存储与数据模型
- Retrieval and indexing · 检索与索引设计
- Graph projection and performance · 图投影与性能设计
- MCP, Hooks, and AgentTarget design · MCP、Hook 与 AgentTarget 设计
- Safety and trust boundaries · 安全模型与信任边界
- Maintenance and diagnostics · 维护与诊断
- Troubleshooting and FAQ · 故障排查与常见问题
- Migration and compatibility · 迁移与版本兼容
- Support and issue reporting · 获取帮助与问题反馈
- CLI and configuration reference · CLI 与配置参考
- JSON output and error contract · JSON 输出与错误契约
- Limits and glossary · 系统限制与术语表
- Contributing and development · 贡献与开发指南
- Testing and release process · 测试与发布流程
- Wiki style guide · Wiki 编写规范