Conditional Commands

As of 0.9.10 Enkaidu supports conditional continuation commands that start with a ?.

Conditional commands are intended for use within macros since they allow a macro to exit pre-maturely based on conditions.

Macros are sequences of queries that were executed in order, and nested calls to macros were inserted at the call site and then executed in sequence. Until now we did not have a way for a macro to ask a model to do some work and then test for that.

Using the new ?break with if... or unless... conditional commands macros can now make branching decisions, allowing them to exit a macro earlier in its query sequence.

As of 0.9.11, conditional commands are also used to exit blocks — nested groups of queries within a macro, started with the <enter> key (see Macros). A ?break line inside a block exits that block early, skipping any remaining nested queries, while execution continues with the query following the block.

As of 0.9.17, conditional commands can also inspect whether the last prompt or turn was interrupted (via user action such as Ctrl-C / Stop button or via the repetition tripwire). As of 0.9.18, a session also records error when an LLM or connection error stops a turn. A session tracks whether the last turn was interrupted and why (none, user, tripwire, or error). Macros can use last_prompt_interrupt=<TARGET> to react to interruptions.

  • Break on condition

    • ?break if file_exists=<PATH>
      • Exit macro if given file exists
    • ?break if file=<PATH> contains=<STR>
      • Exit macro if given file exists and contains given string
    • ?break if global ns=<NAMESPACE> key=<STR> equals=<STR>
      • Exit macro if global state key has matching value
    • ?break if last_prompt_interrupt=<TARGET> Updated in 0.9.18
      • Exit macro if last prompt interrupt matched target (any, tripwire, user, error, none). Matching any matches user, tripwire, or error.
    • ?break unless file_exists=<PATH>
      • Exit macro unless given file exists
    • ?break unless file=<PATH> contains=<STR>
      • Exit macro unless given file exists and contains given string
    • ?break unless global ns=<NAMESPACE> key=<STR> equals=<STR>
      • Exit macro unless global state key has matching value
    • ?break unless last_prompt_interrupt=<TARGET> Updated in 0.9.18
      • Exit macro unless last prompt interrupt matched target (any, tripwire, user, error, none). Matching any matches user, tripwire, or error.