{
  "$schema": "https://raw.githubusercontent.com/cobia68/pi-onward/main/onward.schema.json",
  "enabled": true,
  "maxFailures": 20,
  "maxHandoffs": 3,
  "actionTimeout": "30s",
  "rules": [
    {
      "name": "quota",
      "when": {
        "failure": "insufficient[\\s_-]*quota|exceeded your current quota|quota exceeded|out of budget|billing|余额不足|额度不足"
      },
      "stages": [
        { "minFailures": 1, "action": { "use": "onward.stop", "with": { "reason": "额度问题需要处理后再继续" } } }
      ]
    },
    {
      "name": "transient",
      "when": {
        "failure": "\\b(401|429|500|502|503|504|529)\\b|connection|network|fetch failed|timed? ?out|overloaded"
      },
      "stages": [
        { "minFailures": 1, "delay": "3s..15s", "action": { "use": "pi.message", "with": { "prompt": "{taskPrompt}" } } },
        { "minFailures": 4, "action": { "use": "onward.stop", "with": { "reason": "连续失败 4 次，请检查服务或配置恢复插件动作" } } }
      ]
    },
    {
      "name": "empty",
      "when": { "failure": "^$" },
      "stages": [
        { "minFailures": 1, "delay": "3s", "action": { "use": "pi.message", "with": { "prompt": "请继续执行任务：\n{taskPrompt}" } } },
        { "minFailures": 3, "action": { "use": "onward.stop" } }
      ]
    }
  ]
}
