Skip to main content

Module utils

Module utils 

Source

Modules§

serde_base64
Serde adapter: Vec<u8> ↔ base64 string.

Structs§

RetryConfig
Retry configuration

Enums§

CappedLine
Outcome of one read_line_capped call.
Grace
How aggressively to tear a tree down.
HostClass

Functions§

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
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.
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).
output_with_timeout
Run cmd to completion with a deadline, capturing stdout/stderr — a Command::output() that cannot hang. On expiry the child is killed and (bounded-best-effort) reaped, and ErrorKind::TimedOut comes back. stdin is null.
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).
terminate_tree
Terminate pid’s process tree (async). Safe to call on a pid that has already exited — signals are best-effort and every error is swallowed.
terminate_tree_blocking
Blocking sibling for sync call sites (the daemon’s /stop / /restart run off a sync runtime client and can’t await).
truncate_content
Truncate content to a maximum character count (char-boundary safe)
truncate_web_content
Truncate web content using the default limit
write_stdin_with_timeout
Feed input to cmd’s stdin and wait for exit under a deadline — the write-side sibling of output_with_timeout. stdout/stderr go to null, so tools that fork a long-lived holder of their fds (wl-copy and xclip serve the selection from a background fork) can’t pin any pipe of ours.