Skip to main content

Trigger

Struct Trigger 

Source
pub struct Trigger {
Show 20 fields pub name: String, pub schedule: Schedule, pub prompt: String, pub description: Option<String>, pub timezone: Option<String>, pub enabled: bool, pub created_at: Option<DateTime<Utc>>, pub provider: Option<String>, pub model: Option<String>, pub workspace: Option<PathBuf>, pub permission_mode: PermissionMode, pub tools: Vec<String>, pub skills: Vec<String>, pub no_mcp: bool, pub max_turns: Option<u32>, pub max_output_tokens: Option<u64>, pub max_cost_usd: Option<f64>, pub timeout: Option<String>, pub catch_up: CatchUp, pub notify: Option<String>,
}
Expand description

One scheduled prompt.

Fields§

§name: String

The file’s stem. Never read from the file itself — a name that can disagree with its filename is a class of bug with no upside.

§schedule: Schedule

Five-field cron, in timezone.

§prompt: String

What to ask. This is the whole action: a trigger runs an agent, not a command. (Scheduled commands are what cron is for, and giving one a place in this store would mean answering how it gets confined and which environment it sees — questions the MCP and sandbox work already answered the expensive way.)

§description: Option<String>

One line for mecha trigger list.

§timezone: Option<String>

IANA name. Written explicitly by mecha trigger add, resolved from [agent] timezone at the time: “07:00” must not quietly mean something different after a config edit.

§enabled: bool§created_at: Option<DateTime<Utc>>

The anchor for the first fire. Without it a trigger added at 08:00 would find 07:00 unfired and run immediately.

§provider: Option<String>§model: Option<String>§workspace: Option<PathBuf>

The path jail for this run. Defaults to the daemon’s working directory, which is usually not what you want — say it.

§permission_mode: PermissionMode

Read-only by default. See the module docs: an unattended run has nobody to ask, and outbox staging works at every level.

§tools: Vec<String>

Only these tools, if set. The narrowest useful control there is: a briefing that can read mail and nothing else cannot be talked into anything else.

§skills: Vec<String>

Skills this run may load. Empty means none, which is the opposite of the tools field above and is deliberate.

A trigger is an unattended run with nobody to ask, so “what does this run actually do” has to be answerable from the trigger file. If the model could load any skill in the store, the effective instruction set of a scheduled run would be larger than its file shows, and it would grow every time the user wrote an unrelated skill — the same reason trigger show prints the resolved workspace rather than leaving an omitted line to be interpreted.

So this defaults closed and the schedule names what it needs. Note the asymmetry with tools: an empty allowlist there means “the usual surface”, because that surface is fixed and reviewable, where the skill store is a directory the user adds to.

§no_mcp: bool

Skip MCP servers entirely for this run.

§max_turns: Option<u32>§max_output_tokens: Option<u64>§max_cost_usd: Option<f64>

Needs prices on the provider. A cap that cannot fire is refused at load rather than ignored at 03:00 — see Trigger::validate.

§timeout: Option<String>

Wall-clock ceiling on one run. Cancels at the next safe point, keeping the partial answer, exactly as Ctrl-C does.

§catch_up: CatchUp§notify: Option<String>

A command run when the trigger produces an answer, with the answer on stdin — notify-send, a mail invocation, an append to a file.

An observer, like post_tool: its failure is logged and never fails the run. The answer is already in the session transcript, which is the record; this is delivery.

Implementations§

Source§

impl Trigger

Source

pub fn new( name: impl Into<String>, schedule: Schedule, prompt: impl Into<String>, ) -> Self

Source

pub fn valid_name(name: &str) -> Result<()>

A trigger name is a filename, a log line, and a CLI argument. Keep it to what is unambiguous in all three.

Source

pub fn validate(&self) -> Result<()>

Everything that can be wrong with a trigger before it ever runs.

Called on load, so a typo surfaces on mecha trigger list at a keyboard, not on the fire it was meant to control.

Source

pub fn tz(&self, fallback: Option<Tz>) -> Tz

The zone its wall-clock schedule is read in.

Source

pub fn timeout_duration(&self) -> Duration

Source

pub fn next_fire( &self, at: DateTime<Utc>, fallback_tz: Option<Tz>, ) -> Option<DateTime<Utc>>

When this trigger would next fire after at.

Source

pub fn due( &self, last_slot: Option<DateTime<Utc>>, now: DateTime<Utc>, fallback_tz: Option<Tz>, ) -> Due

Is it due, and if not, when?

last_slot is the most recent slot that has already been accounted for — fired, or deliberately skipped. None means nothing has, in which case created_at is the anchor: a trigger must not fire for a slot that predates its own existence.

Trait Implementations§

Source§

impl Clone for Trigger

Source§

fn clone(&self) -> Trigger

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Trigger

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Trigger

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Trigger

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more