Collaborative Markdown Database for LLM Agents - A zen garden for your plans and specs
Project description
Niwa 庭
A Zen Garden for Your Plans - Collaborative Markdown Database for LLM Agents
Niwa (庭, "garden") is a CLI tool that enables multiple LLM agents to collaboratively edit markdown documents with automatic conflict detection and resolution. Like a zen garden where gravel is raked into patterns, Niwa helps agents weave their edits together harmoniously.
Built on LMDB for high-performance concurrent access.
Features
- Concurrent Editing: Multiple agents can read/edit simultaneously
- Conflict Detection: Automatic version tracking detects when agents edit the same section
- Smart Merging: Auto-merge suggestions for compatible changes, detailed diffs for conflicts
- Sub-Agent Support: Stored conflicts survive context switches, status commands for fresh context
- Version History: Full audit trail with rollback capability
- Search: Find content by keyword when you don't know the node ID
- LLM-Friendly: Comprehensive error messages with usage guides
- Claude Code Integration: Hooks to inject usage context on session start and compaction
Installation
# From PyPI (when published)
pip install niwa
# Or from source
git clone https://github.com/secemp9/niwa
cd niwa
pip install .
# For development (editable install)
pip install -e .
# Or with uv
uv pip install .
Quick Start
# 1. Initialize database
niwa init
# 2. Load a markdown file
niwa load document.md
# 3. View structure
niwa tree
# 4. Read a section (as an agent)
niwa read h2_3 --agent claude_1
# 5. Edit
niwa edit h2_3 "New content" --agent claude_1 --summary "Updated section"
# 6. Export back to markdown
niwa export > updated.md
Commands
Setup
| Command | Description |
|---|---|
init |
Initialize a new database |
load <file> |
Load markdown file into database |
check |
Verify database health |
setup claude |
Set up Claude Code hooks integration |
setup claude --remove |
Remove Claude Code hooks |
Browse
| Command | Description |
|---|---|
tree |
Show document structure with node IDs |
peek <id> |
Quick view (doesn't track read version) |
search <query> |
Find content by keyword |
Edit
| Command | Description |
|---|---|
read <id> --agent <name> |
Read for editing (tracks version) |
edit <id> <content> --agent <name> |
Edit a node |
resolve <id> <resolution> --agent <name> |
Resolve a conflict |
title <id> <title> |
Update node title |
summarize <id> <summary> |
Add summary to node |
Agent Status
| Command | Description |
|---|---|
status --agent <name> |
Check pending reads, conflicts, recent edits |
conflicts --agent <name> |
List unresolved conflicts |
agents |
List all agents who've used this DB |
whoami |
Get suggested unique agent name |
History & Undo
| Command | Description |
|---|---|
history <id> |
View version history |
rollback <id> <version> --agent <name> |
Restore to previous version |
dry-run <id> <content> --agent <name> |
Preview edit without applying |
cleanup |
Remove stale pending reads/conflicts |
Output
| Command | Description |
|---|---|
export |
Export database to markdown |
help |
Show full usage guide |
Multi-Agent Workflow
Agent A: reads section (v1) Agent B: reads section (v1)
│ │
▼ ▼
Agent A: edits Agent B: edits
│ │
▼ ▼
SUCCESS (v1→v2) CONFLICT! (expected v1, found v2)
│
▼
Agent B resolves with MANUAL_MERGE
│
▼
SUCCESS (v2→v3) - both changes preserved!
Conflict Resolution
When a conflict is detected, you get 4 options:
# Use your version (discard theirs)
niwa resolve h2_3 ACCEPT_YOURS --agent me
# Use their version (discard yours)
niwa resolve h2_3 ACCEPT_THEIRS --agent me
# Use auto-merge suggestion
niwa resolve h2_3 ACCEPT_AUTO_MERGE --agent me
# Manual merge (recommended!)
niwa resolve h2_3 MANUAL_MERGE "merged content" --agent me
niwa resolve h2_3 MANUAL_MERGE --file merged.md --agent me
Complex Content
For content with quotes, newlines, or special characters, use --file or --stdin:
# Edit from file
niwa edit h2_3 --file content.txt --agent me
# Edit from stdin
cat content.md | niwa edit h2_3 --stdin --agent me
# Resolve from file
niwa resolve h2_3 MANUAL_MERGE --file merged.md --agent me
Sub-Agents / Fresh Context
If you're a sub-agent or have fresh context, run these first:
# Get a unique agent name
niwa whoami
# Check your state
niwa status --agent <your_name>
# Check for pending conflicts
niwa conflicts --agent <your_name>
Key rules:
- Use a unique agent name (check with
agentscommand) - Use the same name for all your reads/edits
- Conflicts are stored and survive context switches
Node IDs
Nodes follow the pattern h{level}_{index}:
[root] v1 "Document"
[h1_0] v1 "Main Title"
[h2_1] v3 "Section 1" (by agent_A) ← node_id is "h2_1"
[h2_2] v1 "Section 2"
[h3_3] v2 "Subsection" (by agent_B) ← node_id is "h3_3"
Use tree to find node IDs, or search to find by content.
Examples
Basic editing workflow
niwa init
niwa load README.md
niwa tree
niwa read h2_1 --agent editor
niwa edit h2_1 "# Updated Heading\n\nNew content here." \
--agent editor --summary "Rewrote introduction"
niwa export > README_updated.md
Handling a conflict
# You tried to edit but got a conflict
niwa edit h2_3 "My changes" --agent me
# Output: CONFLICT DETECTED!
# View the diff, then resolve
niwa resolve h2_3 MANUAL_MERGE \
"Combined content from both versions" --agent me
Finding and editing content
# Don't know the node ID? Search for it
niwa search "authentication"
# Output: [h2_5] "Authentication" - 3 matches
# Read and edit
niwa read h2_5 --agent me
niwa edit h2_5 --file auth_rewrite.md --agent me
Rollback a bad edit
# Check history
niwa history h2_3
# Output: v3, v2, v1...
# Rollback to v2
niwa rollback h2_3 2 --agent me
Claude Code Integration
Niwa integrates with Claude Code via hooks for automatic context awareness:
# Set up Claude Code hooks
niwa setup claude
# Remove hooks later
niwa setup claude --remove
What the hooks do
| Hook | Trigger | Action |
|---|---|---|
| SessionStart | Session begins | Injects full Niwa usage guide + current status |
| PreCompact | Before /compact |
Preserves Niwa context so Claude remembers after compaction |
| PreToolUse | Before Write/Edit | Warns if there are unresolved conflicts |
| PostToolUse | After Write/Edit | Hints to sync markdown changes to database |
| Stop | Session ending | Reminds about unresolved conflicts |
The SessionStart and PreCompact hooks ensure Claude always knows how to use Niwa, even after context compaction.
How it works
- Run
setup claudein your project directory - Creates
.claude/settings.jsonwith hook configuration - Hooks automatically call
niwa.py hook --hook-event <event> - Claude receives context about your markdown database state
Example workflow with Claude Code
# 1. Initialize and set up hooks
niwa init
niwa load design_doc.md
niwa setup claude
# 2. Start Claude Code session
# Claude will see: "[Niwa Status] Database active with 15 nodes..."
# 3. When Claude edits markdown files
# Claude will see: "[Niwa] Markdown file modified... Consider syncing"
# 4. If conflicts exist when stopping
# Claude will see: "[Niwa Reminder] There are 2 unresolved conflict(s)..."
Architecture
- Storage: LMDB (Lightning Memory-Mapped Database) for fast concurrent access
- Versioning: Each edit increments version, full history stored
- Conflict Detection: Compares read version vs current version at edit time
- Merge Analysis: Diff-based overlap detection with auto-merge for compatible changes
- Hook Integration: Claude Code hooks for automatic context awareness
Name
Niwa (庭) means "garden" in Japanese. Like a zen garden where gravel (砂利, jari) is raked into patterns, Niwa helps organize your plans and specs with deliberate structure. Multiple agents can collaboratively tend the same garden without disturbing each other's patterns.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file niwa-0.1.1.tar.gz.
File metadata
- Download URL: niwa-0.1.1.tar.gz
- Upload date:
- Size: 38.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31274a5bc02d5930c0abd29ffd0028fc3bb6b3ea0883aef53c66692e13c8027c
|
|
| MD5 |
3b8e19e292b1b71287df6c0a7bb926a1
|
|
| BLAKE2b-256 |
9812c64c2887284b45ba3c8f8333f26c4df3487f266fd23744305370c3a336f7
|
Provenance
The following attestation bundles were made for niwa-0.1.1.tar.gz:
Publisher:
publish.yml on secemp9/niwa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
niwa-0.1.1.tar.gz -
Subject digest:
31274a5bc02d5930c0abd29ffd0028fc3bb6b3ea0883aef53c66692e13c8027c - Sigstore transparency entry: 868205982
- Sigstore integration time:
-
Permalink:
secemp9/niwa@6412cfc18a878d8096b2a5953f8ddf7fb14d6638 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/secemp9
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6412cfc18a878d8096b2a5953f8ddf7fb14d6638 -
Trigger Event:
release
-
Statement type:
File details
Details for the file niwa-0.1.1-py3-none-any.whl.
File metadata
- Download URL: niwa-0.1.1-py3-none-any.whl
- Upload date:
- Size: 40.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ae9c004097da5b707f224f2a7db59203fcb6727bfc14e41e2a84af8086d4d9c
|
|
| MD5 |
08509d2a17222764da045c9b173f8d90
|
|
| BLAKE2b-256 |
5a087f89ad102eea7b447559a9405601a83a288101560a1559eb065230af58a3
|
Provenance
The following attestation bundles were made for niwa-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on secemp9/niwa
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
niwa-0.1.1-py3-none-any.whl -
Subject digest:
6ae9c004097da5b707f224f2a7db59203fcb6727bfc14e41e2a84af8086d4d9c - Sigstore transparency entry: 868206000
- Sigstore integration time:
-
Permalink:
secemp9/niwa@6412cfc18a878d8096b2a5953f8ddf7fb14d6638 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/secemp9
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6412cfc18a878d8096b2a5953f8ddf7fb14d6638 -
Trigger Event:
release
-
Statement type: