跳到內容

串流規則

必須在 agent 自己的輸出裡成立的規則,最便宜的做法是在輸出違反它的當下觸發,所以命中時就倒回回應,帶著規則重試。pi/ttsr.ts 移植自 oh-my-pi 的 Time Traveling Stream Rules。

規則檔、比對與 frontmatter

~/.pi/agent/rules/ 或 <project>/.pi/rules/ 裡 frontmatter 帶有 condition regex 的 Markdown 規則,會在執行過程中被監看。assistant 串流文字命中時,中斷回應、丟棄那段輸出,並注入規則後重試。工具參數命中時(bash 看指令,write/edit 看新寫入的文字),直接擋下呼叫,以規則內容作為理由。

frontmatter 欄位沿用 oh-my-pi:condition、scope(text、thinking、tool、tool:bash、tool:edit(*.ts))、globs、interruptMode(always、prose-only、tool-only、never)。另加 repeatMode(once 或 after-gap)與 repeatGap。注入的規則以 <rule name="…">body</rule> 送出。預設每條規則每個 session 只觸發一次。

不支援 astCondition、question、agents,用到的規則會被跳過並回報。/ttsr 列出已載入的規則。