[2026-04-03 Fri]
Crucible consists of four layers:
The LLM (Claude Code via the crucible skill) sits above all four layers, reading and writing files, querying the database via CLI commands, and maintaining the knowledge base.
The wiki graph database (.crucible/crucible.db) models three entity types
and their relationships. It holds nothing that is not in the committed
files: it is rebuilt from the wiki articles, .crucible/references.bib and .crucible/taxonomy.org, and a rebuild gives the
same database.
The schema is versioned (schema_version, now v4: v2 dropped peers, v3 added article_fts_joined, v4 tag_hierarchy). A command opening a project's
database migrates an older one first (get_db), since new code writes to tables an
older database lacks; a table added to the schema needs a new version,
or a database made before it would pass for current. Peers searched with
--all or served over MCP are only read,
and tolerate missing newer tables, so they are never migrated.
Primary source documents (papers, notebooks, data files).
Source rows are derived from references.bib and the files on disk. An entry
with a file field owns the row for that
file, keyed by its cite key, and the row's title, authors and date come
from the entry. Files in sources/notebooks/ and sources/data/ that no entry claims get a row
from a disk scan, keyed <stem> or,
when that key is already a bib key or another source's key, <stem>-<ext> (then -2, -3, …). An
entry without a file field gets no
row.
The bibliography is read with one brace-balanced parser (src/crucible/bibtex.py). Entries may be
delimited with braces or parentheses, compact one-line entries such as
doi.org returns are read correctly, and @comment, @string
and @preamble blocks are ignored. An entry
that is never closed is skipped (and reported by crucible lint) without swallowing the entries
after it.
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key |
| path | TEXT | Path relative to the project root (.crucible/sources/...) |
| title | TEXT | Source title |
| sourcetype | TEXT | pdf, web, notebook, data, other |
| shareable | INTEGER | 0 = external/gitignored, 1 = shareable |
| url | TEXT | Original URL (optional) |
| authors | TEXT | JSON array |
| date | TEXT | ISO date |
| ingestedat | TEXT | Timestamp |
| metadata | TEXT | JSON blob for extras |
Distilled wiki articles (the org files in wiki/).
The timestamps come from the article's properties drawer, so a
rebuild reproduces them: created_at from
:CREATED: and updated_at from :MODIFIED:, which falls back to :CREATED:. An article with only :MODIFIED: uses it for both. With neither, sync
uses the time of the sync, which a rebuild cannot reproduce (crucible lint reports it).
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key |
| path | TEXT | Path relative to the project root (.crucible/wiki/...) |
| title | TEXT | Article title |
| articletype | TEXT | concept, summary, comparison, method |
| status | TEXT | draft, reviewed, verified |
| createdat | TEXT | From :CREATED: |
| updatedat | TEXT | From :MODIFIED: |
| distillmodel | TEXT | Which LLM produced it |
| abstract | TEXT | Brief summary |
Named topics that articles can be tagged with, extracted from #+FILETAGS.
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Primary key |
| name | TEXT | Canonical name (unique) |
| aliases | TEXT | JSON array of alternate names |
Many-to-many: which sources an article was distilled from.
Many-to-many: which concepts an article covers.
(parent, child) pairs of tag names from
the #+TAGS: [ parent : child ... ] group
tags of .crucible/taxonomy.org, replaced
on every sync. Names are compared by the same key as concepts (case,
spaces, underscores and dashes ignored), so a group tag such as methods need not be any article's tag. Search
filters expand a tag to the closure of its children in the database
being searched, so a peer uses its own hierarchy; a peer database from
before this table existed has none.
Directed graph: explicit cross-references between articles, extracted
from [[file:...]] links in the org
files.
Tracks knowledge evolution: article Y was synthesized from articles
A, B, C at a given time. Extracted from the :DERIVED_FROM: property.
| Column | Type | Description |
|---|---|---|
| derivedid | INTEGER | The synthesized article |
| sourceid | INTEGER | One of its input articles |
| derivedat | TEXT | When the derivation happened |
The article_fts virtual table uses
SQLite FTS5 with porter stemming tokenization. It stores article path,
title, and full text content; queries match only title and content (a
column filter), since the words of a path such as .crucible/wiki/concepts/x.org are in every
article. Populated by crucible sync.
The embeddings table stores vector
representations generated by ollama.
| Column | Type | Description |
|---|---|---|
| articleid | INTEGER | References articles(id) |
| model | TEXT | Embedding model name |
| dimensions | INTEGER | Vector dimensionality (e.g. 768) |
| vector | BLOB | Packed float32 array |
| updatedat | TEXT | Timestamp |
An article has at most one embedding. The vector column is an untyped
BLOB, so models of any dimension can be stored; older databases whose
column was F32_BLOB(768) (with a libSQL
vector index) are migrated to this layout, keeping their rows, the next
time crucible embed or crucible search opens the table.
What is embedded is the article text with its org header (#+KEYWORD: lines, the title kept as the first
line) and drawers such as :PROPERTIES:
removed, truncated to its first 8000 characters. Long articles are
therefore represented by their opening sections only.
Standard SQLite full-text search with porter stemming. The query is
matched against article title and content. Each word is quoted, so FTS5
syntax in a query is literal text, except that a trailing * makes a word a prefix query. Results are
ranked by BM25 (SQLite's default FTS5 ranking).
--model, or else the model that most stored
embeddings were made with, so a query is embedded with the same model as
the articles unless asked otherwise.--url
or $CRUCIBLE_OLLAMA_URL, default http://localhost:11434/api/embed).vector_distance_cos ranks the
embeddings of that model and dimension; embeddings from other models are
ignored. If the model's stored vectors have a different dimension from
the query's, search stops with an error asking for crucible embed --force.This is a brute-force scan in SQL (no approximate-nearest-neighbour index), appropriate for knowledge bases up to a few thousand articles.
If the embedding service cannot be reached or lacks the model, the
default auto mode warns on stderr and
falls back to FTS; the explicit semantic
and hybrid modes exit with an error.
Both FTS and semantic search produce ranked lists. These are merged using Reciprocal Rank Fusion (RRF):
For each article appearing in either list: score = fts_weight / (k + fts_rank) + semantic_weight / (k + semantic_rank)
Where k = 60 (the standard RRF constant
that dampens rank differences). Articles found by both methods get
contributions from both, so they naturally rank higher.
The weights are configurable via --fts-weight and --semantic-weight.
FTS5 virtual tables cannot be queried across SQLite ATTACH boundaries
with the MATCH operator. Instead, search --all opens a separate SQLite connection
to each registered crucible's database and runs the query there. Results
from all connections are merged and re-ranked.
The lightweight parser in src/crucible/orgparse.py extracts metadata from
org files without requiring Emacs. It handles:
#+TITLE: keyword#+FILETAGS: keyword (colon-delimited
tags):PROPERTIES: drawers (key-value pairs
within drawer boundaries)[[file:...]] links (with optional
:: anchors)cite:, citep:, citet:
org-ref citationsIt is not a full org-mode parser. Complex structures (nested drawers, inline properties, dynamic blocks) are not supported but are not needed for crucible's metadata extraction.
crucible sync first reconciles the
sources table with references.bib and the
disk scan (see the sources table above), then operates in two passes to
avoid foreign key violations:
[[file:...]]), source links (:SOURCE_KEYS:), and derivation chains (:DERIVED_FROM:).The two-pass approach ensures all articles exist before cross-referencing.
Crucibles find each other through the global registry, ~/.crucible/registry.json, rather than through
anything stored in a project's database. Each entry maps a name to the
project's absolute path, with an optional description and the time it
was registered. crucible init, sync and update
register the current project, and crucible registry lists, adds, removes and
cleans entries (clean drops those with no
database on disk).
An entry also records its origin, where
the crucible comes from. On every registration it is read from the git
origin remote of the checkout the project
is in (git remote get-url origin); without
one, an origin given by hand (registry add --origin) is kept. URLs are
scrubbed of credentials before they are stored. crucible clone sets the origin to the URL it
cloned, and adds cloned_at; crucible pull sets pulled_at.
Crucibles from elsewhere travel as git repositories: the wiki, references.bib, notebooks and data are
committed, while the database and sources/external/ are not. clone runs git clone, rebuilds the database from the
committed files (the same rebuild get_root() does for a missing database) and
registers the result. pull fetches and
fast-forwards the clone, then syncs it. A clone is treated as a
read-only peer: pull refuses one with tracked changes or commits of its
own, except MANIFEST.md and index.org, which sync regenerates with the date
and pull resets before updating. Folding a clone's content into another
crucible is left to merge.
When --all is used on search or concepts, crucible opens a separate connection
to each other registered crucible's .crucible/crucible.db and runs the query against
it. Results are tagged with the crucible's registry name and merged with
local results. A peer left out (no database on disk, or one that fails
to open or query) is named in a warning on stderr; get_peers(skipped…)=, CrucibleDB.peer_warnings and EmbeddingIndex.warnings collect the reasons.
Peer results are untrusted. A peer's wiki was written by someone
else, and search output is often read by an agent, so a peer article is
data to be read, never instructions. _mark_peer_rows tags every row of an --all listing with _untrusted (and a peer's with _origin and _abs_path), and the text output ends with a
notice whenever a peer contributed. The skill tells agents not to act on
instructions found in peer content.
No data is written to other crucibles' databases. The connection is read-only by convention (SQLite's default mode allows writes, but crucible never issues write queries against those connections).
crucible mcp (src/crucible/mcp_server.py) serves crucibles to
other agents. CrucibleService holds the
queries and returns plain data, so it is tested without the MCP library;
build_server wraps it in a FastMCP server
with nine read-only tools and article resources, and the command runs it
over stdio or, with --http, as a
streamable HTTP app under uvicorn, behind a bearer-token ASGI middleware
when --token-env is given.
The crucibles served are fixed when the server starts, from the
command line; a client cannot name another registry entry. Every file
read goes through _resolve_article, which
resolves the path (following symbolic links) and refuses anything
outside .crucible/wiki/ (and, with --include-notebooks, .crucible/sources/notebooks/). Bibliography
entries are served without their file
field. Each call opens its own database connection, so the server holds
no connection between calls and sees a crucible pull or sync at once. Results carry the crucible's name,
and the server's instructions tell the client the content is reference
data, not instructions.