feat(engine): extend Mission types with webhook/event triggers + evolving strategy

Mission types updated to support external activation sources:

MissionCadence expanded:
- Cron { expression, timezone } — timezone-aware scheduling
- OnEvent { event_pattern } — channel message pattern matching
- OnSystemEvent { source, event_type } — structured events from tools
- Webhook { path, secret } — external HTTP triggers (GitHub, email, etc.)
- Manual — explicit triggering only

The engine defines trigger TYPES. The bridge implements infrastructure
(cron ticker, webhook endpoints, event matchers). GitHub issues, PRs,
email, Slack events all use the generic Webhook cadence — no
special-casing in the engine. Webhook payload injected as
state["trigger_payload"] in the thread's Python context.

Mission struct extended:
- current_focus: what the next thread should work on (evolving)
- approach_history: what we've tried (for adaptation)
- max_threads_per_day / threads_today: daily budget
- last_trigger_payload: webhook/event data for thread context

Plan updated with trigger type table and webhook integration design.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
2026-03-24 09:21:15 -07:00
co-authored by Claude Opus 4.6
parent e67f2d686d
commit 10cf040b43
3 changed files with 73 additions and 6 deletions
@@ -154,7 +154,9 @@ impl MissionManager {
mission.next_fire_at.is_some_and(|next| next <= now)
}
MissionCadence::Manual => false,
MissionCadence::OnEvent { .. } | MissionCadence::OnPush => false,
MissionCadence::OnEvent { .. }
| MissionCadence::OnSystemEvent { .. }
| MissionCadence::Webhook { .. } => false,
};
if should_fire && let Some(tid) = self.fire_mission(mid, user_id).await? {
@@ -539,6 +541,7 @@ mod tests {
"periodic goal",
MissionCadence::Cron {
expression: "* * * * *".into(),
timezone: None,
},
)
.await
+46 -5
View File
@@ -47,15 +47,31 @@ pub enum MissionStatus {
}
/// How a mission triggers new threads.
///
/// The engine defines the trigger *types*. The bridge/host implements the
/// actual trigger infrastructure (cron tickers, webhook endpoints, event
/// matchers). The engine just needs to be told "fire this mission now."
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum MissionCadence {
/// Spawn on a cron schedule (e.g., "0 */6 * * *" for every 6 hours).
Cron { expression: String },
/// Spawn in response to a named event.
Cron {
expression: String,
timezone: Option<String>,
},
/// Spawn in response to a channel message matching a pattern.
OnEvent { event_pattern: String },
/// Spawn when code is pushed (webhook-driven).
OnPush,
/// Only spawn when manually triggered.
/// Spawn in response to a structured system event (from tools or external).
OnSystemEvent {
source: String,
event_type: String,
},
/// Spawn when an external webhook is received at a registered path.
/// The bridge registers the webhook endpoint and routes payloads here.
Webhook {
path: String,
secret: Option<String>,
},
/// Only spawn when manually triggered (via mission_fire tool or API).
Manual,
}
@@ -68,10 +84,30 @@ pub struct Mission {
pub goal: String,
pub status: MissionStatus,
pub cadence: MissionCadence,
// ── Evolving strategy ──
/// What the next thread should focus on (updated after each thread).
pub current_focus: Option<String>,
/// What approaches have been tried and what happened.
pub approach_history: Vec<String>,
// ── Progress tracking ──
/// History of threads spawned by this mission.
pub thread_history: Vec<ThreadId>,
/// Optional criteria for declaring the mission complete.
pub success_criteria: Option<String>,
// ── Budget ──
/// Maximum threads per day (0 = unlimited).
pub max_threads_per_day: u32,
/// Threads spawned today (reset daily by the cron ticker).
pub threads_today: u32,
// ── Trigger payload ──
/// Payload from the most recent trigger (webhook body, event data, etc.).
/// Injected into the thread's context so the code can access it.
pub last_trigger_payload: Option<serde_json::Value>,
pub metadata: serde_json::Value,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
@@ -94,8 +130,13 @@ impl Mission {
goal: goal.into(),
status: MissionStatus::Active,
cadence,
current_focus: None,
approach_history: Vec::new(),
thread_history: Vec::new(),
success_criteria: None,
max_threads_per_day: 10,
threads_today: 0,
last_trigger_payload: None,
metadata: serde_json::Value::Object(serde_json::Map::new()),
created_at: now,
updated_at: now,
+23
View File
@@ -44,6 +44,29 @@ pub struct Mission {
Already defined in `crates/ironclaw_engine/src/types/mission.rs`.
## Trigger Types
The engine defines trigger *types*. The bridge implements the actual infrastructure:
| Trigger | Engine type | Bridge implementation |
|---|---|---|
| Cron schedule | `MissionCadence::Cron { expression, timezone }` | Tokio interval task, cron parser |
| Channel message | `MissionCadence::OnEvent { event_pattern }` | Regex match in `handle_message` before routing |
| System event | `MissionCadence::OnSystemEvent { source, event_type }` | Match events from `event_emit` tool |
| Webhook | `MissionCadence::Webhook { path, secret }` | Register HTTP endpoint on webhook server |
| Manual | `MissionCadence::Manual` | `mission_fire` tool or API call |
**Webhook-based integrations** (GitHub, email, etc.) use the generic `Webhook` cadence. The webhook payload is stored as `mission.last_trigger_payload` and injected into the thread's context:
```python
# Inside the mission's thread, the trigger payload is accessible:
payload = state["trigger_payload"]
# For a GitHub webhook: payload["action"], payload["issue"]["title"], etc.
# For email: payload["from"], payload["subject"], payload["body"]
```
This means GitHub issues, PRs, email, Slack events, etc. all work through the same webhook mechanism — no special-casing in the engine.
## Architecture
```