Skip to main content

Crate trusty_common

Crate trusty_common 

Source
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).

Structs§

ChatMessage
OpenAI-compatible chat message.

Functions§

bind_with_auto_port
Bind to addr; if the port is in use, walk forward up to max_attempts ports and return the first listener that binds.
init_tracing
Initialise the global tracing subscriber.
is_dir
Check whether a path exists and is a directory.
maybe_disable_color
Disable coloured terminal output when requested or when stdout is not a TTY.
openrouter_chat
Send a chat completion request to OpenRouter and return the assistant’s message content.
openrouter_chat_stream
Stream chat-completion deltas from OpenRouter through a tokio mpsc channel.
read_daemon_addr
Read the daemon’s HTTP address from the app’s data directory.
resolve_data_dir
Resolve <data_dir>/<app_name>, creating it if it doesn’t exist.
write_daemon_addr
Write the daemon’s bound HTTP address to the app’s data directory.