OpenProgram Docs

Events and state

Rules read state; nobody maintains it by hand. It is the event stream folded from empty, one event at a time.

EventPayload readSessionState after
user.prompt_submittedturn_has_file_change and turn_has_verification reset to false
tool.beforetool, args.commandlast_tool set; turn_has_verification true when it is a verification
file.changedpathchanged_files adds it; turn_has_file_change true
tool.after, is_errortooltool_fail_count[tool] + 1
tool.after, successtooltool_fail_count[tool] = 0

A verification is a tool named with pytest, test, chrome, browser or navigate, or a bash or test tool whose command holds test, pytest, npm run or make .

Fold

state = empty_state()
for event in stream:
    state = update(state, event)

From scratch is the definition. StateStore.apply updates incrementally and must give the same result.

PropertyRule
StreamOrdered and append-only, so any moment can be recomputed. The event layer defines the event.
ConcurrencyOne state per metadata["session"]. Subagents folded together would pair one's changes with another's situation.
originEvents the framework caused are not folded or shown to rules: Invariants.
DepthMechanical facts only (L0). Heuristic and LLM layers are added when a rule needs them.

Reading state

class StuckToolWatcher(Policy):
    on = {"tool.after"}
    def evaluate(self, event, state):
        tool = event.payload["tool"]
        if state.tool_fail_count.get(tool, 0) >= 3:
            return Notify(f"{tool} has failed repeatedly, may be stuck")

Rules and how they run

Last updated · 2026-11-25