The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(hosting): add hosting_deployment_logs
Ghost Scripter3e42bdc0d93c
diff --git a/src/openhuman/hosting/README.md b/src/openhuman/hosting/README.mdindex 27c5055195..5f7b6b56c3 100644--- a/src/openhuman/hosting/README.md+++ b/src/openhuman/hosting/README.md@@ -9,7 +9,7 @@ everything about a provider, and this module owns everything about OpenHuman.- Resolve the configured hosting account (`Account::from_config`) from`[hosting]`, falling back to the provider's own environment variables.- Decide which directory an agent may deploy (`resolve_in_workspace`).-- Expose the nine `hosting_*` agent tools and describe their results to a model.+- Expose the ten `hosting_*` agent tools and describe their results to a model.Everything else — Vercel's endpoints, the upload-then-build deployment protocol,how a marketplace database is provisioned and connected, the order a launch runs@@ -21,7 +21,7 @@ mock of the provider's REST API. Nothing here knows the word `readyState`.| File | Role || --- | --- || `mod.rs` | `Account` (credential resolution + the shared `dyn Host`) and `resolve_in_workspace`. |-| `tools.rs` | The nine agent tools. |+| `tools.rs` | The ten agent tools. || `test.rs` | Account resolution, workspace containment, and each tool's contract. |## Agent tools@@ -31,6 +31,7 @@ mock of the provider's REST API. Nothing here knows the word `readyState`.| `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. || `hosting_deployment_status` | Whether a build has finished. Read-only. || `hosting_list_deployments` | A site's recent deployments, newest first, with status and target. Read-only. |+| `hosting_deployment_logs` | A deployment's build and runtime log events, oldest first, trimmed to the most recent. Read-only. || `hosting_rollback` | Points production back at an earlier deployment that already built. External effect. || `hosting_list_sites` | The sites on the account. Read-only. || `hosting_set_env` | Sets environment variables on an existing site. External effect. |diff --git a/src/openhuman/hosting/hosting_tests.rs b/src/openhuman/hosting/hosting_tests.rsindex 9416655546..7b136227e1 100644--- a/src/openhuman/hosting/hosting_tests.rs+++ b/src/openhuman/hosting/hosting_tests.rs@@ -91,6 +91,7 @@ fn an_account_exposes_every_hosting_tool() {"hosting_launch_site","hosting_deployment_status","hosting_list_deployments",+ "hosting_deployment_logs","hosting_rollback","hosting_list_sites","hosting_set_env",@@ -509,3 +510,107 @@ async fn domain_status_distinguishes_a_verified_domain_from_a_pending_one() {read domains: {domains}");}++/// The read an agent reaches for once `hosting_deployment_status` says a build+/// failed. A status carries one error line; the reason is in the events.+#[tokio::test]+async fn deployment_logs_report_the_build_error_behind_a_failed_status() {+ let server = MockServer::start().await;++ Mock::given(method("GET"))+ .and(path("/v3/deployments/dpl_broken/events"))+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({+ "events": [+ {"created": 1, "type": "stdout", "payload": "installing dependencies"},+ {"created": 2, "type": "stderr", "payload": "error TS2304: cannot find name 'foo'"}+ ]+ })))+ .mount(&server)+ .await;++ let result = tools::DeploymentLogsTool::new(host_against(&server))+ .execute(json!({"deployment_id": "dpl_broken"}))+ .await+ .expect("the tool reports rather than panics");++ assert!(!result.is_error, "{result:?}");++ let logs: serde_json::Value =+ serde_json::from_str(&result.text()).expect("the tool answers with JSON");+ let rows = logs.as_array().expect("an array of events");++ assert_eq!(rows.len(), 2, "{logs}");+ // Oldest first, as the crate documents, and each message bound to its kind:+ // a log that reported the right lines against the wrong streams would show+ // a build error as ordinary output and hide the one line worth reading.+ assert_eq!(rows[0]["kind"], "stdout", "{logs}");+ assert_eq!(rows[1]["kind"], "stderr", "{logs}");+ assert!(+ rows[1]["message"]+ .as_str()+ .expect("a message")+ .contains("TS2304"),+ "the build error must survive to the model: {logs}"+ );+}++/// Trimming keeps the tail. A build that fails after a thousand lines of setup+/// puts its error at the end, so a limit that kept the head would return a+/// thousand lines of noise and drop the only one an agent came for.+#[tokio::test]+async fn a_limited_log_read_keeps_the_end_where_the_failure_is() {+ let server = MockServer::start().await;++ let events: Vec<serde_json::Value> = (0..10)+ .map(|n| json!({"created": n, "type": "stdout", "payload": format!("line {n}")}))+ .collect();+ Mock::given(method("GET"))+ .and(path("/v3/deployments/dpl_long/events"))+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({"events": events})))+ .mount(&server)+ .await;++ let result = tools::DeploymentLogsTool::new(host_against(&server))+ .execute(json!({"deployment_id": "dpl_long", "limit": 3}))+ .await+ .expect("the tool reports rather than panics");++ assert!(!result.is_error, "{result:?}");++ let logs: serde_json::Value =+ serde_json::from_str(&result.text()).expect("the tool answers with JSON");+ let rows = logs.as_array().expect("an array of events");++ assert_eq!(rows.len(), 3, "{logs}");+ assert_eq!(rows[0]["message"], "line 7", "{logs}");+ assert_eq!(rows[2]["message"], "line 9", "{logs}");+}++/// A read tool that calls out before checking its arguments turns a model's+/// omission into a provider request.+#[tokio::test]+async fn reading_logs_without_a_deployment_id_is_refused_before_any_call() {+ let server = MockServer::start().await;++ let result = tools::DeploymentLogsTool::new(host_against(&server))+ .execute(json!({}))+ .await+ .expect("the tool reports rather than panics");++ assert!(result.is_error, "{result:?}");+ assert!(+ result.text().contains("deployment_id"),+ "the error should name the argument: {}",+ result.text()+ );+ // Nothing was mounted, so any request would have been a miss; assert the+ // absence rather than trusting that.+ assert!(+ server+ .received_requests()+ .await+ .unwrap_or_default()+ .is_empty(),+ "a missing argument must not reach the provider"+ );+}diff --git a/src/openhuman/hosting/mod.rs b/src/openhuman/hosting/mod.rsindex 606b16bd0c..cf556a0bb9 100644--- a/src/openhuman/hosting/mod.rs+++ b/src/openhuman/hosting/mod.rs@@ -12,7 +12,7 @@//!//! # What the agent gets//!-//! Nine tools, in [`tools`]. `hosting_launch_site` is the one that matters: it+//! Ten tools, in [`tools`]. `hosting_launch_site` is the one that matters: it//! turns a directory in the workspace into a live site with a database behind//! it. `hosting_rollback` is its counterweight — it points production back at//! an earlier deployment, so an agent that ships a broken site has a way backdiff --git a/src/openhuman/hosting/tools.rs b/src/openhuman/hosting/tools.rsindex 79fc6a9a64..be3512cd39 100644--- a/src/openhuman/hosting/tools.rs+++ b/src/openhuman/hosting/tools.rs@@ -1,6 +1,6 @@//! The `hosting_*` agent tools.//!-//! Nine tools over one hosting account. They are thin on purpose: argument+//! Ten tools over one hosting account. They are thin on purpose: argument//! parsing, one call into [`tinyhosts`], and a result described for a model.//! Anything that looks like hosting logic belongs in the crate, where it is//! provider-independent and tested against a mock of the provider's API.diff --git a/src/openhuman/hosting/tools_part_01.rs b/src/openhuman/hosting/tools_part_01.rsindex d0a4bd3884..1154972541 100644--- a/src/openhuman/hosting/tools_part_01.rs+++ b/src/openhuman/hosting/tools_part_01.rs@@ -16,6 +16,7 @@ pub fn hosting_tools(account: &Account) -> Vec<Box<dyn Tool>> {Box::new(LaunchSiteTool::new(account.clone())),Box::new(DeploymentStatusTool::new(account.host())),Box::new(ListDeploymentsTool::new(account.host())),+ Box::new(DeploymentLogsTool::new(account.host())),Box::new(RollbackTool::new(account.host())),Box::new(ListSitesTool::new(account.host())),Box::new(SetEnvTool::new(account.host())),@@ -424,6 +425,91 @@ impl Tool for ListDeploymentsTool {}}+// ── hosting_deployment_logs ─────────────────────────────++/// Reads the build and runtime events a deployment recorded.+///+/// The other half of [`DeploymentStatusTool`]. That tool reports *that* a build+/// failed and carries the provider's one-line error; this one is how an agent+/// finds out *why*, which is the difference between reporting a broken deploy+/// and fixing it.+pub struct DeploymentLogsTool {+ host: Arc<dyn Host>,+}++impl DeploymentLogsTool {+ pub fn new(host: Arc<dyn Host>) -> Self {+ Self { host }+ }+}++#[async_trait]+impl Tool for DeploymentLogsTool {+ fn name(&self) -> &str {+ "hosting_deployment_logs"+ }++ fn description(&self) -> &str {+ "Read a deployment's build and runtime log events, oldest first. Use it \+ after hosting_deployment_status reports a failed deployment to find the \+ error that caused it. Takes the same deployment id as \+ hosting_deployment_status."+ }++ fn parameters_schema(&self) -> Value {+ json!({+ "type": "object",+ "required": ["deployment_id"],+ "properties": {+ "deployment_id": {+ "type": "string",+ "description": "The id hosting_launch_site returned, or one \+ from hosting_list_deployments."+ },+ "limit": {+ "type": "integer",+ "description": "How many of the most recent events to return. \+ Defaults to 100."+ }+ }+ })+ }++ fn permission_level(&self) -> PermissionLevel {+ PermissionLevel::ReadOnly+ }++ async fn execute(&self, args: Value) -> anyhow::Result<ToolResult> {+ let id = match required_str(&args, "deployment_id") {+ Ok(id) => id,+ Err(error) => return Ok(ToolResult::error(error.to_string())),+ };+ let limit = args+ .get("limit")+ .and_then(Value::as_u64)+ .unwrap_or(100)+ .clamp(1, 1000) as usize;++ match self.host.deployment_logs(&id).await {+ Ok(logs) => {+ // The crate returns the whole log oldest-first and a build can+ // record thousands of lines, which is a context window rather+ // than a bill. Trimming takes the *tail*: the failure that sent+ // an agent here is at the end, and dropping the head loses+ // setup noise rather than the error.+ let trimmed = if logs.len() > limit {+ &logs[logs.len() - limit..]+ } else {+ &logs[..]+ };++ Ok(ToolResult::success(serde_json::to_string_pretty(&trimmed)?))+ }+ Err(error) => Ok(ToolResult::error(error.to_string())),+ }+ }+}+// ── hosting_rollback ────────────────────────────────────────────────────────/// Points a site's production traffic back at an earlier deployment.