From 0dd8808993f8d6fd2b33c4043510528ed17bec13 Mon Sep 17 00:00:00 2001 From: Zhongwei Li Date: Sun, 30 Nov 2025 08:53:34 +0800 Subject: [PATCH] Initial commit --- .claude-plugin/plugin.json | 12 ++ README.md | 3 + plugin.lock.json | 49 +++++ skills/candlekeep.skill | Bin 0 -> 4483 bytes skills/candlekeep/SKILL.md | 412 +++++++++++++++++++++++++++++++++++++ 5 files changed, 476 insertions(+) create mode 100644 .claude-plugin/plugin.json create mode 100644 README.md create mode 100644 plugin.lock.json create mode 100644 skills/candlekeep.skill create mode 100644 skills/candlekeep/SKILL.md diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json new file mode 100644 index 0000000..e26c55e --- /dev/null +++ b/.claude-plugin/plugin.json @@ -0,0 +1,12 @@ +{ + "name": "candlekeep-cli", + "description": "Personal knowledge base CLI that gives AI agents direct access to your books and annotations", + "version": "0.1.0", + "author": { + "name": "Sahar Carmel", + "email": "sahar@example.com" + }, + "skills": [ + "./skills" + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5e2ec78 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# candlekeep-cli + +Personal knowledge base CLI that gives AI agents direct access to your books and annotations diff --git a/plugin.lock.json b/plugin.lock.json new file mode 100644 index 0000000..054c392 --- /dev/null +++ b/plugin.lock.json @@ -0,0 +1,49 @@ +{ + "$schema": "internal://schemas/plugin.lock.v1.json", + "pluginId": "gh:SaharCarmel/CandleKeep:plugins/candlekeep-cli", + "normalized": { + "repo": null, + "ref": "refs/tags/v20251128.0", + "commit": "c710acc3dd5361811aface1a59166f25b3e5a50d", + "treeHash": "4f074f51c1f304eb0e02cbc79398f810f8d753141e3bffcf1210abad91f38436", + "generatedAt": "2025-11-28T10:12:43.342588Z", + "toolVersion": "publish_plugins.py@0.2.0" + }, + "origin": { + "remote": "git@github.com:zhongweili/42plugin-data.git", + "branch": "master", + "commit": "aa1497ed0949fd50e99e70d6324a29c5b34f9390", + "repoRoot": "/Users/zhongweili/projects/openmind/42plugin-data" + }, + "manifest": { + "name": "candlekeep-cli", + "description": "Personal knowledge base CLI that gives AI agents direct access to your books and annotations", + "version": "0.1.0" + }, + "content": { + "files": [ + { + "path": "README.md", + "sha256": "c333a756ac195d2566c7e7f739c1c8d7eaeb74599eebf07af6a9c6dc8cc1131c" + }, + { + "path": ".claude-plugin/plugin.json", + "sha256": "bbdf45b2d2650e4cbb12e0e8185e612bca9ae1ebab11fa50c82ce09de2ae81de" + }, + { + "path": "skills/candlekeep.skill", + "sha256": "11f51f93770d3fb204a395d882cadc429ad1d7fabdad8f8b091908ee52da04d5" + }, + { + "path": "skills/candlekeep/SKILL.md", + "sha256": "661f1c990ad3688ad679f0970dfdbdb7e1fd2569d83a17feda47fe7e10ef16a6" + } + ], + "dirSha256": "4f074f51c1f304eb0e02cbc79398f810f8d753141e3bffcf1210abad91f38436" + }, + "security": { + "scannedAt": null, + "scannerVersion": null, + "flags": [] + } +} \ No newline at end of file diff --git a/skills/candlekeep.skill b/skills/candlekeep.skill new file mode 100644 index 0000000000000000000000000000000000000000..1a498fbaf9f6a5171e3f919504d56406096dace2 GIT binary patch literal 4483 zcmV-}5q$1YO9KQH0000805-OCTZ@3D^7{|~03R*@022TJ0ApcpWNc+?Wo2+LQ%gxq zOfGF?&05WJ8#$7`*Ha+qh%u>QQKWusH^bW#YRR5fx7{sE>hZzr2trjLS*>EBrcgzR zbC~Fu!#==87!=J_ zbW5A^Te8B|59e20&_)$xnH-u?P?AiOay1A-m@0T8PT5XB!cHP=jPu3`#&*dTCv1x# zXbqlWFGj3%wQV8E=Xz>H?#1!e+-3(5eyhY>E=hTkcBW(z&0ztPm{MjXj-v@bP#6E3 z_2N_kbFWxjA8L?!sS4I+4z#dFXl0@AGBd#8a5`NmaWPL)ZFD|g1;O6lDQnMKWttSG zwA$NL++3ykU~f;HPaCIM|!c)8QF)B^ZB<=78uxDiEU=4kMlrhCFXT@?<6WCv@`NM|L@p~E(7F4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41)LTcc685#Pi*;#~3wZ$$4ydouXyu zB#Lyw#2K2|YbuOAy71WSRnp5VT;Jli_z9ASkc0K_2}$atC1oglTjZ0T*2yGcsx>K3+j zqj$q#B>9>m5?%HgcN^<^`{b&0F-sk(X;naOvE9cB&TXWJ)mKn!eWON`r{F~`^wt## zPSI9%;M96J3Xg_8+hn#^Ig1=D4vKY!&$RA$*tlv9`yI|iw;ZAijj_YM6et})=ja9o zCOXsX`Ut#)4wa^)*5BC#@&S+4__6Ib$x=qvB4-H>tQZzSDAsO7x35Asudo~JMj8jS;e#?WVSXWR z72RLE&auBFzMHQ|`ieWCB7!>+hJE%qpStc210BD#R%1@GFEjip9Z{H8oI$5b(w{w; zgl=rGDv~c@keM85d7il=b!BCR}DF+W9-Xg7E!2~x~KHGM$5V7cdc)c#+2hC(W=#3 zAxWd5zhyq`4~IkI53%WqrP-wf(S0#&k1~>8syu(r-%47jejGv%Hh>cQKEtZ+((~Yx z`Z7X{7R2s7(9zAEfb5S$?Sd3Eyv30xcgr8O zo%TjMGG&^C@~%q2)nC(TEp1;%hkYWn-M!odLH#Gvg@b}H%g&}-^+HH z*{$_0ol_o%wS$(c+!FsswBcI>_{BHjH*NY`U%ggI%KpCLlQOeyC#vsjH{A90*?0=Yj36;cYM!9m$(nck$)6(UFeE3 z(Ohea!qyV4M-dy(QCfPg-)_RL_dbH{O@txU15XD4RELNbs@jgn}TfVT|;90KSg2lxz*RR7DG=-Z>4H+`L z{ic405QiBi8CkWs;kU4btOk;IT}Xp?FmR0o1K+!4HSX3@vTAENq?(yO*dnV;@@%R6n8Ry0q1x z3vF+=*qMhA@j!UmI!6S1;H%gx3zrBSLz>%ED- && uv run candlekeep init +``` + +**Initialization creates:** +- `~/.candlekeep/` - Main directory +- `~/.candlekeep/candlekeep.db` - SQLite database (metadata only) +- `~/.candlekeep/library/` - Markdown files (book content) +- `~/.candlekeep/originals/` - Original PDF/markdown files + +## Command Reference + +All commands require CandleKeep CLI. The plugin should install this automatically. Commands are run with `uv run candlekeep` from the plugin directory. + +### 1. List Books (`list`) + +See what books are available in the library. + +```bash +# Basic list (essential metadata) +cd && uv run candlekeep list + +# Full metadata +cd && uv run candlekeep list --full + +# Specific fields +cd && uv run candlekeep list --fields category,tags +``` + +**Output format** (optimized for LLM consumption): +```markdown +# Library Books (Total: 3) + +## Book ID: 1 +Title: Clean Code +Author: Robert C. Martin +Type: pdf +Pages: 464 +Added: 2024-11-20 10:30:00 + +## Book ID: 2 +Title: Designing Data-Intensive Applications +Author: Martin Kleppmann +Type: pdf +Pages: 616 +Added: 2024-11-19 15:45:00 +``` + +**Use when:** +- User asks "what books do I have?" +- Checking if a topic is covered before answering +- Starting a session with book-related work + +### 2. Get Table of Contents (`toc`) + +View book structure to find relevant sections. + +```bash +cd && uv run candlekeep toc +``` + +**Example:** +```bash +cd && uv run candlekeep toc 1 +``` + +**Output format:** +```markdown +## Table of Contents - Book ID: 1 +Title: Clean Code + +Clean Code (Page 1) + Chapter 1: Clean Code (Page 7) + Chapter 2: Meaningful Names (Page 17) + Rules for Naming (Page 18) + Use Intention-Revealing Names (Page 18) + Chapter 3: Functions (Page 31) +``` + +**Use when:** +- Need to find where a topic is covered +- User asks "what does [book] say about [topic]?" +- Planning which pages to extract + +### 3. Get Pages (`pages`) + +Extract specific pages or ranges from a book. + +```bash +cd && uv run candlekeep pages --pages "" +``` + +**Page range formats:** +- Single pages: `"1,5,10"` +- Ranges: `"1-5"` (pages 1 through 5) +- Mixed: `"1-5,10,15-20"` (pages 1-5, 10, and 15-20) + +**Examples:** +```bash +# Get pages 17-31 (Chapter 2 of Clean Code) +cd && uv run candlekeep pages 1 --pages "17-31" + +# Get specific pages +cd && uv run candlekeep pages 2 --pages "1,10,50-55" +``` + +**Output format:** +```markdown +## Book ID: 1 - Clean Code +Pages: 17-31 + +### Page 17 +# Chapter 2: Meaningful Names +Names are everywhere in software... + +### Page 18 +## Use Intention-Revealing Names +The name of a variable, function, or class should answer... +``` + +**Use when:** +- Answering specific questions that a chapter covers +- Providing detailed guidance from book content +- User requests specific information from a known book + +**Performance tip:** Extract only needed pages. A book might be 600 pages, but the relevant section is often 5-20 pages. + +### 4. Add PDF Book (`add-pdf`) + +Add a PDF book to the library. + +```bash +cd && uv run candlekeep add-pdf \ + [--category "category"] \ + [--tags "tag1,tag2"] \ + [--title "Custom Title"] \ + [--author "Custom Author"] +``` + +**Examples:** +```bash +# Basic add +cd && uv run candlekeep add-pdf ~/Downloads/clean-code.pdf + +# With metadata +cd && uv run candlekeep add-pdf ~/Downloads/book.pdf \ + --category "Software Engineering" \ + --tags "coding,best-practices" +``` + +**Process:** +1. Computes file hash (duplicate detection) +2. Parses PDF with docling + LLM +3. Extracts metadata (title, author, TOC, page count) +4. Converts to markdown with page markers +5. Stores markdown in `~/.candlekeep/library/` +6. Stores metadata in database + +**Use when:** User provides a PDF file to add to their library + +### 5. Add Markdown Book (`add-md`) + +Add a markdown book to the library. + +```bash +cd && uv run candlekeep add-md \ + [--category "category"] \ + [--tags "tag1,tag2"] \ + [--title "Custom Title"] \ + [--author "Custom Author"] +``` + +**Markdown frontmatter support:** +```markdown +--- +title: My Guide to Python +author: Jane Developer +category: Programming +tags: [python, tutorial] +--- + +# Chapter 1 +Content here... +``` + +**Use when:** User provides a markdown file to add (documentation, notes, agent-optimized books) + +## Best Practices + +### When to Query Books + +**Always check books for:** +- Technical questions (coding, system design, algorithms) +- Domain expertise (finance, medicine, law, etc.) +- Methodologies and best practices +- Historical or research questions +- Specific author/book references + +**Example triggers:** +- "How should I structure this React component?" → Check for React/design books +- "What's the best way to value a startup?" → Check for investing/valuation books +- "Explain CQRS pattern" → Check for architecture/design books + +### Page Extraction Strategy + +**Start narrow, expand if needed:** + +1. **Check TOC first** to identify relevant pages +2. **Extract specific section** (e.g., pages 45-62 for one chapter) +3. **If insufficient, expand** to related chapters +4. **Avoid extracting entire book** unless specifically requested + +**Example workflow:** +```bash +# 1. List books to find relevant one +cd && uv run candlekeep list + +# 2. Get TOC to locate section +cd && uv run candlekeep toc 3 + +# 3. Extract specific pages based on TOC +cd && uv run candlekeep pages 3 --pages "120-145" +``` + +### Presenting Book Content + +When answering with book content: + +1. **Cite the source:** "According to *Clean Code* by Robert C. Martin (pages 17-19):" +2. **Synthesize, don't just quote:** Combine book knowledge with training knowledge +3. **Provide context:** Explain how the book's advice applies to their situation +4. **Reference specific pages:** This helps users verify and explore further + +**Example:** +``` +I checked your library and found relevant guidance in *Clean Code* +(pages 31-40). The book emphasizes that functions should: + +1. Be small (ideally < 20 lines) +2. Do one thing well +3. Have descriptive names + +For your React component, this means splitting `handleSubmit` into +smaller functions: `validateForm()`, `prepareData()`, and `sendRequest()`. + +[Citation: Clean Code, Chapter 3: Functions, pages 31-40] +``` + +### Privacy and Discretion + +- Books in the library represent user's personal knowledge collection +- Don't make assumptions about why they have certain books +- If a book contains personal notes/annotations (future feature), treat as private + +## Technical Details + +### Storage Architecture + +- **Database:** SQLite at `~/.candlekeep/candlekeep.db` (metadata only) +- **Content:** Markdown files in `~/.candlekeep/library/` (actual book text) +- **Originals:** PDFs in `~/.candlekeep/originals/` (optional backup) + +### Page Markers + +PDFs are converted to markdown with page separators: +```markdown +Content from page 1... + +--- end of page=1 --- + +Content from page 2... + +--- end of page=2 --- +``` + +This enables precise page extraction without loading entire books. + +### Performance + +- **Listing books:** <10ms (database query) +- **Getting TOC:** <10ms (database query, TOC stored as JSON) +- **Extracting pages:** <50ms (regex on markdown file) + +**Token efficiency:** Extracting 10 pages (3,000 words) vs loading entire book (80,000 words) saves 77,000 tokens. + +## Common Patterns + +### Research Assistant Pattern + +User working on a project with multiple relevant books: + +```bash +# 1. Show available books +cd && uv run candlekeep list + +# 2. For each relevant book, get TOC +cd && uv run candlekeep toc 1 +cd && uv run candlekeep toc 2 + +# 3. Extract relevant sections from each +cd && uv run candlekeep pages 1 --pages "50-75" +cd && uv run candlekeep pages 2 --pages "120-135" + +# 4. Synthesize answer using content from both books +``` + +### Quick Fact Check Pattern + +User asks a specific question: + +```bash +# 1. Check if library has relevant books +cd && uv run candlekeep list + +# 2. Get TOC to verify coverage +cd && uv run candlekeep toc 3 + +# 3. Extract just the relevant pages (5-10 pages typically) +cd && uv run candlekeep pages 3 --pages "89-95" +``` + +### Library Building Pattern + +User wants to add multiple books: + +```bash +# Add books one at a time +cd && uv run candlekeep add-pdf ~/Downloads/book1.pdf --category "Engineering" +cd && uv run candlekeep add-pdf ~/Downloads/book2.pdf --category "Engineering" + +# Verify they were added +cd && uv run candlekeep list +``` + +## Troubleshooting + +### CandleKeep not initialized +```bash +# Initialize CandleKeep +cd && uv run candlekeep init +``` + +### Command not found +```bash +# Ensure you're in the plugin directory and using uv +cd +uv run candlekeep --help +``` + +### Book not parsing correctly +- PDF parsing uses docling + LLM - complex PDFs may take time +- If parsing fails, check PDF isn't encrypted/locked +- Markdown files should use UTF-8 encoding + +### Pages not extracting +- Verify page numbers are within book's page count +- Check page range format: `"1-5"` not `1-5` +- Some books may not have page markers if added before that feature + +## Summary + +CandleKeep transforms how AI agents access knowledge: + +- **Proactive:** Check books when they might help +- **Precise:** Extract specific pages, not entire books +- **Cited:** Always attribute information to source books +- **Efficient:** Fast queries, token-conscious extraction + +Think of it as giving every AI agent access to a personal research library—making responses more informed, specific, and tailored to the user's knowledge collection.