Expand description
Shared utility surface for trusty-* projects.
Why: Port auto-detect, data-directory resolution, tracing init, NO_COLOR handling, and the OpenRouter chat-completions client appeared in both trusty-memory and trusty-search with subtle divergence. Centralising keeps them aligned and gives future trusty-* binaries a one-import surface.
What: pure utility functions — no global state. Each subsystem is a free function or a small helper struct.
Test: cargo test -p trusty-common covers port walking, data-dir creation,
and the OpenRouter request shape (without hitting the network).
§Test isolation: TRUSTY_DATA_DIR_OVERRIDE
macOS’s dirs::data_dir() resolves the application-support directory via
NSFileManager, a native Cocoa API that completely ignores the HOME and
XDG_DATA_HOME environment variables. This makes it impossible to redirect
data-directory access in tests using ordinary env-var tricks, because the
kernel query bypasses the environment entirely.
To work around this, resolve_data_dir checks the
DATA_DIR_OVERRIDE_ENV (TRUSTY_DATA_DIR_OVERRIDE) environment variable
before consulting dirs::data_dir(). When set, the variable’s value is used
as the base directory verbatim, and dirs::data_dir() is never called.
This escape hatch is intended for testing only. Do not set it in production deployments; rely on the OS-standard data directory instead.
Re-exports§
pub use shutdown::shutdown_signal;pub use slug::slugify_string;pub use index_id::derive_index_id;pub use index_id::resolve_project_root;pub use palace_id::PALACE_OVERRIDE_ENV;pub use palace_id::derive_palace_id;pub use palace_id::owner_repo_from_git_remote;pub use palace_id::palace_override_from_env;pub use palace_id::parent_dir_slug;pub use palace_id::repo_slug_from_git_remote;pub use chat::BedrockProvider;pub use chat::ChatEvent;pub use chat::ChatProvider;pub use chat::DEFAULT_BEDROCK_MODEL;pub use chat::LocalModelConfig;pub use chat::OllamaProvider;pub use chat::OpenRouterProvider;pub use chat::ToolCall;pub use chat::ToolDef;pub use chat::auto_detect_local_provider;pub use port::bind_with_auto_port;pub use data_dir::DATA_DIR_OVERRIDE_ENV;pub use data_dir::is_dir;pub use data_dir::resolve_data_dir;pub use data_dir::sanitize_data_root;pub use daemon_addr::check_already_running;pub use daemon_addr::read_daemon_addr;pub use daemon_addr::remove_daemon_addr;pub use daemon_addr::write_daemon_addr;pub use health_probe::probe_health;pub use tracing_init::init_tracing;pub use tracing_init::init_tracing_with_buffer;pub use tracing_init::maybe_disable_color;pub use openrouter_legacy::ChatMessage;pub use openrouter_legacy::openrouter_chat;Deprecated pub use openrouter_legacy::openrouter_chat_stream;Deprecated
Modules§
- bin_
resolve - Robust executable discovery and daemon
PATHcomposition. - chat
- Provider-agnostic streaming chat abstraction with tool-use support.
- claude_
config - Claude Code configuration discovery and patching.
- daemon_
addr - Daemon HTTP-address file helpers.
- daemon_
guard - Shared CLI daemon-guard helper (probe + spinner + spawn).
- data_
dir - Data-directory resolution and filesystem utilities.
- github_
path - Shared GitHub
owner/repopath derivation (issue #1220). - health_
probe - HTTP health-probe helper.
- index_
id - Canonical trusty-search index-id derivation from a project path (issue #1373).
- log_
buffer - Bounded in-memory ring buffer of recent tracing log lines.
- openrouter_
legacy - Deprecated single-shot OpenRouter helpers.
- palace_
alias - Palace-level alias map: redirect one palace name to another (issue #1939).
- palace_
id - Canonical trusty-memory palace-ID derivation from project identity (#1217/#1605).
- port
- TCP port auto-walking helper.
- project_
discovery - Claude Code project directory discovery.
- shutdown
- Shared graceful-shutdown signal helper for trusty-* daemons (issue #534).
- slug
- Canonical project-slug derivation (issue #1348).
- sys_
metrics - Process RSS / CPU sampling and data-directory sizing for daemon health.
- tracing_
init - Global tracing subscriber initialisation helpers.