Skip to content

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

refactor(flows): derive trigger kind via TinyFlows portability

Steven Enamakela26ea8caf9fe
diff --git a/crates/openhuman-core/src/flows/README.md b/crates/openhuman-core/src/flows/README.md
index c55ef89056..462fb7aef1 100644
--- a/crates/openhuman-core/src/flows/README.md
+++ b/crates/openhuman-core/src/flows/README.md
@@ -86,8 +86,8 @@ back as a `{ code: "version_conflict", ... }` error the UI can offer to reload.
Every graph change is kept as a revision (`flows_get_history`,
`flows_rollback`).
-Drafts are separate, non-live working copies stored as files under
-`<workspace>/flows/drafts/` ([`draft_store.rs`](./draft_store.rs), [`ops/drafts.rs`](./ops/drafts.rs)). Promoting a
+Drafts are separate, non-live working copies owned by the TinyFlows Catalog
+service ([`draft_store.rs`](./draft_store.rs), [`ops/drafts.rs`](./ops/drafts.rs)). Promoting a
draft runs the same create/update gates as a normal save.
### Enabling and triggers
@@ -229,9 +229,8 @@ The catalog (`store.rs`), drafts (`draft_store.rs`), run rows, per-flow state,
and checkpoints are owned by TinyFlows' module services and the document port.
OpenHuman registers a scope-bound CatalogStorage callback per acting storage
scope and retains its stable address with each live or approval-parked run.
-There is one storage path whatever the storage URL says: the installed backend,
-else a SQLite document database of the catalog's own
-(`<workspace>/flows/catalog.db`). The files TinyFlows used to write
+There is one storage path: the installed host storage backend, which defaults
+to local SQLite for desktop use. The files TinyFlows used to write
(`flows/flows.db`, `flows/drafts/`, `flows/checkpoints.db`) are imported
read-only once, at boot for an installed backend (`storage::import::tinyflows`)
and on first use otherwise, and are never written again. When the scope cannot
diff --git a/crates/openhuman-core/src/flows/bus.rs b/crates/openhuman-core/src/flows/bus.rs
index 1350be39fd..b46f8ccfa7 100644
--- a/crates/openhuman-core/src/flows/bus.rs
+++ b/crates/openhuman-core/src/flows/bus.rs
@@ -16,8 +16,8 @@ mod run_digest;
mod trigger;
pub use run_digest::FlowRunDigestSubscriber;
-pub use trigger::FlowTriggerSubscriber;
pub(crate) use trigger::describe_trigger;
+pub use trigger::FlowTriggerSubscriber;
// Private helpers and shared imports the colocated tests reach through
// `use super::*`.
diff --git a/crates/openhuman-core/src/flows/bus_subscriber_tests.rs b/crates/openhuman-core/src/flows/bus_subscriber_tests.rs
index 69e2b46c58..73e790cedf 100644
--- a/crates/openhuman-core/src/flows/bus_subscriber_tests.rs
+++ b/crates/openhuman-core/src/flows/bus_subscriber_tests.rs
@@ -28,7 +28,10 @@ async fn portability_proxy_describes_bindings_and_returns_pinned_inputs() {
let details = describe_trigger(&config, &schedule_flow).unwrap();
assert_eq!(details.kind.as_deref(), Some("schedule"));
- assert!(details.schedule.is_some(), "schedule is returned as a typed value");
+ assert!(
+ details.schedule.is_some(),
+ "schedule is returned as a typed value"
+ );
let inputs = trigger::pinned_trigger_inputs(&config, &schedule_flow).unwrap();
assert_eq!(inputs["repo"], json!("acme/api"));
assert_eq!(inputs["depth"], json!(3));
@@ -42,15 +45,14 @@ async fn portability_proxy_describes_bindings_and_returns_pinned_inputs() {
"trigger_slug": "GMAIL_NEW_GMAIL_MESSAGE"
}),
);
- assert!(trigger::matches_app_event(
- &config,
- &event_flow,
- "Gmail",
- "gmail_new_gmail_message"
- )
- .unwrap());
- assert!(!trigger::matches_app_event(&config, &event_flow, "slack", "GMAIL_NEW_GMAIL_MESSAGE")
- .unwrap());
+ assert!(
+ trigger::matches_app_event(&config, &event_flow, "Gmail", "gmail_new_gmail_message")
+ .unwrap()
+ );
+ assert!(
+ !trigger::matches_app_event(&config, &event_flow, "slack", "GMAIL_NEW_GMAIL_MESSAGE")
+ .unwrap()
+ );
let malformed = flow_with_trigger_config(
"malformed-flow",
diff --git a/crates/openhuman-core/src/flows/catalogue.rs b/crates/openhuman-core/src/flows/catalogue.rs
index 194b334fa4..4311aae731 100644
--- a/crates/openhuman-core/src/flows/catalogue.rs
+++ b/crates/openhuman-core/src/flows/catalogue.rs
@@ -16,7 +16,7 @@
//! # What a Flow entry is not
//!
//! It is a **listing**, not a bundle. Every other scope is a directory the
-//! skill scanner walked; this is a row in `flows.db`. There is no `SKILL.md`,
+//! skill scanner walked; this is a TinyFlows Catalog record. There is no `SKILL.md`,
//! so `location` is `None` and `resources` is empty, and the tools that read
//! those (`describe_workflow`, `read_workflow_resource`) must say so by name
//! rather than failing on a missing file. That is the whole reason
@@ -28,10 +28,11 @@
//!
//! Saved flows carry the name and graph metadata supplied by the shared catalog
//! crate, but no separate catalogue description. The summary below therefore
-//! describes only the graph's shape, without inventing a purpose from node
-//! internals.
+//! describes only the graph's shape, using TinyFlows Portability for its
+//! trigger kind and avoiding guesses from node internals.
use crate::config::Config;
+use crate::flows::bus;
use {tinyskills::Skill as Workflow, tinyskills::SkillScope as WorkflowScope};
/// How many flows the catalogue will surface.
@@ -47,7 +48,7 @@ pub const MAX_CATALOGUE_FLOWS: usize = 20;
/// Every saved flow, as catalogue entries.
///
/// Returns an empty vec on any store error rather than propagating: this feeds
-/// a prompt section and a search index, and a transient `flows.db` problem
+/// a prompt section and a search index, and a transient Catalog storage issue
/// should degrade the catalogue, never fail the turn. The error is logged.
pub fn flow_entries(config: &Config) -> Vec<Workflow> {
let (flows, skipped) = match super::store::list_flows(config) {
@@ -74,7 +75,7 @@ pub fn flow_entries(config: &Config) -> Vec<Workflow> {
// answer "you have no such automation" to someone looking at it in the
// UI. The entry says it is paused; the model can offer to enable it.
.take(MAX_CATALOGUE_FLOWS)
- .map(entry_for)
+ .map(|flow| entry_for_with_config(config, flow))
.collect();
if total > MAX_CATALOGUE_FLOWS {
tracing::debug!(
@@ -87,14 +88,14 @@ pub fn flow_entries(config: &Config) -> Vec<Workflow> {
entries
}
-fn entry_for(flow: tinyflows_catalog::types::Flow) -> Workflow {
+fn entry_for_with_config(config: &Config, flow: tinyflows_catalog::types::Flow) -> Workflow {
Workflow {
name: flow.name.clone(),
// The flow id, because that is what `run_workflow` / `get_flow` take.
// A slug of the name would be a second identifier that resolves
// nowhere.
dir_name: flow.id.clone(),
- description: describe(&flow),
+ description: describe(config, &flow),
scope: WorkflowScope::Flow,
// No bundle on disk: no manifest to read, no resources to page
// through. Left explicitly empty so a consumer that reads them gets an
@@ -105,8 +106,8 @@ fn entry_for(flow: tinyflows_catalog::types::Flow) -> Workflow {
}
/// A structural summary of the flow graph.
-fn describe(flow: &tinyflows_catalog::types::Flow) -> String {
- describe_shape(flow)
+fn describe(config: &Config, flow: &tinyflows_catalog::types::Flow) -> String {
+ describe_shape(config, flow)
}
/// A one-line summary of what the graph *is*, for a flow with no description.
@@ -114,18 +115,16 @@ fn describe(flow: &tinyflows_catalog::types::Flow) -> String {
/// Deliberately structural — trigger, size, paused-ness — because that is all
/// the record carries. See the module docs: inventing a purpose from node
/// internals would read as authoritative and frequently be wrong.
-fn describe_shape(flow: &tinyflows_catalog::types::Flow) -> String {
- // Read out of the trigger node's free-form config, which is where the
- // engine keeps it — the same way `tinyflows`' own `trigger_kind` does.
- // A graph with zero or several triggers has no single answer, and
- // validation reports that separately, so this stays quiet.
- let trigger = flow
- .graph
- .trigger()
- .and_then(|node| node.config.get("trigger_kind"))
- .and_then(|value| value.as_str())
- .unwrap_or("manual")
- .to_string();
+fn describe_shape(config: &Config, flow: &tinyflows_catalog::types::Flow) -> String {
+ // Trigger semantics belong to TinyFlows. A graph with no recognized
+ // trigger is summarized as manual, matching the catalogue's former copy.
+ let trigger = match bus::describe_trigger(config, flow) {
+ Ok(details) => details.kind.unwrap_or_else(|| "manual".to_string()),
+ Err(error) => {
+ tracing::warn!(target: "flows", flow_id = %flow.id, %error, "[flows][catalogue] could not describe flow trigger");
+ "unknown".to_string()
+ }
+ };
let steps = flow
.graph
.nodes
@@ -142,6 +141,11 @@ fn describe_shape(flow: &tinyflows_catalog::types::Flow) -> String {
out
}
+#[cfg(test)]
+fn entry_for(flow: tinyflows_catalog::types::Flow) -> Workflow {
+ entry_for_with_config(&Config::default(), flow)
+}
+
#[cfg(test)]
#[path = "catalogue_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/flows/catalogue_tests.rs b/crates/openhuman-core/src/flows/catalogue_tests.rs
index 0bd41db747..346f802898 100644
--- a/crates/openhuman-core/src/flows/catalogue_tests.rs
+++ b/crates/openhuman-core/src/flows/catalogue_tests.rs
@@ -145,7 +145,7 @@ fn a_flow_description_is_always_derived_from_its_graph_shape() {
// ── Against a real store ──────────────────────────────────────────────────
//
-// The mapping tests above never touch `flows.db`. These do, because the
+// The mapping tests above never touch Catalog storage. These do, because the
// interesting failure is not the mapping — it is `flow_entries` reading the
// wrong database, or silently swallowing a real one. A unit test over
// `entry_for` would pass in both cases.
diff --git a/crates/openhuman-core/src/flows/host_gates/agent_refs.rs b/crates/openhuman-core/src/flows/host_gates/agent_refs.rs
index 3fdbb9f502..b571158379 100644
--- a/crates/openhuman-core/src/flows/host_gates/agent_refs.rs
+++ b/crates/openhuman-core/src/flows/host_gates/agent_refs.rs
@@ -7,7 +7,7 @@ use tinyflows::model::{NodeKind, WorkflowGraph};
// real agent, not the runtime's `RegistryFallback` "unknown agent_ref" case
// ─────────────────────────────────────────────────────────────────────────────
//
-// `run_via_registry_fallback` (`tinyflows/caps.rs`) hard-errors mid-run with
+// `run_via_registry_fallback` (`flows/caps_host/agent.rs`) hard-errors mid-run with
// "unknown agent_ref '…'" the moment an `agent` node's `config.agent_ref`
// doesn't resolve to either a harness `AgentDefinition` or a custom agent
// registry entry. Today that is the FIRST time an author finds out — the
@@ -25,7 +25,7 @@ use tinyflows::model::{NodeKind, WorkflowGraph};
/// Rejects an `agent` node whose `config.agent_ref` would hit the runtime's
/// `RegistryFallback` "unknown agent_ref" hard error mid-run
-/// (`run_via_registry_fallback` in `tinyflows/caps.rs`) — a real ref is one
+/// (`run_via_registry_fallback` in `flows/caps_host/agent.rs`) — a real ref is one
/// that resolves via [`crate::flows::agent_route::route_for_agent_ref`]
/// to a harness [`AgentDefinition`](crate::agent_registry::host_definition::AgentDefinition)
/// (`AgentRoute::Harness`), OR — when it routes to `AgentRoute::RegistryFallback`
diff --git a/crates/openhuman-core/src/flows/ops/definitions.rs b/crates/openhuman-core/src/flows/ops/definitions.rs
index 582ff95ae7..8546772df0 100644
--- a/crates/openhuman-core/src/flows/ops/definitions.rs
+++ b/crates/openhuman-core/src/flows/ops/definitions.rs
@@ -114,12 +114,15 @@ pub(crate) async fn flows_create_with_context(
let mut logs = vec!["flow created".to_string()];
if !enabled {
- let trigger_label = flow
- .graph
- .trigger()
- .and_then(|t| t.config.get("trigger_kind"))
- .and_then(Value::as_str)
- .unwrap_or("automatic");
+ let trigger_label = match bus::describe_trigger(config, &flow) {
+ Ok(details) => details
+ .kind
+ .unwrap_or_else(|| "automatic".to_string()),
+ Err(error) => {
+ tracing::warn!(target: "flows", flow_id = %flow.id, %error, "[flows] could not describe trigger after create");
+ "automatic".to_string()
+ }
+ };
logs.push(format!(
"Flow created DISABLED because it has an automatic trigger ({trigger_label}). \
Enable it explicitly (flows_set_enabled) when you are ready for it to fire."
diff --git a/crates/openhuman-core/src/flows/ops/triggers.rs b/crates/openhuman-core/src/flows/ops/triggers.rs
index 80bfb4f08c..98674b6403 100644
--- a/crates/openhuman-core/src/flows/ops/triggers.rs
+++ b/crates/openhuman-core/src/flows/ops/triggers.rs
@@ -92,7 +92,9 @@ pub(super) fn bind_trigger(config: &Config, flow: &Flow) {
match details.kind.as_deref() {
Some("schedule") => match details.schedule {
Some(schedule) => bind_schedule_trigger(config, flow, schedule),
- None => tracing::warn!(target: "flows", flow_id = %flow.id, "[flows] schedule trigger description omitted its schedule"),
+ None => {
+ tracing::warn!(target: "flows", flow_id = %flow.id, "[flows] schedule trigger description omitted its schedule")
+ }
},
Some("webhook") => log_webhook_trigger_deferred(flow, true),
_ => {
@@ -245,7 +247,9 @@ async fn reconcile_schedule_triggers_in_scope(config: &Config) -> Result<(), Str
}
}
Ok(_) => {}
- Err(error) => tracing::warn!(target: "flows", flow_id = %flow.id, %error, "[flows] failed to describe trigger during boot reconcile"),
+ Err(error) => {
+ tracing::warn!(target: "flows", flow_id = %flow.id, %error, "[flows] failed to describe trigger during boot reconcile")
+ }
}
}
tracing::debug!(target: "flows", scanned = flows.len(), reconciled, skipped, "[flows] boot reconciliation of schedule-trigger cron jobs complete");
diff --git a/crates/openhuman-core/src/flows/ops_triggers_and_resume_tests.rs b/crates/openhuman-core/src/flows/ops_triggers_and_resume_tests.rs
index e87dcb1e3b..c57fc44afc 100644
--- a/crates/openhuman-core/src/flows/ops_triggers_and_resume_tests.rs
+++ b/crates/openhuman-core/src/flows/ops_triggers_and_resume_tests.rs
@@ -253,14 +253,20 @@ async fn flows_update_does_not_rebind_schedule_for_pinned_input_changes() {
let original_job = crate::cron::find_flow_schedule_job(&config, &created.value.id)
.unwrap()
.expect("paused schedule job remains registered");
- assert!(!original_job.enabled, "precondition: schedule job is paused");
+ assert!(
+ !original_job.enabled,
+ "precondition: schedule job is paused"
+ );
let mut graph = schedule_trigger_graph("0 9 * * *");
graph["nodes"][0]["config"]["inputs"] = json!({"team": "platform"});
let updated = flows_update(&config, &created.value.id, None, Some(graph), None, None)
.await
.unwrap();
- assert!(updated.value.enabled, "the flow remains enabled during the edit");
+ assert!(
+ updated.value.enabled,
+ "the flow remains enabled during the edit"
+ );
assert_eq!(
updated.value.graph.trigger().unwrap().config["inputs"]["team"],
"platform",
@@ -270,8 +276,14 @@ async fn flows_update_does_not_rebind_schedule_for_pinned_input_changes() {
let job = crate::cron::find_flow_schedule_job(&config, &created.value.id)
.unwrap()
.expect("schedule job remains bound after input-only edit");
- assert_eq!(job.id, original_job.id, "input edits must preserve the binding");
- assert!(!job.enabled, "input-only edits must preserve a paused schedule job");
+ assert_eq!(
+ job.id, original_job.id,
+ "input edits must preserve the binding"
+ );
+ assert!(
+ !job.enabled,
+ "input-only edits must preserve a paused schedule job"
+ );
assert_eq!(job.expression, original_job.expression);
}