A personal Markdown knowledge base with a local mirror and index, built to be queried cheaply by AI agents.
pip install dsh-kb==0.4.0 Copy PIP instructions
A personal knowledge base for AI agents: the source of truth lives on shared storage, each machine keeps a mirror and an index, retrieval is fast and works offline.
For one person (or a small team) whose knowledge already lives in a Markdown folder — on a network share, a NAS, or just a directory — and whose agent keeps re-reading it. Not a hosted product, not a multi-tenant service, not a note-taking UI: one machine, one bundle, one owner.
What it costs: Python ≥ 3.10 and one dependency (handrolled, itself standard-library only, no compiled extensions) — no daemon, no server, no database service, no root. One process per command. State (mirror + index) lives under ~/.dsh-kb and runs about 1.9× the size of the bundle; the index is local, so a share that is offline or slow costs you freshness, not availability.
Try it in two minutes — no share and no config file needed:
git clone https://github.com/LUgABeEEE/dsh-kb && cd dsh-kb bash examples/demo.sh # builds a throwaway bundle, indexes it, searches it The problem Personal knowledge — notes, lessons learned, decisions, project records — usually ends up scattered across session transcripts, a memory plugin, a pile of Markdown reports and a network share. So every agent session does the same thing: it re-reads several sources, stuffs raw text into the context window (one measured deployment re-sent ~230 000 tokens of context per request), and when it still cannot find the answer it says so.
one Markdown directory on shared storage ← single source of truth │ incremental pull ▼ local mirror + local FTS5 index ← milliseconds, works offline │ two narrow tools ▼ the agent asks for "path + line + 240-char snippet" The size of a result is independent of the size of the corpus — 200 pages or 10 000 pages, a search returns roughly 2.4 KB. That property is the whole point: growing the knowledge base does not make each lookup more expensive.
Pure Python, no compiled extensions, one dependency that has none of its own (handrolled — the stdlib-only toolkit this project's text/WebDAV/mount/import layers were extracted into):
pip install -e . # or simply PYTHONPATH=src python3 -m dsh_kb dsh-kb --version Quick start 1. Create a bundle (a directory on shared storage) /kb/ index.md # optional: progressive-disclosure front door log.md # optional: change log z0-public/ # public zone z1-restricted/ # restricted zone z2-sensitive/ # sensitive zone (not mirrored, not indexed) _incoming/ # proposals (the only place an agent writes) _meta/ # conventions, registry, receipts 2. Configure Configuration lives in ~/.dsh-kb/config.json — deliberately outside any checkout, so a public clone never carries your paths or private data:
{ "source": "auto", "mount": "/mnt/nas/kb", "local_root": "/srv/kb-share", "webdav_root": "https://nas.example.com:5000/webdav/kb", "stale_minutes": 15 } source=auto picks the first usable option in the order mount → local directory → Samba (smbclient) → WebDAV. Walking a local filesystem tree takes milliseconds; WebDAV costs one PROPFIND per directory (~55 ms on a consumer NAS), so prefer a mount when you have one. Paths may be written POSIX-style, as a Windows drive, or as a UNC path (Z:\kb, \\nas\share\kb, /mnt/nas/kb) — all are normalised.
Samba/CIFS mounts need extra care (we hit all of these in production): a mount can be rw and still read-only for the account; a dropped session makes the whole tree raise ESTALE; and timestamps have one-second granularity. All three are handled explicitly — see docs/deployment.md.
never defaults to credentials, .credentials, secrets, id_rsa, 密钥 ("keys"), 密钥库 and is extendable. All three enforcement points are covered by tests.
z3-skills is not built in. Register it in config.json with "index": false before moving files into it — an unregistered top-level directory is mirrored and indexed. See examples/config.json.
Shared flags are accepted before or after the subcommand.
Not everything labelled "diagnostic" is read-only. doctor is the one exception: it creates and deletes a probe file in home, and — when the source exposes it — writes and deletes a probe under _incoming/ on the share, to answer "can push work at all?". The probes are removed again; nothing else is written. Don't wire doctor into anything that must be strictly read-only.
Supersession is a first-class relation. A page may carry supersedes: [...] or superseded_by: in its front matter, and dsh-kb supersede-check reports the four ways that relation goes wrong: a link nobody answers (not reciprocal), a cycle, a dangling target, and a page claimed by two successors. The same relation is a gate on writes: push refuses a whole batch when a proposal's title collides with a live page and it declares neither supersedes: nor not_superseding: " " — --allow-undeclared is the explicit bypass. One prompt at the write door is cheaper than untangling two near-duplicates that both look current six months later.
Exit codes. diff and rag-check share one contract: 0 clean, 10 something needs a human, 11 local state is unreadable / the store is broken. rag-check --force without --prune is a usage error and exits 1 — it would override nothing, so it refuses rather than pretending it forced something.
dsh-kb diff compares two pairs, in two directions, and splits both by file kind (markdown / other) so image or JSON churn can't drown the .md diff:
dsh-kb rag-check compares the vector store against the index at page (path) and chunk (path + startline) granularity. The chunk view is what catches "one page, five chunks, only two embedded" — page-level counters stay at 0 for that shape. On an older store whose tables have no startline column the comparison degrades to page-level and says so in note.
WebDAV secrets are read only from the environment or a credentials file, never from config.json:
export DSH_KB_WEBDAV_USER=me export DSH_KB_WEBDAV_PASSWORD=... # or DSH_KB_WEBDAV_CREDENTIALS= export DSH_KB_WEBDAV_CERT=... DSH_KB_WEBDAV_KEY=... DSH_KB_WEBDAV_CA=... # mutual TLS export DSH_KB_WEBDAV_CONNECT=192.0.2.10 # connect to an IP, verify TLS against the CN Search behaviour CJK: indexing keeps the original text and appends adjacent character bigrams, so 挂载 matches 重新挂载 (a 2-character query, which a plain unicode61 tokenizer cannot do). Latin and identifiers: the original text is indexed verbatim, so z2-sensitive, page-000123.md and fts5 all match. Two passes: strict AND first, then a relaxed OR restricted to selective tokens. Results carry relaxed: true and dropped: [...] so the caller knows precision was traded for recall. Snippet location prefers the whole query as a literal, then word-boundary token hits — so searching mount -a reports that line, not the line holding /proc/mounts. Measured performance Single Linux host, bundled SQLite with FTS5, synthetic corpus (~3.4 KB per page, mixed Chinese and English):
The index stays near 1.9× because the FTS5 table stores no content (content='') and the text lives once in a separate meta table, joined back by rowid. Inlining the text into FTS5 measured 8.1×.
Positioning: a supplement, not standing context. Nothing is auto-injected and nothing is searched per turn — it is consulted once, when past decisions, environment facts or history are actually needed.
Two shapes, one implementation (dsh_kb.service), so their output cannot drift:
dsh-kb mcp # JSON-RPC on stdin/stdout, exposing search / read / status / skills Wiring it into DSH is one insert (other hosts: docs/agent-integration.md):
- id: mcp-kb name: '@deepseek-ai/dsh-mcp-client' config: serverName: kb transport: stdio command: python3 args: [-m, dsh_kb, mcp, --home, /srv/dsh-kb, --source, auto, --mount, /mnt/nas/kb] env: { PYTHONPATH: /opt/dsh-kb/src } Why the configuration goes in args, not env: some hosts scrub the environment of the MCP child process (credential-shaped names, stale prefixes). Command-line arguments are never scrubbed. Measured: with every DSH_KB_* variable removed and only args set, it still works against a real share.
Design choices — one optional deep flag, no mode knobs, no write tools, failures returned as tool results — are in docs/design.md.
Everything above is lexical. On top of it there is an opt-in layer that can add embedding hits, a cross-encoder, or a remote model — and it is deliberately outside the zero-dependency promise:
With the defaults, import dsh_kb never touches third-party code and a search is byte-identical to 0.1.0. Read docs/semantic-arm.md before enabling anything: it lists what each layer needs, where the models come from, and which of them send page text off the machine (deep does; that is the one to leave off if your bundle holds anything you would not paste into a chat window).
If the knowledge already exists somewhere else, import turns that export into pages instead of asking you to copy files by hand:
dsh-kb import --from ~/notes/obsidian --format obsidian --prefix notes # dry run dsh-kb import --from ~/notes/obsidian --format obsidian --prefix notes --write dsh-kb refresh Adapters for mem0, Obsidian, Notion's Markdown export, basic-memory, plain JSON/JSONL and dsh-kb's own records/v1. It is additive (never deletes), deterministic (a second run is a no-op), and refuses to write into z0-public without --allow-public. See docs/import.md.
Alpha (0.3.0) with 370 tests (unit, end-to-end, transport, CLI smoke and MCP — all offline):
python3 -m unittest discover -s tests -t . -v With the official MCP SDK installed, one extra interop test runs (a real client against this hand-rolled server); otherwise it skips.
knowledge-base markdown full-text-search sqlite-fts5 ai-agents local-first webdav
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




