{
  "jimothyPipeline": 1,
  "name": "Incident postmortem draft",
  "description": "Traces an incident to the commits behind it, writes a blameless postmortem, and opens it as a pull request.",
  "icon": "bug",
  "color": "#f97316",
  "repo": {
    "mode": "worktree",
    "localPath": "",
    "baseBranch": "main",
    "branchTemplate": "postmortem/{{issue.key | slug}}"
  },
  "concurrency": 2,
  "variables": {
    "postmortemDir": "docs/postmortems"
  },
  "steps": [
    {
      "id": "investigate",
      "name": "Investigate",
      "type": "agent",
      "description": "Reads the timeline, finds the commits behind the incident and explains the failure. Changes nothing.",
      "harnessId": "claude-code",
      "model": "opus",
      "timeoutMinutes": 30,
      "prompt": "Incident {{issue.key}}: {{issue.title}}\n{{#if issue.url}}Link: {{issue.url}}{{/if}}\n\nTimeline and notes:\n{{issue.description}}\n\nInvestigate the repository in the current directory. Do not modify any files.\n1. Use git log (with dates) to list the commits and merges in the 48 hours before the incident started.\n2. Identify the change or changes most likely to have caused it, and read the code involved.\n3. Explain the failure mechanism: what the code did, under what conditions, and why tests and review didn't catch it.\n\nReport your findings in Markdown with commit SHAs and file paths. Separate what you confirmed from what you suspect."
    },
    {
      "id": "draft",
      "name": "Write postmortem",
      "type": "agent",
      "description": "Writes the blameless postmortem into the repository and commits it.",
      "harnessId": "claude-code",
      "model": "sonnet",
      "dependsOn": [
        "investigate"
      ],
      "timeoutMinutes": 20,
      "prompt": "Write a blameless postmortem for incident {{issue.key}}: {{issue.title}}\n\nTimeline and notes:\n{{issue.description}}\n\nInvestigation:\n{{steps.investigate.output}}\n\nCreate {{vars.postmortemDir}}/<YYYY-MM-DD>-{{issue.key | slug}}.md (today's date; create the folder if needed) with these sections: Summary, Impact (who, how many, how long), Timeline (times with time zone), Root cause, Contributing factors, What went well, What went poorly, Action items (a table: action, type prevent/detect/mitigate, priority, owner \"TBD\"). Describe systems and decisions, never individuals' mistakes. Commit it with the message \"Postmortem: {{issue.key}} {{issue.title}}\". Then answer with the file's contents.{{#if steps.review.output}}\n\nA reviewer checked your previous draft. Fix every point in the same file and amend the commit:\n{{steps.review.output}}{{/if}}{{#if steps.approve.output}}\n\nYour previous draft was rejected with this feedback. Rewrite it:\n{{steps.approve.output}}{{/if}}"
    },
    {
      "id": "review",
      "name": "Blameless review",
      "type": "agent",
      "description": "Checks the draft for blame, gaps and vague action items, and sends it back until it passes.",
      "harnessId": "anthropic-api",
      "model": "claude-opus-5",
      "dependsOn": [
        "draft"
      ],
      "timeoutMinutes": 10,
      "passPattern": "VERDICT:\\s*APPROVE",
      "loopBackTo": "draft",
      "maxLoops": 2,
      "prompt": "Review this postmortem.\n\n{{steps.draft.output}}\n\nCheck that it is blameless (no sentence assigns fault to a person), the root cause explains the timeline, every contributing factor has at least one action item, action items are specific enough to be ticketed, and impact is quantified. List each problem with the sentence it applies to. End with exactly one line: VERDICT: APPROVE or VERDICT: CHANGES_REQUESTED."
    },
    {
      "id": "approve",
      "name": "Approve postmortem",
      "type": "approval",
      "description": "Shows you the postmortem. Reject with a comment and it is rewritten.",
      "dependsOn": [
        "review"
      ],
      "loopBackTo": "draft",
      "maxLoops": 3,
      "approvalMessage": "Open a pull request with this postmortem for {{issue.key}}?\n\n---\n\n{{steps.draft.output}}"
    },
    {
      "id": "pr",
      "name": "Open pull request",
      "type": "shell",
      "description": "Pushes the branch and opens a pull request.",
      "dependsOn": [
        "approve"
      ],
      "timeoutMinutes": 5,
      "command": "git push -u origin HEAD && gh pr create --base {{run.baseBranch}} --title \"Postmortem: $FACTORY_ISSUE_KEY $FACTORY_ISSUE_TITLE\" --body \"Blameless postmortem drafted by Jimothy run #$FACTORY_RUN_NUMBER. $FACTORY_ISSUE_URL\""
    }
  ]
}