Skip to content

Stream rules

A rule that must hold in the agent’s own output is cheapest when it fires at the moment the output breaks it, so a match rewinds the response and retries with the rule in hand. pi/ttsr.ts is a port of oh-my-pi’s Time Traveling Stream Rules.

Rule files, matching, and frontmatter

A Markdown rule in ~/.pi/agent/rules/ or <project>/.pi/rules/ whose frontmatter has a condition regex is watched during the run. A match in streamed assistant text aborts the response, drops it, and retries with the rule injected. A match in tool arguments (the command for bash, the new text for write and edit) blocks the call with the rule as its reason.

Frontmatter fields follow oh-my-pi: condition, scope (text, thinking, tool, tool:bash, tool:edit(*.ts)), globs, and interruptMode (always, prose-only, tool-only, never). repeatMode (once or after-gap) and repeatGap are added. Each injected rule arrives as <rule name="…">body</rule>. A rule fires once per session by default.

astCondition, question, and agents are not supported; a rule that uses them is skipped and reported. /ttsr lists the loaded rules.