libgrite-cli
Programmatic API for all Grite operations — embed issue tracking, task coordination, and distributed sync directly into your Rust applications.
libgrite-cli exposes every command the grite binary supports as a clean, composable library function. This makes it easy to build custom workflows, integrate issue tracking into existing applications, create multi-agent harnesses, or write automation scripts that interact with Grite repositories.
If you are building a Rust application that needs programmatic issue tracking, agent orchestration, or git-backed task management, this crate is your entry point.
What This Crate Provides
Complete Command Coverage
Every CLI command has a corresponding library function:
| Module | Operations |
|---|---|
issue |
create, list, show, update, close, reopen, comment, label, assign, link, attach |
actor |
init, list, show, set_default |
sync |
pull, push, merge, snapshot, rebuild |
context |
extract, query (tree-sitter symbol extraction) |
lock |
acquire, release, status, list |
daemon |
start, stop, status |
Context Resolution
The GriteContext type handles all the complexity of finding repositories, resolving actors, and choosing execution modes (daemon vs. standalone):
use ;
// Automatically resolves the git repo, actor, and execution mode
let ctx = resolve?;
GriteContext automatically:
- Discovers the git repository from the current directory or ancestors
- Loads the default actor configuration
- Detects whether the daemon is running and prefers IPC when available
- Falls back to standalone mode if the daemon is unavailable
Async Support
Enable the async feature for tokio-based wrappers around all sync operations:
[]
= { = "0.5", = ["async"] }
use issue_create_async;
// Run issue creation in a blocking task pool
let result = issue_create_async.await?;
Every sync function has an *_async counterpart that runs the operation in tokio::spawn_blocking, preventing event loop blocking during database operations.
Type-Safe Options
Every operation takes a dedicated options struct with strongly typed fields:
use IssueCreateOptions;
let options = IssueCreateOptions ;
This eliminates stringly-typed APIs and provides compile-time guarantees about which options are valid for which operations.
Key Modules
context
Repository and actor resolution:
use ;
let ctx = resolve?;
issue
Full issue lifecycle management:
use ;
// Create an issue
let result = issue_create?;
// List open issues
let issues = issue_list?;
// Show details
let issue = issue_show?;
actor
Multi-actor identity management:
use ;
// Initialize a new actor
let actor = actor_init?;
// List all actors
let actors = actor_list?;
// Set default
actor_set_default?;
sync
Distributed synchronization:
use ;
// Pull remote changes
sync_pull?;
// Push local changes
sync_push?;
// Rebuild materialized view from WAL
sync_rebuild?; // true = from snapshot
lock
Distributed resource locking:
use ;
// Claim exclusive access to a resource
lock_acquire?; // TTL: 1 hour
// Release when done
lock_release?;
async_wrappers
Tokio-compatible async variants:
use ;
let issues = issue_list_async.await?;
Quick Example
use ;
Architecture
libgrite-cli (programmatic API)
|
+-- libgrite-core (data model, storage, CRDTs)
+-- libgrite-git (WAL, sync, snapshots)
+-- libgrite-ipc (daemon communication, optional)
The library abstracts over the underlying crates, providing a unified interface regardless of whether the daemon is running. When the daemon is available, operations are dispatched via IPC. When it is not, the library opens the database directly.
Why Use the Library Instead of the CLI?
For Application Developers
If you are building an application that needs issue tracking (a CI system, a project management tool, an agent harness), shelling out to the CLI is fragile:
- Parsing output — You must parse human-readable output or JSON from stdout.
- Error handling — Exit codes are coarse. You lose structured error information.
- Performance — Every invocation pays process startup cost.
- State management — You must manage working directory and environment variables.
The library gives you:
- Native Rust types — Results are structs, not strings.
- Rich errors — Every error variant is typed and carry context.
- In-process execution — No process overhead. Direct function calls.
- Composable — Build higher-level abstractions by combining library functions.
For Agent Harnesses
Multi-agent systems need to query and update issue state at high frequency:
// An agent harness can query issues, claim locks, and post updates
// without ever shelling out to a subprocess
loop
Configuration
Library behavior is controlled through ResolveOptions and environment variables:
| Variable | Description |
|---|---|
GRITE_GIT_DIR |
Override the detected .git directory |
GRITE_ACTOR_ID |
Override the default actor |
GRITE_NO_DAEMON |
Force standalone mode (no IPC) |
See Also
- Grite Repository — Main project and documentation
- grite — The CLI binary that wraps this library
- libgrite-core — Data model and storage engine
- libgrite-git — Git-backed WAL and sync
- docs.rs/libgrite-cli — Full Rust API documentation
License
MIT License — see LICENSE for details.