Skip to content

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

docs(hosting): add README for the hosting module

Steven Enamakel23e2969c6ee6
diff --git a/crates/openhuman-core/src/hosting/README.md b/crates/openhuman-core/src/hosting/README.md
index 35bfa3a032..08dc2eace4 100644
--- a/crates/openhuman-core/src/hosting/README.md
+++ b/crates/openhuman-core/src/hosting/README.md
@@ -1,31 +1,92 @@
# hosting
-Puts a workspace on the internet. This domain is the seam between OpenHuman and
-[`tinyhosts`](../../../../vendor/tinyhosts), the unified hosting API: TinyHosts owns
-everything about a provider, and this module owns everything about OpenHuman.
-
-## Responsibilities
-
-- Resolve the configured hosting account (`Account::from_config`) from
- `[hosting]`, falling back to the provider's own environment variables.
-- Hand the crate's ten `hosting_*` agent tools (`tinyhosts::tools`, its `tools`
- feature) the account's host and workspace; `resolve_in_workspace` (which
- decides which directory an agent may deploy) is re-exported from there.
-
-Everything else belongs to the crate: Vercel's endpoints, the upload-then-build
-deployment protocol, how a marketplace database is provisioned and connected,
-and the order a launch runs in. That side is provider-independent and tested
-against a mock of the provider's REST API. Nothing here knows the word `readyState`.
+Puts a workspace on the internet. This domain is the thin seam between
+OpenHuman and [`tinyhosts`](../../../../vendor/tinyhosts), the unified hosting
+API. TinyHosts owns everything about a provider (today, Vercel): its REST
+endpoints, the upload-then-build deployment protocol, how a marketplace
+database is provisioned and connected, and the order a launch runs in. This
+module owns the OpenHuman side: where the credential comes from, which
+workspace the agent deploys from, and whether the tools are offered at all.
+
+The whole domain is one file, `mod.rs`, around a single type, `Account`.
+
+## How it works
+
+At tool-registry build time, `tools::ops` (in `src/tools/ops.rs`) asks this
+module for an account. If one resolves, the account's ten tools are appended
+to the agent's tool list. If none resolves, nothing is registered.
+
+```text
+ tools::ops (registry build, #[cfg(feature = "hosting")])
+ |
+ v
+ Account::from_config(&Config)
+ |
+ |-- [hosting].enabled == false ----------------> Ok(None) (no tools)
+ |
+ |-- ProviderKind::from_str(provider) (bad slug -> Err, logged at warn)
+ |
+ |-- [hosting].api_key set?
+ | yes -> Credentials::new(key) [+ with_team(team)]
+ | no -> provider.credentials_from_env()
+ | not found ---------------------> Ok(None) (no tools)
+ |
+ v
+ tinyhosts::connect(provider, credentials) -> Arc<dyn Host>
+ |
+ v
+ Account { host, workspace_dir }
+ |
+ v
+ account.tools() = tinyhosts::tools::hosting_tools(&host, &workspace_dir)
+```
+
+`from_config` separates "absent" from "wrong". Hosting switched off, or
+switched on with no key anywhere, is the ordinary state of a host nobody has
+connected a provider to, so it returns `Ok(None)` and logs at `debug`. An
+unknown provider slug, a blank configured key, or a client that fails to build
+is a misconfiguration: it returns an error, which `tools::ops` logs at `warn`
+and then skips. Startup does not fail, since nothing else in the process
+depends on hosting.
+
+The reason absent credentials mean absent tools: a tool that is present and
+cannot work is worse than one that is missing, because a model will retry it.
+
+Embedders that hold their own credential use `Account::connect(provider,
+api_key, team, workspace_dir)` instead. It takes the provider slug and key as
+plain strings, so a host (OpenCompany keeps one hosting key per company in that
+company's secret store) can reach the tools without naming `tinyhosts` in its
+own dependency graph.
+
+Configuration lives in `HostingConfig` (`src/config/schema/hosting.rs`):
+`enabled`, `provider` (default `vercel`), `api_key` (empty means "read the
+provider's environment variable"), and `team` (empty means the personal
+account). Its `Debug` impl redacts the key.
+
+## Layout
+
+| Path | What it does |
+| --- | --- |
+| `mod.rs` | `Account`: `from_config` credential resolution, `connect` for embedders, the shared `Arc<dyn Host>`, `tools()`, and the `resolve_in_workspace` re-export. |
-## Key files
+## Key types and entry points
-| File | Role |
-| --- | --- |
-| `mod.rs` | `Account` (`from_config` credential resolution, `connect` for embedders that hold their own key, the shared `dyn Host`) and the `resolve_in_workspace` re-export. |
-| `hosting_tests.rs` | Account resolution, workspace containment, and each tool's contract. |
+- `Account` (`mod.rs`) is one hosting account plus the workspace it deploys
+ from. Its `Debug` prints the provider slug and workspace, never the client.
+- `Account::from_config` resolves an account from `[hosting]` and the
+ environment, as described above.
+- `Account::connect` builds an account from credentials an embedder resolved.
+- `Account::tools` returns the ten `hosting_*` tools as
+ `Vec<Box<dyn tinytools::Tool>>`.
+- `resolve_in_workspace` is re-exported from `tinyhosts::tools`. It decides
+ which directory an agent may deploy.
## Agent tools
+All ten are implemented in `vendor/tinyhosts/src/tools/`. Tools with an
+external effect return `true` from `Tool::external_effect`, which the agent
+harness reads to route the call through approval.
+
| Tool | Effect |
| --- | --- |
| `hosting_launch_site` | Deploys a workspace directory as a live site, optionally provisioning a database and wiring it in, setting environment variables, and attaching domains. External effect. |
@@ -39,48 +100,57 @@ against a mock of the provider's REST API. Nothing here knows the word `readySta
| `hosting_domain_status` | Whether a site's domains are verified and serving. Read-only. |
| `hosting_analytics` | Traffic over the last N days. Read-only. |
-### Why there is a rollback and no separate promote
+### Rollback, and why there is no separate promote
-`Host::promote` is both: a rollback *is* a promote of an older deployment, and
-the crate models it once rather than twice. The tool is named for the reason an
-agent reaches for it.
+`Host::promote` covers both: a rollback is a promote of an older deployment,
+and the crate models it once. The tool is named for the reason an agent
+reaches for it, which is recovering a site a deploy broke.
-`hosting_rollback` reads the deployment before promoting it and refuses one that
-did not finish building. `hosting_list_deployments` returns failed and
+`hosting_rollback` reads the deployment before promoting it and refuses one
+that did not finish building. `hosting_list_deployments` returns failed and
still-building deployments too, because they are the history an agent is
-reading. So the id it picks is not necessarily one that can serve traffic, and
-promoting a failed build would take the site down during an attempt to bring it
-back up. It does **not** check that the deployment belongs to the named site: a
+reading, so the id an agent picks is not necessarily one that can serve
+traffic. Promoting a failed build would take the site down during an attempt
+to bring it back up.
+
+The tool does not check that the deployment belongs to the named site. A
deployment is looked up by id alone and the provider's response may omit the
project name, so that check would refuse legitimate rollbacks. The provider
-owns it.
-
-## Gating
-
-Two gates, and both matter:
-
-- The `hosting` Cargo feature (default-OFF, product-ON). Off, the domain is not
- compiled at all.
-- A credential that actually resolves. `Account::from_config` returns `Ok(None)`
- when `[hosting].enabled` is false or no key is found anywhere, and
- `tools::ops` then registers nothing. A tool that is present and cannot work is
- worse than one that is absent, because a model retries it.
-
-A *misconfigured* section (an unknown provider slug, a blank configured key) is
-an error rather than a silent skip, logged at `warn` by the registry.
-
-## Two things this domain will not do
-
-- **Read a secret.** A managed database's connection string is injected by the
- provider into the site's environment. This process learns the *names* of the
- variables and never their values, which is why `hosting_launch_site` reports
- `DATABASE_URL` rather than a URL.
-- **Deploy something the user did not name.** `resolve_in_workspace` refuses an
- absolute path, a `..` escape, and a non-directory. It is the only place that
- decides what may leave the machine, and a deployment uploads every byte under
- the directory it is given.
-
-## Events
-
-None. No `bus.rs`, no `EventHandler`. Approval routing is via the
-`Tool::external_effect` hook the agent harness reads.
+enforces it.
+
+## Boundaries
+
+- Provider behavior (endpoints, deployment states, database provisioning,
+ launch ordering, the tool implementations and their argument validation)
+ belongs to `tinyhosts` (`vendor/tinyhosts`, upstream
+ `tinyhumansai/tinyhosts`). Nothing in this module knows the word
+ `readyState`, and nothing in `tinyhosts` knows what a workspace is.
+- Approval routing belongs to the agent harness, via `external_effect`.
+- There are no RPC controllers and no events: no `schemas.rs`, no `bus.rs`.
+
+## Gotchas
+
+- Two gates both have to pass. The `hosting` Cargo feature (default-off in the
+ contributor build, on in `scripts/ci/product-features.txt`) decides whether
+ `openhuman::hosting` compiles at all. A resolving credential decides whether
+ the tools register at runtime.
+- This process never reads a managed database's secret. The provider injects
+ the connection string into the site's environment; OpenHuman learns only the
+ variable names. That is why `hosting_launch_site` reports `DATABASE_URL`
+ rather than a URL.
+- `resolve_in_workspace` refuses absolute paths, `..` escapes, and
+ non-directories. It is the only place that decides what may leave the
+ machine, and a deployment uploads every byte under the directory it is given.
+- The doc comment in `src/config/schema/hosting.rs` mentions
+ `crate::hosting::credentials`, which does not exist. Credential resolution is
+ `Account::from_config`.
+
+## Tests
+
+`hosting_tests.rs` covers the seam only: account resolution from config and
+the tool set handed back. The tools themselves, workspace containment, and the
+rollback guard are tested in `tinyhosts` against a mock of the provider API.
+
+```bash
+cargo test -p openhuman --features hosting hosting::
+```