Skip to content

Commit 863a782

Browse files
genezhangclaude
andcommitted
feat(tool): add cg CLI + embedded opt-in feature flag + v0.6.6-dev
- New `clickgraph-tool` workspace crate (`cg` binary): agent/script CLI for Cypher translation and execution without a running server. Commands: sql, validate, query, nl (NL→Cypher via LLM), schema show/validate/discover/diff. Supports Anthropic (default) and any OpenAI-compatible API. Config via ~/.config/cg/config.toml. - `clickgraph-embedded`: make `embedded` feature (chdb) opt-in. Added `Database::new_remote(schema, RemoteConfig)` — executes Cypher against external ClickHouse with no chdb dependency. `sql_only()` and `query_to_sql()` always available. `clickgraph-ffi` now explicitly enables the `embedded` feature. - Remove leftover debug println in render_plan/render_expr.rs. - Version bump to v0.6.6-dev; TCK test count (383/402) added to README. - Docs: README, CHANGELOG, STATUS, ROADMAP, CLAUDE.md, DEV_QUICK_START, copilot-instructions, all AGENTS.md files updated. Wiki: Quick-Start-Guide (pre-built binaries), Embedded-Mode (3 constructors), Schema-Discovery (cg server-free path), AI-Assistant-Integration-MCP (cg agent path), Home (v0.6.6-dev). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 1f11ad7 commit 863a782

30 files changed

Lines changed: 1966 additions & 152 deletions

.github/copilot-instructions.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,12 @@ ecommerce_simple.yaml → schemas/examples/
330330
- Protocol enabling/disabling capabilities
331331

332332
**Embedded Mode + Language Bindings**
333-
- `clickgraph-embedded` crate: in-process Cypher queries via chdb (Kuzu-compatible API)
334-
- `clickgraph-ffi` UniFFI crate: single source of truth for Go and Python bindings
333+
- `clickgraph-embedded` crate: Kuzu-compatible sync API. Three constructors:
334+
- `Database::sql_only(path)` — Cypher→SQL only, no executor (always available)
335+
- `Database::new_remote(path, RemoteConfig)` — execute against external ClickHouse (no chdb)
336+
- `Database::new(path, SystemConfig)` — in-process chdb execution (`embedded` feature, opt-in)
337+
- `clickgraph-ffi` UniFFI crate: single source of truth for Go and Python bindings (always uses `embedded` feature)
338+
- `clickgraph-tool` crate: `cg` CLI binary for agents/scripts — `sql`, `validate`, `query`, `nl`, `schema show/validate/discover/diff`
335339
- Hybrid remote query + local storage: `RemoteConfig` enables `query_remote()`, `query_remote_graph()`, `store_subgraph()` for querying a remote ClickHouse cluster and storing results locally
336340
- Write API: `create_node()`, `create_edge()`, `upsert_node()`, `store_subgraph()` with batch variants
337341

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [0.6.6-dev] - 2026-04-03
2+
3+
### 🚀 Features
4+
5+
- **`cg` CLI tool** (`clickgraph-tool` crate): Agent/script-oriented CLI for Cypher translation and execution without a running server. Commands: `cg sql` (Cypher→SQL), `cg validate` (parse + plan check), `cg query` (execute via remote ClickHouse), `cg nl` (NL→Cypher via LLM), `cg schema show/validate/discover/diff`. Config via `~/.config/cg/config.toml`. Supports Anthropic (default) and any OpenAI-compatible API.
6+
7+
- **`embedded` feature now opt-in** in `clickgraph-embedded`: chdb is no longer compiled by default. New `Database::new_remote(schema, RemoteConfig)` constructor executes Cypher against external ClickHouse with no chdb dependency — the backend used by `cg query`. `Database::sql_only(schema)` and `Connection::query_to_sql()` are always available for translation-only use.
8+
9+
### 🐛 Bug Fixes
10+
11+
- **Debug println removed**: Eliminated leftover `println!("DEBUG TryFrom RenderExpr: ...")` in `render_plan/render_expr.rs` that was polluting stdout during query translation.
12+
13+
---
14+
115
## [0.6.5-dev] - 2026-03-29
216

317
### 🚀 Features

CLAUDE.md

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ClickGraph is a **read-only graph query engine** for ClickHouse, written in Rust
99
**Modes of operation:**
1010
- **Server mode** — HTTP (axum) + Bolt v5.8 protocol servers, querying a remote ClickHouse instance
1111
- **Embedded mode** — In-process serverless execution via chdb (ClickHouse embedded). Query Parquet, S3, Iceberg, Delta Lake directly without a running server
12+
- **Remote mode** — Cypher translated locally, executed against an external ClickHouse (no chdb needed)
1213
- **SQL-only mode** — Translate Cypher to SQL without executing (for debugging, testing, or external execution)
1314

1415
**Ground rules**: (1) Never change query semantics — honestly return what is asked, no more, no less. (2) No shortcuts — fully understand the processing flow before making changes. Quality over speed.
@@ -21,10 +22,11 @@ clickgraph-embedded/ # Embedded Rust API (Database/Connection/QueryResul
2122
clickgraph-ffi/ # UniFFI FFI layer (cdylib — single source of truth for all bindings)
2223
clickgraph-go/ # Idiomatic Go bindings via cgo + UniFFI-generated C bridge
2324
clickgraph-py/ # Pythonic wrapper over UniFFI-generated ctypes bridge
24-
clickgraph-client/ # CLI client for querying ClickGraph servers
25+
clickgraph-client/ # Interactive REPL client for querying ClickGraph servers (human use)
26+
clickgraph-tool/ # cg CLI — agent/script-oriented tool (sql, validate, query, nl, schema)
2527
```
2628

27-
**Workspace members** (in `Cargo.toml`): `clickgraph-client`, `clickgraph-embedded`, `clickgraph-ffi`
29+
**Workspace members** (in `Cargo.toml`): `clickgraph-client`, `clickgraph-embedded`, `clickgraph-ffi`, `clickgraph-tool`
2830

2931
Go and Python bindings are not Cargo workspace members — they consume `libclickgraph_ffi.so`.
3032

@@ -42,7 +44,7 @@ cargo fmt --all
4244
# Lint
4345
cargo clippy --all-targets
4446

45-
# Rust tests (~1,560 tests across workspace)
47+
# Rust tests (~1,600 tests across workspace)
4648
cargo test # All Rust tests
4749
cargo test <test_name> # Single test
4850
cargo test -- --nocapture # With output
@@ -71,6 +73,17 @@ cargo run --bin clickgraph
7173
curl -X POST http://localhost:8080/query \
7274
-H "Content-Type: application/json" \
7375
-d '{"query":"MATCH (n) RETURN n","sql_only":true}'
76+
77+
# cg CLI — agent/script-oriented tool (no server needed)
78+
cg --schema schema.yaml sql "MATCH (n:Person) RETURN n.name" # translate only
79+
cg --schema schema.yaml validate "MATCH (n:Person) RETURN n" # parse + plan check
80+
cg --schema schema.yaml \
81+
--clickhouse http://localhost:8123 \
82+
query "MATCH (n:Person) RETURN n.name LIMIT 10" # execute via remote CH
83+
cg --schema schema.yaml nl "find people with more than 5 friends" # NL → Cypher
84+
cg --schema schema.yaml schema show # agent-friendly schema view
85+
cg schema discover --clickhouse http://localhost:8123 \
86+
--database mydb --out schema.yaml # LLM-assisted discovery
7487
```
7588

7689
## Architecture — Query Pipeline
@@ -103,31 +116,31 @@ Cypher Query → Parse → Plan → Optimize → Render → Generate SQL → Exe
103116
## Ecosystem Architecture
104117

105118
```
106-
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
107-
│ Go App │ │ Python App │ │ Rust App │
108-
│ (cgo) │ │ (ctypes) │ │ (direct) │
109-
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘
110-
│ │ │
111-
clickgraph-go clickgraph-py clickgraph-embedded
112-
│ │ │
113-
└────────┬────────┘
114-
115-
┌─────────▼──────────┐
116-
│ clickgraph-ffi │
117-
│ (libclickgraph_ffi │
118-
.so / UniFFI)
119-
└─────────┬──────────┘ │
120-
└─────────────────────────┘
121-
122-
┌──────────▼──────────┐
123-
│ clickgraph (core) │
124-
│ Parser + Planner + │
125-
│ SQL Generator │
126-
└──────────┬──────────┘
127-
128-
┌──────────▼──────────┐
129-
│ ClickHouse / chdb │
130-
└─────────────────────┘
119+
┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
120+
│ Go App │ │ Python App │ │ Rust App │ │ Agent/Script
121+
│ (cgo) │ (ctypes) │ │ (direct) │ │ (cg CLI) │
122+
└──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘
123+
│ │ │
124+
clickgraph-go clickgraph-py clickgraph-embedded clickgraph-tool
125+
│ │ (sql_only/remote)
126+
└────────┬────────┘ (chdb: +embedded feat)
127+
128+
┌─────────▼──────────┐ └────────┬────────┘
129+
│ clickgraph-ffi
130+
│ (libclickgraph_ffi │
131+
│ .so / UniFFI)
132+
└─────────┬──────────┘
133+
└──────────────────┬────────────────┘
134+
135+
┌──────────▼──────────┐
136+
│ clickgraph (core) │
137+
│ Parser + Planner + │
138+
│ SQL Generator │
139+
└──────────┬──────────┘
140+
141+
┌──────────▼──────────┐
142+
│ ClickHouse / chdb │
143+
└─────────────────────┘
131144
```
132145

133146
### FFI Layer (`clickgraph-ffi/`)
@@ -148,7 +161,15 @@ uniffi-bindgen-go --library target/debug/libclickgraph_ffi.so --out-dir clickgra
148161

149162
### Embedded Mode (`clickgraph-embedded/`)
150163

151-
Core Rust crate with Kuzu-compatible sync API (`Database``Connection``QueryResult`). Backend is chdb (ClickHouse embedded), enabled via `embedded` feature flag. Supports `sql_only` mode without chdb.
164+
Core Rust crate with Kuzu-compatible sync API (`Database``Connection``QueryResult`). Three constructors:
165+
166+
| Constructor | Needs chdb? | Use case |
167+
|---|---|---|
168+
| `Database::sql_only(schema)` | No | Translate Cypher → SQL only |
169+
| `Database::new_remote(schema, RemoteConfig)` | No | Execute against external ClickHouse |
170+
| `Database::new(schema, SystemConfig)` | **Yes** (`embedded` feature) | In-process chdb execution |
171+
172+
The `embedded` feature flag is **opt-in** (default off). `clickgraph-ffi` and `clickgraph-tck` enable it; `clickgraph-tool` does not.
152173

153174
Schema `source:` field supports: local files, `s3://`, `iceberg+s3://`, `delta+s3://`, `table_function:...`.
154175

@@ -218,6 +239,11 @@ Five schema variations exist: Standard, FK-edge, Denormalized, Polymorphic, Comp
218239
| `CLICKGRAPH_CHDB_TESTS` | Set to `1` to enable chdb e2e tests |
219240
| `CLICKGRAPH_LLM_PROVIDER` | LLM provider for schema discovery (`anthropic` or `openai`) |
220241
| `ANTHROPIC_API_KEY` / `OPENAI_API_KEY` | API keys for LLM schema discovery |
242+
| `CG_SCHEMA` | Default schema file path for `cg` CLI |
243+
| `CG_CLICKHOUSE_URL` | ClickHouse URL for `cg query` |
244+
| `CG_CLICKHOUSE_USER` / `CG_CLICKHOUSE_PASSWORD` | Credentials for `cg query` |
245+
| `CG_LLM_PROVIDER` | LLM provider for `cg nl` and `cg schema discover` |
246+
| `CG_LLM_MODEL` / `CG_LLM_API_KEY` / `CG_LLM_BASE_URL` | LLM config for `cg` |
221247

222248
## Key Documentation Files
223249

@@ -226,5 +252,5 @@ Five schema variations exist: Standard, FK-edge, Denormalized, Polymorphic, Comp
226252
- **`DEV_QUICK_START.md`** — Essential developer workflow
227253
- **`DEVELOPMENT_PROCESS.md`** — Detailed 6-phase development process
228254
- **`.github/copilot-instructions.md`** — Comprehensive architecture guide
229-
- **`*/AGENTS.md`** — Module-level architecture guides (in `src/`, `src/render_plan/`, `src/server/`, `clickgraph-ffi/`, `clickgraph-embedded/`, `clickgraph-go/`, `clickgraph-py/`, etc.)
255+
- **`*/AGENTS.md`** — Module-level architecture guides (in `src/`, `src/render_plan/`, `src/server/`, `clickgraph-ffi/`, `clickgraph-embedded/`, `clickgraph-tool/`, `clickgraph-go/`, `clickgraph-py/`, etc.)
230256
- **`docs/wiki/cypher-language-reference.md`** — Primary feature documentation (must be updated for every feature)

Cargo.lock

Lines changed: 107 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ members = [
44
"clickgraph-embedded",
55
"clickgraph-ffi",
66
"clickgraph-tck",
7+
"clickgraph-tool",
78
]
89

910
[package]

DEV_QUICK_START.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,15 @@ cargo test && pytest tests/integration/ && echo "✅ ALL TESTS PASSED"
129129

130130
### Check Generated SQL
131131
```bash
132-
# Use sql_only mode for quick debugging
132+
# Option 1: cg CLI (no server needed — fastest for development)
133+
cg --schema benchmarks/social_network/schemas/social_benchmark.yaml \
134+
sql "MATCH (n:User) RETURN n.name LIMIT 10"
135+
136+
# Validate syntax + planning without execution
137+
cg --schema benchmarks/social_network/schemas/social_benchmark.yaml \
138+
validate "MATCH (n:User)-[:FOLLOWS]->(f) RETURN f.name"
139+
140+
# Option 2: Via server (if already running)
133141
curl -X POST http://localhost:8080/query \
134142
-H "Content-Type: application/json" \
135143
-d '{"query":"MATCH (n) RETURN n","sql_only":true}'

0 commit comments

Comments
 (0)