NIWA (庭 - Garden) は、LLM エージェントの知識を永続化・成長させる Expertise Graph 管理システムです。
NIWA は 「知能資産の永続化と成長」 を実現します。
┌─────────────────────────────────────────────────────────────┐
│ User Interface (CLI powered by sen-rs) │
│ ┌──────────────────┐ ┌──────────────────────────┐ │
│ │ Generation │ │ Query & Management │ │
│ │ (LLM Agent) │ │ (Read-only CLI) │ │
│ │ │ │ │ │
│ │ gen │ │ list / show / search │ │
│ │ improve │ │ tags / graph / filter │ │
│ │ merge │ └──────────┬───────────────┘ │
│ └────────┬─────────┘ │ │
└───────────┼──────────────────────────────┼─────────────────┘
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────┐
│ niwa-core (SQLite Graph + Expertise CRUD) │
│ - llm-toolkit Expertise types │
│ - SQLite storage with FTS5 │
│ - Relations & versioning │
└────────────────────────┬────────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌────────┐ ┌─────────┐ ┌──────────┐
│ MCP │ │ Gemini │ │ Cursor │
│ Server │ │ Export │ │ Export │
└────────┘ └─────────┘ └──────────┘
- ベンダーロックイン回避: Expertise Graph は SQLite に保存され、任意のツール(Claude, Gemini, Custom Agent)に投影可能
- 永続的な成長: セッションログから学習し、Expertise を自動生成・改善
- 型安全: sen-rs フレームワークによるコンパイル時の型チェック
- LLM First: llm-toolkit による SchemaBasedResponse で構造化データ取得
- ✅ SQLite-based storage with FTS5 full-text search
- ✅ Expertise CRUD operations with versioning
- ✅ Dependency graph (Relations: uses, extends, conflicts, requires)
- ✅ Scope-based organization (personal, company, project)
- ✅ Tag-based filtering and search
- ✅ Type-safe API with comprehensive error handling
- ✅ Auto-generation from files or text input (
niwa gen) - ✅ Expertise improvement with LLM assistance (
niwa improve) - ✅ Session log learning - Auto-extract from Claude Code sessions (
niwa crawler) - ✅ Smart deduplication via SHA256 file hashing
- ✅ Interactive tutorial (
niwa tutorial) - ✅ Rich formatting with tables and colored output
- ✅ Graph visualization (
niwa graph) - ✅ Flexible filters (--limit, --recent-days for crawler)
- 📋 MCP Server for direct Claude integration
- 📋 Exporters (Gemini CLI, Cursor rules)
- 💡 Currently: Use NIWA CLI directly - no export needed!
NIWA uses Claude Code CLI internally for LLM-powered features. Make sure you have:
- Rust 1.70+ and SQLite 3.35+
- Claude Code CLI installed (Installation Guide)
- ANTHROPIC_API_KEY environment variable set
# Set your API key (required for gen, improve, crawler commands)
export ANTHROPIC_API_KEY=sk-ant-...Note: NIWA internally uses llm-toolkit, which calls the claude command. Your environment variables (including ANTHROPIC_API_KEY) are passed through to Claude Code.
cargo install niwagit clone https://github.com/ynishi/niwa-cli.git
cd niwa-cli
make install
# Or manually:
cargo build --release
cargo install --path crates/niwause niwa_core::{Database, Expertise, Scope, StorageOperations};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Initialize database
let db = Database::open_default().await?;
// Create expertise
let mut expertise = Expertise::new("rust-expert", "1.0.0");
expertise.inner.description = Some("Expert in Rust programming".to_string());
expertise.inner.tags = vec!["rust".to_string(), "programming".to_string()];
expertise.metadata.scope = Scope::Personal;
// Store
db.storage().create(expertise).await?;
// Query
let results = db.query().search("rust", Default::default()).await?;
println!("Found {} expertises", results.len());
// List all
let all = db.storage().list(Scope::Personal).await?;
for exp in all {
println!("- {} (v{})", exp.id(), exp.version());
}
Ok(())
}niwa-cli/
├── crates/
│ ├── niwa-core/ # Core library (✅ Complete)
│ │ ├── src/
│ │ │ ├── db.rs # Database connection & migrations
│ │ │ ├── storage.rs # CRUD operations
│ │ │ ├── query.rs # Search & filtering
│ │ │ ├── graph.rs # Relations & dependency graph
│ │ │ ├── types.rs # Expertise types & Scope
│ │ │ └── error.rs # Error types
│ │ └── migrations/
│ │ └── 001_init.sql
│ │
│ ├── niwa-generator/ # LLM-powered generation (🚧 In Progress)
│ ├── niwa-export/ # Exporters (Planned)
│ └── niwa/ # CLI binary (Planned)
│
├── ARCHITECTURE.md # Detailed architecture
└── README.md # This file
-- Expertises with FTS5 full-text search
CREATE TABLE expertises (
id TEXT PRIMARY KEY,
version TEXT NOT NULL,
scope TEXT CHECK(scope IN ('personal', 'company', 'project')),
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL,
data_json TEXT NOT NULL,
description TEXT
);
-- Tags
CREATE TABLE tags (
expertise_id TEXT NOT NULL,
tag TEXT NOT NULL,
PRIMARY KEY (expertise_id, tag)
);
-- Relations (dependency graph)
CREATE TABLE relations (
from_id TEXT NOT NULL,
to_id TEXT NOT NULL,
relation_type TEXT CHECK(relation_type IN ('uses', 'extends', 'conflicts', 'requires')),
metadata TEXT,
created_at INTEGER NOT NULL,
PRIMARY KEY (from_id, to_id, relation_type)
);
-- Version history
CREATE TABLE versions (
expertise_id TEXT NOT NULL,
version TEXT NOT NULL,
created_at INTEGER NOT NULL,
data_json TEXT NOT NULL,
PRIMARY KEY (expertise_id, version)
);
-- FTS5 for full-text search
CREATE VIRTUAL TABLE expertises_fts USING fts5(
id, description, tags
);- Rust 1.70+
- SQLite 3.35+ (for FTS5 support)
cargo buildcargo test -p niwa-corecargo check --workspaceNIWA can replace traditional "Skill" or "Expertise" management systems. Instead of exporting to external formats, use NIWA CLI directly to browse and query your knowledge.
# Search for architecture-related knowledge
$ niwa search "architecture"
# Show detailed information
$ niwa show niwa-architecture-detail
# Browse all knowledge
$ niwa list# Find migration policy
$ niwa search "migration"
$ niwa show niwa-migration-policy
# Check related knowledge
$ niwa deps niwa-migration-policy
# Visualize knowledge graph
$ niwa graphReview checklist (based on stored expertise):
- ✅ Migration uses
ALTER TABLE ADD COLUMNonly? - ❌ No
DROP COLUMNorDROP TABLE? - ✅ Uses runtime
Migrator::new()instead ofmigrate!()macro?
# Initialize crawler monitoring (one-time setup)
$ niwa crawler init claude-code
# Process recent sessions (last 5 days, max 10 files)
$ niwa crawler run --recent-days 5 --limit 10
# Check what was learned
$ niwa list
$ niwa tags# Add quick tips
$ niwa gen --id rust-error-handling --text "Use Result<T,E> for recoverable errors, panic! for bugs"
# Extract from documentation
$ niwa gen --id project-architecture --file ARCHITECTURE.md
# Search when you need it
$ niwa search "error handling"
# Build knowledge graph
$ niwa link rust-error-handling --to rust-best-practices --relation-type extendsuse niwa_core::{Database, Expertise, Scope, StorageOperations};
let db = Database::open("~/.niwa/graph.db").await?;
// Create
let expertise = Expertise::new("rust-expert", "1.0.0");
db.storage().create(expertise).await?;
// Get
let exp = db.storage().get("rust-expert", Scope::Personal).await?;
// Update
if let Some(mut exp) = exp {
exp.inner.version = "2.0.0".to_string();
db.storage().update(exp).await?;
}
// Delete
db.storage().delete("rust-expert", Scope::Personal).await?;use niwa_core::{Database, SearchOptions, Scope};
let db = Database::open_default().await?;
// Full-text search
let options = SearchOptions::new().limit(10);
let results = db.query().search("error handling", options).await?;
// Filter by tags
let options = SearchOptions::new().scope(Scope::Personal);
let results = db.query()
.filter_by_tags(vec!["rust".to_string()], options)
.await?;
// List all tags
let tags = db.query().list_tags(None).await?;
for (tag, count) in tags {
println!("{}: {}", tag, count);
}use niwa_core::{Database, RelationType};
let db = Database::open_default().await?;
// Create relation
db.graph().create_relation(
"rust-expert",
"error-handling",
RelationType::Uses,
None
).await?;
// Get dependencies
let deps = db.graph().get_dependencies("rust-expert").await?;
// Get dependents
let dependents = db.graph().get_dependents("error-handling").await?;
// Build full graph
let graph = db.graph().build_graph().await?;- Database schema & migrations
- CRUD operations
- Query engine (search, filter)
- Graph operations (relations)
- Comprehensive tests
- ExpertiseGenerator implementation
-
niwa gencommand (--file, --text) -
niwa improvecommand - LLM-powered extraction
- Session log parser
-
niwa crawlercommand - claude-code / cursor presets
- Auto-learning from session logs
- Deduplication via file hashing
- MCP protocol implementation
- Prompts / Resources / Tools
- Direct MCP integration
- Gemini CLI config generator
- Cursor rules generator
- Note: Currently use NIWA CLI directly instead of export
- ARCHITECTURE.md - Detailed architecture and design decisions
- API Documentation (Coming soon)
Contributions are welcome! Please read ARCHITECTURE.md to understand the design first.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
NIWA is built on top of:
- sen-rs - CLI framework
- llm-toolkit - LLM agent library
- sqlx - Async SQL toolkit
Inspired by:
- kanri-agent - Original prototype
NIWA (庭): Your personal garden of AI expertise, growing with every conversation.