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§
- Chat
Message - OpenAI-compatible chat message.
Functions§
- bind_
with_ auto_ port - Bind to
addr; if the port is in use, walk forward up tomax_attemptsports 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.