Merge _configs/ into config/ for single configuration directory. Update all path references. Changes: - Move _configs/* to config/ - Update .gitignore for new patterns - No code references to _configs/ found Impact: -1 root directory (layout_conventions.md compliance)
Tools Shared Rust Library
Shared utilities for all Tools ecosystem Rust CLIs.
Overview
This library provides common functionality used across all Tools CLIs:
- Configuration Discovery - Automatic search for configuration files in standard locations
- Manifest Management - Track installed resources and their types
- Database Path Resolution - Smart database file location detection
- Project Detection - Auto-detect projects from
.project/or.vapora/ - Project Selection - Interactive project picker with arrow keys
- Database Migrations - SQL migration discovery and execution
- XDG Directories - Cross-platform standard directory support
- Global Database Support - Multi-project database management
Installation
Add to your Cargo.toml:
[dependencies]
tools-shared = { path = "../../shared/rust" }
From a tools CLI (e.g., crates/tracking-cli):
tools-shared = { path = "../../../shared/rust" }
Usage
Configuration Discovery
Find configuration files automatically:
use tools_shared::find_config_path;
use std::path::PathBuf;
// Search for a config file (returns first found)
let config_path = find_config_path("tracking.toml");
match config_path {
Some(path) => println!("Using config: {}", path.display()),
None => println!("No config found"),
}
Database Path Resolution
Find or create database paths:
use tools_shared::find_db_path;
// Automatically searches and returns PathBuf with fallback
let db_path = find_db_path("tracking.db");
// Returns: .project/tracking.db (with fallback to .project/ if not found)
println!("Database: {}", db_path.display());
Manifest Management
Track installed resources (requires manifest feature):
use tools_shared::{Manifest, ResourceType};
use std::path::Path;
// Load manifest
let manifest = Manifest::load(Path::new(".project/manifest.toml"))?;
// Check if config is enabled
if manifest.is_enabled("tracking") {
println!("Tracking is enabled");
}
// Get all enabled configs
for config in manifest.enabled_configs() {
println!("Using: {}", config.name);
}
Configuration Discovery Order
All Tools CLIs automatically search for configurations in this order:
.project/{name}- External projects using Tools (PRIORITY).vapora/{name}- VAPORA platform projects.coder/{name}- Documentation tracking projects- Current directory - Fallback
The library uses first found - it stops searching once it finds a match.
Examples
In a CLI main.rs
use tools_shared::find_db_path;
use std::path::PathBuf;
#[tokio::main]
async fn main() -> Result<()> {
// Resolve database path using smart search
let db_path = find_db_path("tracking.db");
let db_url = format!("sqlite:///{}", db_path.display());
// Initialize database
let db = TrackingDb::new(&db_url).await?;
Ok(())
}
With explicit fallback
use tools_shared::find_config_path_or;
// Find config or use explicit default
let config = find_config_path_or("app.toml", "config/app.toml");
Project Detection
Automatically detect projects from configuration files in the current working directory or parents:
use tools_shared::detect_project_from_cwd;
// Auto-detect project from CWD searching upward
if let Some(project) = detect_project_from_cwd("config.toml") {
println!("Project: {}", project.name);
println!("Config: {}", project.config_path.display());
println!("Root: {}", project.root_path.display());
}
The detection searches in this order:
.project/lifecycle.toml(Tools projects).vapora/lifecycle.toml(VAPORA projects)- Parent directories recursively
Project Selection
Interactively select from a list of projects with arrow keys (requires interactive feature):
use tools_shared::{select_project, SelectableProject};
let projects = vec![
SelectableProject {
id: "proj-1".to_string(),
name: "My Project".to_string(),
path: Some("/home/user/projects/my-project".to_string()),
metadata: Some("Phase: Development".to_string()),
},
];
match select_project(projects, "Select a project:", None) {
Ok(selected_id) => println!("Selected: {}", selected_id),
Err(e) => println!("Cancelled: {}", e),
}
Database Migrations
Find and manage SQL migration files in data/migration/:
use tools_shared::{find_migration_files, run_migration_file, has_migration_directory};
// Find all migration files
let migrations = find_migration_files(".")?;
println!("Found {} migrations", migrations.len());
// Check if migration directory exists
if has_migration_directory(".") {
// Get migration file list
let filenames = list_migration_files(".")?;
}
// Run a single migration
run_migration_file("migrations/001_initial.sql")?;
XDG Directories
Cross-platform standard directory support:
use tools_shared::{tool_data_dir, tool_config_dir, tool_cache_dir, ensure_dir};
// Get standard directories
let data_dir = tool_data_dir("my-tool"); // ~/.local/share/tools/my-tool
let config_dir = tool_config_dir("my-tool"); // ~/.config/tools/my-tool
let cache_dir = tool_cache_dir("my-tool"); // ~/.cache/tools/my-tool
// Ensure directory exists
ensure_dir(&data_dir)?;
Global Database Support
Use a single global database for multiple projects:
use tools_shared::find_global_db_path;
// Get global database path
let global_db = find_global_db_path("my-tool");
// Returns: ~/.local/share/tools/my-tool/my-tool.db
Features
config-discovery (default)
Provides configuration file discovery utilities:
find_config_path(filename)- ReturnsOption<PathBuf>find_config_path_or(filename, default)- ReturnsPathBufwith fallbackfind_db_path(filename)- ReturnsPathBuffor database filesfind_config_path_warn_conflicts(filename)- Warns if multiple config locations exist
interactive (optional)
Enables interactive project selection with arrow keys:
select_project()- Interactive project picker using inquire- Requires
inquirecrate
Enable in Cargo.toml:
tools-shared = { path = "../../shared/rust", features = ["interactive"] }
manifest (optional, requires serde, toml)
Provides manifest management:
ManifeststructConfigEntrystructResourceTypeenum- TOML serialization/deserialization
Enable in Cargo.toml:
tools-shared = { path = "../../shared/rust", features = ["manifest"] }
Always Included
Project Detection:
DetectedProjectstructdetect_project_from_cwd(config_filename)- Auto-detect from CWDdetect_project_from_path(path, config_filename)- Auto-detect from specific pathload_last_project(tool_name)- Load cached project selectionsave_last_project(tool_name, project_id)- Cache project selection
Project Selection Helpers:
SelectableProjectstructformat_project_option()- Format project for display
XDG Directories:
tool_data_dir(tool_name)- Standard data directorytool_config_dir(tool_name)- Standard config directorytool_cache_dir(tool_name)- Standard cache directoryensure_dir(path)- Create directory if needed
Global Databases:
find_global_db_path(tool_name)- Get global database pathfind_global_db_path_custom(tool_name, filename)- Custom global database pathglobal_db_exists(tool_name)- Check if global database exists
Database Migrations:
run_migration_file(file_path)- Execute SQL migration from filefind_migration_files(root_path)- Find all.sqlfiles indata/migration/list_migration_files(root_path)- Get migration filenames onlymigration_directory(root_path)- Get migration directory pathhas_migration_directory(root_path)- Check if migration directory exists
Testing
Run tests:
# All tests
cargo test -p tools-shared
# Specific module
cargo test -p tools-shared config_finder::tests
# With output
cargo test -p tools-shared -- --nocapture
Module Structure
shared/rust/
├── lib.rs # Module exports
├── config_finder.rs # Configuration discovery
├── manifest_manager.rs # Manifest management
├── xdg.rs # XDG directories
├── global_db.rs # Global database paths
├── project_detection.rs # Project auto-detection
├── project_selector.rs # Interactive selection
├── db_migration.rs # SQL migrations
└── Cargo.toml # Package definition
Integration Points
This library is used by all Tools ecosystem CLIs:
Rust CLIs
- syntaxis-cli - All features (detection, selection, migrations, global DB)
- tracking-cli - Configuration discovery & database paths
- doc-syntaxis-cli - Configuration discovery & project detection
- hello-tool (example) - All features (detection, selection, migrations)
Can Be Used By
- presentation-generator - Configuration discovery
- Any new Tools ecosystem CLI
Maintenance
When updating the library:
- Update version in
Cargo.toml - Run tests:
cargo test -p tools-shared - Check all CLIs still compile:
cargo check --workspace - Update documentation
API Stability
This library follows semantic versioning:
- Major version: Breaking changes to public API
- Minor version: New features, backward compatible
- Patch version: Bug fixes
Current version: 0.1.0 (experimental)
Contributing
When adding new functionality:
- Add to appropriate module (config_finder.rs or manifest_manager.rs)
- Export from lib.rs
- Add unit tests
- Update this README
- Verify all CLIs still compile
License
MIT OR Apache-2.0
Same as all Tools projects.