Skip to main content

Module utils

Module utils 

Source

Structs§

CheckResult
Check result with actionable error message
RetryConfig
Retry configuration
Tokenizer
Token counting utility using character-based estimation. Uses ~4 characters per token as a reasonable approximation.

Enums§

CappedLine
Outcome of one read_line_capped call.
HostClass

Traits§

MutexExt
Extension trait for Mutex to provide safe lock operations

Functions§

check_ollama_available
Check if Ollama is running and responding
check_ollama_model
Check if a specific model is available in Ollama
classify_host
Classify a URL host (hostname or IP literal, with optional [] around an IPv6 literal and an optional trailing FQDN dot).
confirm_or_refuse
Confirm a destructive action (default NO). assume_yes (a --yes/--force flag) is the explicit opt-in for scripted use; without it a non-interactive session refuses rather than proceeding silently. prompt is printed verbatim, followed by [y/N]:.
drain_complete_lines
Drain all complete newline-terminated lines out of buf, decoding each as UTF-8 and dropping the trailing \n. Any partial trailing line stays in buf so the caller can append more bytes and try again.
drain_sse_events
Drain all complete SSE events out of buf, returning the payload of each data: field. The [DONE] sentinel and non-data: fields are filtered out. Each returned String is exactly one event’s data (multi-line data: fields are joined with \n, per the SSE spec).
format_duration
Format a duration in seconds as a human-readable string.
format_relative_timestamp
Format a timestamp as a relative, human-readable string
format_tokens
Format token count for display: “X.Xk” for >= 1000, raw number otherwise.
gpu_vram_bytes
Total GPU VRAM in bytes (best-effort), or None if no GPU is detected.
init_logger
Initialize the logging system with tracing
is_affirmative
Whether s is y/yes (case-insensitive). Default is NO — anything else, including empty input / EOF, is declined.
lock_arc_mutex_safe
Safe lock for Arc<Mutex> - standalone function since we can’t impl on Arc
log_debug
Log a debug message (backward compatible)
log_error
Log an error message with category prefix (backward compatible)
log_info
Log an info message with category prefix (backward compatible)
log_progress
Progress indicator for startup sequence
log_warn
Log a warning message with category prefix (backward compatible)
open_file
Open a file with the platform’s default application. Silently spawns the opener in the background (does not block).
private_temp_dir
Return (creating if needed) a 0700 per-user scratch directory under the app data dir. Callers write transient sensitive files here instead of the shared system temp dir.
read_capped
Like read_file_capped, but reads from an already-open std::fs::File.
read_file_capped
Read at most max_bytes from path. Returns (bytes, truncated) where bytes.len() <= max_bytes and truncated is true when the file was longer than the cap.
read_line_capped
Read one newline-delimited line from reader, refusing to buffer more than max_bytes before the newline.
redact_json
Walk a JSON value and redact every string leaf in place. The recorder uses this to scrub whole structured payloads at the single write choke point.
redact_secrets
Replace credential-shaped substrings of input with [REDACTED].
resolve_api_key
Resolve an API key from the environment.
resolve_api_key_with_fallback
Resolve an API key with a legacy fallback env var.
retry_async
Retry an async operation with exponential backoff, retrying on ANY error. For selective retries (skip terminal errors like HTTP 4xx) use retry_async_if.
retry_async_if
Retry an async operation with exponential backoff, but only while is_retryable returns true for the error. A terminal error (e.g. an HTTP 4xx on a non-idempotent POST) is surfaced immediately instead of being retried max_attempts times (#85).
should_refuse_noninteractive
Fail-closed policy: refuse a destructive/untrusted action when there is no interactive terminal to confirm at and the explicit opt-in was not passed. Also defeats yes | mermaid …, since a pipe is not a TTY.
system_ram_bytes
Total physical system RAM in bytes, or None if it can’t be read. Cached for the process (RAM doesn’t change during a session).
truncate_content
Truncate content to a maximum character count (char-boundary safe)
truncate_web_content
Truncate web content using the default limit