claude_storage/lib.rs
1#![ cfg_attr( doc, doc = include_str!( concat!( env!( "CARGO_MANIFEST_DIR" ), "/", "readme.md" ) ) ) ]
2
3//! # `claude_storage` - CLI Tool for Claude Code Storage
4//!
5//! Command-line interface for exploring and analyzing Claude Code's filesystem-based storage.
6//!
7//! ## Overview
8//!
9//! This crate provides a CLI tool for querying Claude Code's conversation storage at `~/.claude/`.
10//! It wraps the `claude_storage_core` library with an interactive REPL and one-shot command interface.
11//!
12//! **Extraction context**: This is the CLI-focused crate after extracting core library functionality
13//! to `claude_storage_core` (2025-11-29). All storage access logic now lives in the core library;
14//! this crate provides the command-line interface.
15//!
16//! ## Usage
17//!
18//! ### REPL mode (interactive):
19//! ```bash
20//! cargo run --features cli
21//! > .status
22//! > .list target::projects
23//! > exit
24//! ```
25//!
26//! ### One-shot mode (scripting):
27//! ```bash
28//! cargo run --features cli -- .status
29//! cargo run --features cli -- .count target::projects
30//! ```
31//!
32//! ## CLI Commands
33//!
34//! - `.status` - Show storage statistics (projects, sessions, entries, tokens)
35//! - `.list` - List projects or sessions with optional filtering
36//! - `.show` - Display details about a specific session
37//! - `.count` - Fast counting of entries, sessions, or projects
38//!
39//! ## Library API
40//!
41//! For programmatic access to Claude Code storage, use the `claude_storage_core` crate directly:
42//!
43//! ```rust,no_run
44//! use claude_storage_core::{ Storage, ProjectId };
45//!
46//! fn main() -> claude_storage_core::Result< () >
47//! {
48//! let storage = Storage::new()?;
49//! for project in storage.list_projects()?
50//! {
51//! println!( "Project: {:?}", project.id() );
52//! }
53//! Ok( () )
54//! }
55//! ```
56
57#![deny( missing_docs )]
58#![warn( rust_2018_idioms )]
59
60// Re-export core library types for convenience
61pub use claude_storage_core::
62{
63 encode_path,
64 decode_path,
65 Error,
66 Result,
67 Entry,
68 EntryType,
69 MessageContent,
70 UserMessage,
71 AssistantMessage,
72 ContentBlock,
73 ThinkingMetadata,
74 Session,
75 Project,
76 ProjectId,
77 Storage,
78 JsonValue,
79 parse_json,
80 SessionStats,
81 GlobalStats,
82 ProjectStats,
83 stats,
84};
85
86/// Absolute path to this crate's command definitions YAML.
87///
88/// Use in `build.rs` for compile-time aggregation or at runtime for dynamic registration.
89pub const COMMANDS_YAML : &str = concat!( env!( "CARGO_MANIFEST_DIR" ), "/unilang.commands.yaml" );
90
91#[cfg( feature = "cli" )]
92pub mod cli;
93
94#[cfg( feature = "cli" )]
95pub mod cli_main;
96
97#[cfg( feature = "cli" )]
98pub use cli::parse_project_parameter;
99
100#[ cfg( feature = "cli" ) ]
101/// Register `claude_storage` commands into an existing registry.
102///
103/// Commands are defined in [`COMMANDS_YAML`] for compile-time aggregation
104/// (used by `assistant/build.rs`). This function is provided for API consistency with
105/// other Layer 2 crates; the body is intentionally empty because runtime registration of
106/// `claude_storage` commands is handled by the build-time YAML aggregation path in `assistant`.
107#[ inline ]
108pub fn register_commands( _registry : &mut unilang::registry::CommandRegistry ) {}