Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

docs(readme): add crate readmes for core util and tinyhumans

Steven Enamakelbc019663c56d
diff --git a/crates/openhuman-core/src/util/README.md b/crates/openhuman-core/src/util/README.md
index c1d4d81894..253a867dee 100644
--- a/crates/openhuman-core/src/util/README.md
+++ b/crates/openhuman-core/src/util/README.md
@@ -1,34 +1,154 @@
# util
-Kernel helper family. `pub mod util;` in `lib.rs` is unconditional, never
-feature-gated. Helpers reused across domains; nothing here may reach into a
-domain. No file in this directory has a `use crate::` line, and that is the
-rule: a helper that needs config, a `Tool`, a workspace, or security policy
-belongs in the domain that owns those, not here. New external crates are also
-off-limits: this is kernel surface under the `scripts/kernel-floor.limits`
-dependency ratchet, which is why `redact` is a
-six-line copy rather than an engine link.
+Small, self-contained helpers that several domains share: UTF-8-safe text
+truncation, retry with backoff for flaky filesystem operations, log
+redaction, URL normalization, JSON-RPC param decoding, LLM-facing text
+sanitization and the platform TLS choice for `reqwest`. `pub mod util;` in
+`lib.rs` is unconditional, so everything here is compiled in every build.
+
+## How it works
+
+There is no flow here, only a rule about direction. Domains depend on `util`;
+`util` depends on no domain. No file in this folder has a `use crate::` line.
+A helper that needs a `Config`, a `Tool`, a workspace or security policy
+belongs in the domain that owns those things.
+
+```text
+ agent memory tools inference config integrations mcp ...
+ \ | | | | | /
+ +-----+------+--------+--------+----------+--------+
+ |
+ v
+ crate::util (no `use crate::`)
+ |
+ v
+ external crates: serde_json, sha2, url, reqwest, tokio,
+ tracing, anyhow, tinymcp_bus (sanitize)
+```
+
+`util` is kernel surface, so it also sits under the dependency-floor ratchet
+in `scripts/kernel-floor.limits` (checked by `scripts/check-kernel-floor.sh`).
+Adding an external crate here raises the floor of every build. That is why
+`redact` is a few lines of SHA-256 rather than a link to the memory engine's
+copy.
## Layout
-| File | Purpose |
+| Path | What it does |
| --- | --- |
-| `redact.rs` | `redact()`: SHA-256 to 8 hex chars for source ids, entity ids, and content paths in log lines. Same helper as `tinymemory_core::util::redact`, kept as a local copy so the host does not link the memory engine for a log formatter; the two copies never need to agree. |
-| `retry.rs` | `retry_with_backoff` / `retry_with_backoff_async` (`base_ms * 2^i` backoff, `warn!` per retry) and `is_transient_fs_error`, for Windows mandatory-locking errors (`ERROR_SHARING_VIOLATION`, `ERROR_ACCESS_DENIED`) on a tree another handle still holds. |
-| `sanitize.rs` | Pure re-export of `tinymcp_bus::sanitize` (`sanitize_for_llm`, `strip_control_chars`, `strip_instruction_fences`, `truncate_utf8_safe`, `MAX_DESCRIPTION_BYTES`, `MAX_TITLE_BYTES`) at the path callers already use. The rule lives in `tinymcp_bus` so MCP tool descriptions and the orchestrator prompt builder's skill descriptions get the same stripping; do not fork it back here. |
-| `text.rs` | `truncate_with_ellipsis` / `truncate_with_suffix` (char-count truncation), `truncate_at_byte_boundary` (byte-cap with `…`), `floor_char_boundary` / `ceil_char_boundary` / `utf8_safe_prefix_at_byte_boundary` (byte-index rounding). |
-| `types.rs` | `MaybeSet<T>`: `Set(T)` / `Unset` / `Null`, distinguishing "field absent" from "field explicitly null" in partial-update payloads (see `tools/impl/system/proxy_config.rs`). |
-| `tls/` | `tls_client_builder()`: platform-conditional TLS backend for `reqwest` clients. See [tls/README.md](tls/README.md). |
-
-`*_tests.rs` files sit beside each module.
-
-## Public surface
-
-`mod.rs` re-exports `retry`, `text`, and `types` items at the module root, so
-`crate::util::truncate_with_ellipsis`, `crate::util::retry_with_backoff`, and
-`crate::util::MaybeSet` resolve without the submodule. `redact`,
-`sanitize`, and `tls` are reached through their submodule:
-`crate::util::redact::redact`,
-`crate::util::sanitize::sanitize_for_llm`, `crate::util::tls::tls_client_builder`.
-From outside the crate the lib is `openhuman_core`, which is the path the
-`truncate_with_ellipsis` doctest uses.
+| `text.rs` | Char-count truncation (`truncate_with_ellipsis`, `truncate_with_suffix`), byte-capped truncation with an ellipsis (`truncate_at_byte_boundary`), and byte-index rounding to a char boundary (`floor_char_boundary`, `ceil_char_boundary`, `utf8_safe_prefix_at_byte_boundary`). |
+| `retry.rs` | `retry_with_backoff` (sync, `std::thread::sleep`) and `retry_with_backoff_async` (`tokio::time::sleep`), plus `is_transient_fs_error`. |
+| `redact.rs` | `redact` hashes a string to 8 hex chars for log lines. `redact_url_for_log` replaces URL userinfo with `redacted`. |
+| `url.rs` | `normalize_api_base_url`, `normalize_backend_api_base_url`, `join_url`, `host_is_local`. |
+| `params.rs` | `read_required` and `read_optional`, the shared param decoders for controller handlers. |
+| `sanitize.rs` | A re-export of `tinymcp_bus::sanitize`: `sanitize_for_llm`, `strip_control_chars`, `strip_instruction_fences`, `truncate_utf8_safe`, `MAX_DESCRIPTION_BYTES`, `MAX_TITLE_BYTES`. |
+| `types.rs` | `MaybeSet<T>` (`Set`, `Unset`, `Null`). |
+| [`tls/`](tls/README.md) | `tls_client_builder()`, the platform-conditional TLS backend for `reqwest` clients. |
+
+## Key types and entry points
+
+### Text
+
+`truncate_with_ellipsis(s, max_chars)` keeps at most `max_chars` characters
+and appends `...` when it cuts. It counts characters, not bytes, so emoji and
+CJK text never split. `truncate_at_byte_boundary` is the byte-capped
+variant used when a size limit is in bytes (log fields, telemetry payloads).
+`floor_char_boundary` and `ceil_char_boundary` round a byte index to the
+nearest valid char boundary below or above it.
+
+### Retry
+
+`retry_with_backoff(op_name, attempts, base_ms, f)` retries `f` only while
+the error is transient by `is_transient_fs_error`. Any other error returns at
+once. The sleep is `base_ms * 2^i`, capped at 30 seconds. Each retry logs a
+`warn!` (`[util] transient fs retry`), a success after retries logs `info!`,
+and the final error carries `<op_name> failed after <n> attempts` context.
+Use the async version on the tokio executor.
+
+`is_transient_fs_error` walks the `anyhow` chain for an `io::Error` and, on
+Windows, matches the mandatory-locking codes: 5 (`ERROR_ACCESS_DENIED`), 32
+(`ERROR_SHARING_VIOLATION`), 33 (`ERROR_LOCK_VIOLATION`), 303
+(`ERROR_DELETE_PENDING`), 665 (`ERROR_FILE_SYSTEM_LIMITATION`) and 1224
+(`ERROR_USER_MAPPED_FILE`). On other platforms it returns `false`, so the
+helpers run `f` once.
+
+### Redaction
+
+`redact(s)` returns the first 4 bytes of the SHA-256 digest as 8 hex chars.
+It is stable across runs, so a developer holding the raw value can grep for
+it. Use it for source ids, entity ids and content paths, which can embed
+email addresses. `tinymemory_core::util::redact` is an identical, independent
+copy; the two never need to agree because neither reads the other's output.
+
+`redact_url_for_log(raw)` parses the URL (assuming `http://` when the scheme
+is missing), replaces any username and password with `redacted`, and strips a
+trailing slash. An unparseable input comes back trimmed and unchanged.
+
+### URLs
+
+`normalize_api_base_url` trims whitespace and trailing slashes without
+parsing. `normalize_backend_api_base_url` also strips any path, query and
+fragment, so an `api_url` set to a full inference endpoint
+(`.../openai/v1/chat/completions`) becomes a bare origin before backend
+paths are appended; it retries with `https://` for scheme-less values.
+`join_url(base, path)` joins with RFC 3986 rules, which means an absolute
+`path` replaces the base's path. Paths should start with `/`. `host_is_local`
+classifies loopback, unspecified, RFC 1918 IPv4 and `localhost` /
+`*.localhost` hosts using typed `url::Host` matching.
+
+### Params
+
+`read_required::<T>(params, key)` fails with `missing required param '<key>'`
+or `invalid '<key>': <serde error>`. `read_optional` treats an absent key and
+`null` the same (`Ok(None)`). Domain `schemas.rs` files use these so the error
+wording stays one contract.
+
+### Sanitization
+
+The stripping rule for untrusted text going into a model's context lives in
+`tinymcp_bus`, which applies it to every remote MCP tool description. This
+module re-exports it at the old path so the orchestrator prompt builder's
+skill descriptions get the same rule. Change it in `vendor/tinymcp`, not here.
+
+### `MaybeSet`
+
+`MaybeSet<T>` tells "field absent" (`Unset`) apart from "field explicitly
+null" (`Null`) in partial-update payloads. The caller today is
+`tools/impl/system/proxy_config.rs`.
+
+### Re-exports
+
+`mod.rs` re-exports `read_optional`, `read_required`, `redact_url_for_log`,
+the `retry` functions, the `text` functions and `MaybeSet` at the module root,
+so `crate::util::truncate_with_ellipsis` works without naming the submodule.
+`redact::redact`, `sanitize::*`, `url::*` and `tls::tls_client_builder` are
+reached through their submodule path. From outside the crate the library name
+is `openhuman_core`, which is the path the `truncate_with_ellipsis` doctest
+uses.
+
+## Boundaries
+
+- The sanitization rule is owned by `tinymcp_bus` (`vendor/tinymcp`).
+- Hosted-backend URL resolution (defaults, `BACKEND_URL` overrides) belongs
+ to the installed backend transport in `crates/openhuman-tinyhumans`, asked
+ through `crate::backend`. `url.rs` only does string and URL shape work.
+- Secret scrubbing for logs and Sentry lives in `core::log_redaction` and
+ `core::observability`. `redact` is only a stable hash for identifiers.
+
+## Gotchas
+
+- Do not add `use crate::` here. If a helper needs domain types, it belongs in
+ that domain.
+- Do not add external dependencies casually. The kernel-floor ratchet only
+ goes down, and raising it needs a written justification.
+- `retry_with_backoff` blocks the thread while it sleeps. Call
+ `retry_with_backoff_async` from async code.
+- `join_url` with a relative `path` (no leading slash) drops the base's last
+ segment, which is almost never what an API client wants.
+
+## Tests
+
+Tests sit beside each file (`text_tests.rs`, `retry_tests.rs`,
+`redact_tests.rs`, `url_tests.rs`, `params_tests.rs`). Run them with
+`cargo test -p openhuman util::` or `pnpm debug rust util::`. The
+`truncate_with_ellipsis` doctest runs under `cargo test -p openhuman --doc`.
diff --git a/crates/openhuman-tinyhumans/README.md b/crates/openhuman-tinyhumans/README.md
index 696398d422..1e1420d50b 100644
--- a/crates/openhuman-tinyhumans/README.md
+++ b/crates/openhuman-tinyhumans/README.md
@@ -175,7 +175,7 @@ names are `openhuman.<namespace>_<function>`:
| `team` | `get_usage`, `list_members`, `list_teams`, `get_team`, `create_team`, `update_team`, `delete_team`, `switch_team`, `leave_team`, `join_team`, `create_invite`, `remove_member`, `change_member_role`, `list_invites`, `revoke_invite` |
| `referral` | `get_stats`, `claim` |
| `announcements` | `get_latest` |
-| `webhooks` | `list_tunnel`, `create_tunnel`, `get_tunnel`, `update_tunnel`, `delete_tunnel`, `get_bandwidth` (shared namespace) |
+| `webhooks` | `list_tunnels`, `create_tunnel`, `get_tunnel`, `update_tunnel`, `delete_tunnel`, `get_bandwidth` (shared namespace) |
| `auth` | `create_channel_link_token`, `oauth_connect`, `oauth_list_integrations`, `oauth_fetch_integration_tokens`, `oauth_revoke_integration`, `oauth_fetch_client_key` (shared namespace) |
| `channels` | `telegram_login_start`, `telegram_login_check`, `discord_link_start`, `discord_link_check` (shared namespace) |