Metadata-Version: 2.5
Name: crucible-llm
Version: 0.2.0
Summary: LLM-compiled knowledge base with org-mode wiki and graph database
Project-URL: Homepage, https://github.com/jkitchin/crucible
Project-URL: Repository, https://github.com/jkitchin/crucible
Project-URL: Issues, https://github.com/jkitchin/crucible/issues
Author-email: John Kitchin <jkitchin@andrew.cmu.edu>
License-Expression: MIT
License-File: LICENSE
Keywords: claude,knowledge-base,llm,org-mode,wiki
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Text Processing :: Markup
Requires-Python: >=3.11
Requires-Dist: click>=8.0
Requires-Dist: filelock>=3.0
Requires-Dist: libsql>=0.1.0
Description-Content-Type: text/markdown

# Crucible: LLM-Compiled Knowledge Base

[![](https://img.shields.io/pypi/v/crucible-llm.svg)](https://pypi.org/project/crucible-llm/) [![](https://github.com/jkitchin/crucible/actions/workflows/tests.yml/badge.svg)](https://github.com/jkitchin/crucible/actions/workflows/tests.yml)

![](https://raw.githubusercontent.com/jkitchin/crucible/main/crucible.png)

# Overview

Crucible is a personal knowledge base system where primary sources (papers, notebooks, data) are ingested and distilled by an LLM into a structured, interlinked org-mode wiki. The wiki is the LLM's domain: you rarely edit it directly. Instead, you converse with Claude, and it reads, writes, and maintains the wiki on your behalf.

The core idea, inspired by Andrej Karpathy's LLM knowledge base pattern, is that raw data from various sources is collected, then compiled by an LLM into a wiki of org-mode files, then operated on by various CLI commands to do Q&A and to incrementally enhance the wiki. Everything is viewable in Emacs via scimax.

Key design principles:

- **Separation of concerns**: primary sources (which may be copyrighted) are kept separate from distilled content (which is shareable).
- **Org-mode native**: all wiki articles use org-mode with scimax conventions, org-ref citations, properties drawers, and filetags.
- **Graph database**: a SQLite database tracks the relationships between sources, articles, concepts, and links, enabling structured queries that grep cannot do.
- **Hybrid search**: combines FTS5 keyword search with ollama vector embeddings for meaning-based retrieval, merged via reciprocal rank fusion.
- **Interoperability**: every crucible on a machine is listed in a global registry, so one can search the others (`search --all`), and one crucible can be merged into another (`crucible merge`).
- **Knowledge evolution**: derivation chains track how articles are synthesized from other articles over time.

# Installation

From PyPI:

``` bash
pip install crucible-llm
crucible --version
```

Or from source for development:

``` bash
git clone https://github.com/jkitchin/crucible.git
cd crucible
pip install -e .
```

Then initialize a new crucible project and wire it into Claude Code:

``` bash
cd /path/to/your/project
crucible init --root .
crucible install    # installs Claude Code skill + CLAUDE.md directive
```

The `install` command does three things:

1.  Copies the skill into `~/.claude/skills/crucible/`
2.  Generates a manifest summarizing the knowledge base contents
3.  Adds a directive to `~/.claude/CLAUDE.md` so agents know to check the crucible before answering domain-specific questions

`init` registers the project and installs the skill, but only `install` writes the `~/.claude/CLAUDE.md` directive. There is one directive, so a new crucible does not take it over until you run `install` in it.

Re-running `install` (or `update`) keeps a copy of a skill file you have edited as `SKILL.md.bak`. To remove: `crucible uninstall`, which deletes only the files crucible installed.

## Installing the skill with knowhow

The skill lives in `skills/crucible/SKILL.md` and follows the [Agent Skills specification](https://agentskills.io/specification), so it can also be installed with [knowhow](https://github.com/jkitchin/knowhow) (or `npx skills`) for Claude Code and other agents (VS Code, Codex, OpenCode, Gemini CLI, Cursor):

``` bash
uvx knowhow add jkitchin/crucible --skill crucible        # this project
uvx knowhow add jkitchin/crucible --skill crucible -g     # global
# or: npx skills add jkitchin/crucible --skill crucible
```

The skill still needs the `crucible` CLI on your PATH. Installing it this way does not generate the manifest or the `~/.claude/CLAUDE.md` directive, so run `crucible install` inside your project if you want those too. Contributors can check the skill with `uvx knowhow validate .`.

For semantic search, you also need ollama running with an embedding model:

``` bash
ollama pull nomic-embed-text
crucible embed
```

# Directory Layout

A crucible project keeps everything in a `.crucible/` directory at its root:

``` example
your-project/
  CLAUDE.md                Conventions for agents working in the project
  .gitignore               Excludes crucible.db and sources/external/
  .crucible/
    crucible.db            Wiki graph database (SQLite, regenerable)
    references.bib         Bibliography of ingested sources
    sources/
      external/            Copyrighted material (gitignored)
        pdfs/              Academic papers, reports
        web/               Web clippings
      notebooks/           Your own ELN entries (shareable)
      data/                Your own experimental data (shareable)
    wiki/
      index.org            Auto-generated master index
      MANIFEST.md          Summary for agent discovery
      concepts/            One topic per file
      summaries/           One per ingested source
      comparisons/         Cross-source analysis
      methods/             Technique and methodology articles
```

The global registry of all crucibles on the machine is `~/.crucible/registry.json`. Because `~/.crucible/` is the registry, the home directory itself cannot be a crucible project.

This repository holds the Python package (`src/crucible/`), the agent skill (`skills/crucible/SKILL.md`, Agent Skills spec), the documentation (`docs/`) and the tests (`tests/`).

# Quick Start

See [the tutorial](https://kitchingroup.cheme.cmu.edu/crucible/docs/tutorial.html) for a complete walkthrough. The short version:

``` bash
# Ingest a source
crucible ingest paper.pdf

# Or from the web
curl -sL "URL" | pandoc -f html -t org | crucible ingest - -t "Title" --type web

# Or a batch
crucible ingest "papers/*.pdf"

# Ask Claude to distill it
# (Claude reads the source, proposes articles, you approve, it writes them)

# Sync the database
crucible sync

# Generate embeddings for semantic search
crucible embed

# Search
crucible search "activation energy"                    # hybrid (auto)
crucible search "how does temperature affect rate"     # finds by meaning
crucible search "catalyst" --mode fts                  # keyword only

# Navigate
crucible concepts                # list all topics
crucible concept thermodynamics  # articles on a topic
crucible backlinks concepts/activation-energy.org   # paths: wiki-, root- or cwd-relative
crucible related concepts/activation-energy.org
crucible history comparisons/synthesis.org        # derivation chain

# Maintain
crucible lint                    # find problems; exits 1 on errors (--strict: warnings too)
crucible suggest                 # find opportunities
crucible index                   # regenerate index
crucible publish                 # export as HTML site
crucible delete wiki/concepts/old.org   # remove an article or source
crucible merge other-crucible    # fold another crucible into this one
```

# Documentation

The documentation is published at <https://kitchingroup.cheme.cmu.edu/crucible/>.

- [Tutorial](https://kitchingroup.cheme.cmu.edu/crucible/docs/tutorial.html): step-by-step guide to ingesting your first source and building a wiki
- [Command Reference](https://kitchingroup.cheme.cmu.edu/crucible/docs/commands.html): complete documentation for every CLI command
- [Architecture](https://kitchingroup.cheme.cmu.edu/crucible/docs/architecture.html): database schema, search algorithms, and design decisions
- [Skill Guide](https://kitchingroup.cheme.cmu.edu/crucible/docs/skill.html): how the Claude Code skill works and how to customize it

# Using Crucible with Claude Code

Crucible is designed to be used through [Claude Code](https://claude.com/claude-code). After installation, Claude automatically knows about your knowledge base and uses it to answer questions, distill sources, and maintain the wiki.

## Setup

Running `crucible install` does three things that wire crucible into Claude Code:

1.  Copies the crucible skill into `~/.claude/skills/crucible/`, which teaches Claude how to ingest sources, write wiki articles, and navigate the graph database.
2.  Generates `MANIFEST.md`, a summary of the knowledge base contents that Claude reads to decide when the wiki is relevant.
3.  Adds a directive to `~/.claude/CLAUDE.md` that tells Claude to check the crucible before answering domain-specific questions.

The skill triggers automatically when you say things like "ingest this", "what do we know about", "search the wiki", "add to crucible", or "distill this source". You do not need to invoke it explicitly.

## Typical Session

A typical conversation looks like this:

``` example
You:    What do we know about activation energies on platinum surfaces?
Claude: [searches the wiki, reads relevant articles]
        Based on the wiki, there are three articles covering this topic...
        [synthesized answer with citations to wiki articles]

You:    Ingest this new paper [attaches PDF]
Claude: [registers the source, reads it, proposes articles]
        I found three key findings. I propose:
        - Update the activation-energy concept article with the new data
        - Create a summary article for this paper
        Shall I proceed?

You:    Yes
Claude: [writes the articles, runs crucible sync]
        Done. Created wiki/summaries/smith2026.org and updated
        wiki/concepts/activation-energy.org with the new measurements.

You:    That comparison you just made between the two papers is interesting.
        Capture that as an article.
Claude: [writes a comparison article with DERIVED_FROM properties]
```

The key insight is that your explorations accumulate. Every question you ask, every source you ingest, and every insight you capture makes the knowledge base richer for next time.

## Browsing Outside Claude Code

You can also browse the wiki in a web browser:

``` bash
crucible browse
```

This launches a local HTTP server that renders org-mode articles as HTML with working cross-links, citation tooltips, and a navigable sidebar. The about page (`/_about`) shows project paths, statistics, and the global registry.

# Use Cases

## Literature Review for a Proposal

When preparing a grant proposal or review paper, you typically need to digest dozens of papers and synthesize them into a coherent narrative. Start by ingesting a batch of PDFs with `crucible ingest "papers/*.pdf"`, then ask Claude to distill each one into summary and concept articles. As the wiki grows, `crucible suggest` identifies comparison opportunities where multiple summaries share concepts but no cross-source analysis exists yet. You can then ask Claude to write comparison articles that synthesize findings across papers, and use `crucible search` to quickly find what the wiki knows about specific topics. The result is a structured, citation-backed knowledge base you can query as you write, rather than a stack of annotated PDFs you have to re-read.

## Lab Notebook as Living Knowledge

Experimental notebook entries often contain insights that only become valuable months later when a new experiment connects to an old one. By ingesting notebook entries with `crucible ingest entry.org --type notebook`, each experiment gets linked to concepts and cross-referenced with prior work. Over time, `crucible related` surfaces connections you might not have noticed: two experiments six months apart that share a concept, or a measurement that contradicts an earlier assumption. Running `crucible viz` produces a force-directed graph of your experimental knowledge, making clusters and gaps visible at a glance. When you synthesize insights across experiments, `crucible history` traces the derivation chain so you can always find which raw observations led to which conclusions.

## Research Group Cross-Pollination

In a research group, each member works on their own project but the work often overlaps in ways nobody tracks. With crucible, each group member maintains their own instance on their own project directory. The PI registers all of them with `crucible registry add student-name /path/to/their/crucible`, and can then run `crucible search "keyword" --all` to query across every group member's knowledge base simultaneously. The results show which crucible each hit came from, making it easy to say "talk to Alex, they have three articles on that catalyst." Copyrighted sources stay local to each instance (they are gitignored), so only the distilled wiki content is visible to others.

## Preparing for a Student Meeting

Before a one-on-one meeting with a student, a PI can use the student's crucible to quickly build context. Running `crucible concepts` shows what topics the student has been working on, while `crucible orphans` reveals articles that lack connections to the broader knowledge base, often a sign of under-explored directions. `crucible lint` flags undigested sources (papers the student ingested but never distilled), missing cross-links, and articles without proper metadata. `crucible suggest` goes further, recommending new concept articles for topics that appear across multiple summaries and identifying potential comparison articles. Together, these commands give the PI a structured picture of where the student's knowledge base is strong, where it has gaps, and what questions to ask.

# How It Works

## The Distillation Loop

The fundamental workflow is a loop:

1.  **Ingest**: bring in a primary source (PDF, web article, notebook entry, data)
2.  **Distill**: Claude reads the source and writes org-mode wiki articles
3.  **Sync**: the database is updated from the wiki files
4.  **Query**: search, navigate, and ask questions against the wiki
5.  **Capture**: conversation insights are written back as new articles
6.  **Maintain**: lint, suggest, and index to keep the wiki healthy

Each pass through the loop enriches the knowledge base. Your explorations and queries always "add up" in the crucible.

## Source Types

| Type     | Storage                | Gitignored | Examples                  |
|----------|------------------------|------------|---------------------------|
| pdf      | sources/external/pdfs/ | Yes        | Papers, reports           |
| web      | sources/external/web/  | Yes        | Blog posts, documentation |
| notebook | sources/notebooks/     | No         | Your own ELN entries      |
| data     | sources/data/          | No         | CSV, JSON, HDF5, images   |

## Article Types

| Type       | Directory         | Purpose                    |
|------------|-------------------|----------------------------|
| concept    | wiki/concepts/    | Single topic or idea       |
| summary    | wiki/summaries/   | Distillation of one source |
| comparison | wiki/comparisons/ | Cross-source analysis      |
| method     | wiki/methods/     | Technique or methodology   |

Each article has a properties drawer on its top heading with `:ARTICLE_TYPE:`, `:SOURCE_KEYS:` (the cite keys of its sources), `:STATUS:`, `:CREATED:` and `:MODIFIED:` (updated on every substantive edit). The database takes an article's dates from `:CREATED:` and `:MODIFIED:`, so a rebuild reproduces them.

## Search Modes

Crucible offers three search modes, with `auto` (hybrid when embeddings exist, FTS otherwise) as the default:

- **FTS**: keyword search using SQLite FTS5 with porter stemming. Fast, exact.
- **Semantic**: vector similarity using ollama embeddings. Finds conceptually related content even without keyword overlap.
- **Hybrid**: combines both using Reciprocal Rank Fusion (RRF). Articles found by both methods rank highest. This is the default when embeddings exist.

## Multiple Crucibles

Every crucible on the machine is recorded in the global registry (`~/.crucible/registry.json`), which `crucible init` and `crucible sync` keep up to date. Others can be added by hand and queried together:

``` bash
crucible registry add lab-shared /path/to/shared/crucible
crucible registry add student /path/to/student/crucible
crucible registry list
crucible search "catalyst design" --all    # searches everywhere
crucible concepts --all                    # unified concept list
```

Each crucible retains full independence. Queries run against separate database connections, so there is no risk of corrupting another crucible's data. To combine two crucibles for good, `crucible merge` copies another crucible's sources, articles and bibliography into this one; it refuses a crucible whose sources or bibliography entries repeat a cite key, which `crucible lint` reports so you can fix them first.

## Knowledge Evolution

When Claude synthesizes insights from existing wiki articles during a conversation and you say "capture this as an article", the new article includes a `:DERIVED_FROM:` property listing the source articles. This creates a derivation chain in the database:

``` bash
crucible history comparisons/my-synthesis.org
# Derived from:
#   [concept] Activation Energy (wiki/concepts/activation-energy.org)
#   [summary] Smith 2024 Results (wiki/summaries/smith2024.org)
```

You can also trace forward: "what has been derived from this article?"

# Version Control

A crucible knowledge base is git-friendly. Commit `.crucible/wiki/`, `.crucible/references.bib`, `.crucible/sources/notebooks/`, and `.crucible/sources/data/`. `crucible init` writes this `.gitignore` at the project root (if there is none):

``` example
# Crucible: external sources (copyrighted, not shareable)
.crucible/sources/external/

# Crucible: database (regenerable from wiki via auto-rebuild)
.crucible/crucible.db
.crucible/crucible.db-wal
.crucible/crucible.db-shm
.crucible/crucible.db-journal
.crucible/.crucible.db.rebuild-*.tmp

# Crucible: lock file for references.bib
.crucible/references.bib.lock

# Crucible: publish output
.crucible/wiki/_build/

# Crucible: left behind only if a merge is killed
.crucible/.merge-staging-*/
```

## Rebuild on clone

The database is regenerable from the committed wiki files and `references.bib`. After cloning a repo that contains a crucible, the first command that needs the database rebuilds it automatically:

``` bash
git clone <repo>
cd <repo>
crucible search "some term"
# crucible: database missing, rebuilding from wiki...
# <search results>
```

No `crucible init` is needed on clone. The rebuild creates the schema, populates articles and their cross-links from `wiki/*.org`, creates `sources` rows from the `references.bib` entries whose `file` field names a stored file (which `crucible ingest` writes), adds a row for each file in `sources/notebooks/` and `sources/data/` that no entry claims (a disk scan), and regenerates `MANIFEST.md` and `index.org`. `references.bib` may use braces or parentheses around entries and compact one-line entries (as doi.org returns them); `@comment`, `@string` and `@preamble` blocks are ignored.

Because the rebuild reads only committed files, deleting a source with `crucible delete` also removes the `file` field from its bibliography entry (the entry is kept), so the source does not come back on the next sync.

## Embeddings are a separate step

Semantic embeddings are not auto-regenerated (they require a local ollama server). If you want `crucible related` and semantic search to work after a clone, run:

``` bash
crucible embed
```

Full-text search (FTS5) and everything else works without embeddings.

## Dropbox + git

If your crucible lives in Dropbox **and** is a git repo, pick one machine as the authoritative sync point. SQLite's WAL files do not play well with simultaneous access across Dropbox; running `crucible sync` from two machines at once can produce `.db` conflict files. Git itself is fine in Dropbox.

# Acknowledgments

Crucible draws on several sources of inspiration:

- [Andrej Karpathy's LLM Wiki pattern](https://gist.github.com/karpathy/442a6bf555914893e9891c11519de94f), which articulated the idea that an LLM should incrementally build and maintain a persistent, interlinked wiki rather than re-synthesizing knowledge from scratch on every query. Crucible implements this pattern with org-mode, a graph database, and hybrid search.

- [scimax](https://github.com/jkitchin/scimax), an Emacs starterkit for scientists and engineers built on org-mode. Crucible inherits scimax conventions for org-mode formatting, org-ref citations, and HTML publishing, and uses scimax as a primary viewing and editing environment for the wiki.

- [litdb](https://github.com/jkitchin/litdb), an earlier project for managing a literature database with org-mode and SQLite. Crucible extends the ideas in litdb (structured citation management, full-text search over scientific literature) into a broader knowledge base system where the LLM handles the synthesis and cross-linking that was previously manual.

# License

MIT. See [LICENSE](https://github.com/jkitchin/crucible/blob/main/LICENSE) for details.
