Skip to content

Local-first 🧠 memory for Hermes Agent that lives in your Obsidian vault and remembers project context. Nightly 😴 dream passes turn repeat corrections into confirmed preferences with measurable confidence. Adapters ship for Claude Code, Codex, and OpenClaw, with an MCP server for anything else.

TypeScript
38.3 KB
Raw Blame
schema: 2
id: osb-pr-prepare
name: Open Second Brain PR prepare
description: 'Turn an Open Second Brain branch whose implementation is done into an open pull request that is ready for the operator to merge. Works for every change kind (feature, fix, refactor, chore, docs, deps). Steps: intake and commit of any uncommitted work, a local zg index, docs plus the version and CHANGELOG decision the change kind drives (CLAUDE.md), the CI QA gates run locally exactly as CI runs them and the code-ranker architecture gate against the main baseline (each with its fix loop), then the owner''s dev quality cycle (skill dev-quality-cycle: OpenCodeReview on the claude-code provider, a read-only Codex gpt-6-sol review, claude -p /security-review, the security-audit and test-audit skills, with its convergence rule), the QA and architecture gates again when the cycle changed anything, an owner approval gate before the push, then push, open the PR with a verified mermaid diagram, one blocking CI wait that ends only when every check has finished, and a bounded bot-review loop. It never merges and never arms auto-merge. The run input (instruction) carries the change kind, the intent, the related issues or cards and the base branch. The finish answer reports the PR URL, the CI state, a summary and whatever is left for a human.'
version: 1.4.1
params:
- name: brief
  type: text
  label: Standing brief for PR preparation (override to change the rules)
  options: null
  default: 'Open Second Brain is a PUBLIC repository. Every artifact (code, commits, PR text, CHANGELOG, comments) is English, uses the full name "Open Second Brain" in prose, and carries no exclamation marks. Engineering bar: SOLID, KISS, DRY, repeated literals hoisted into named constants, no fallbacks that silently do nothing, no stubs, errors surface explicitly and by name. Commits: conventional (`type(scope): imperative summary`), one atomic unit each, formatted and linted before every commit (`bun run fmt`, `bun run lint`; the repo pre-commit hook enforces fmt, mirrors and lint), files staged by name - never `git add -A` or `git add .` (the ignored runtime state in .apb/runs/, .apb/tmp/ and .zvec-grep/ is never part of a change, and the committed .apb/ playbooks and profiles change only when the change is about them). When the commit_trailer parameter is non-empty, every commit message ends with a blank line and that trailer; when it is empty (the default), commit messages carry no trailer and no AI-authorship marker. Tests run with a throwaway HOME: `env HOME=$(mktemp -d) bun test <paths>`. Code search: zg (`zg --mode direct --refresh wait "<question>"` for semantic and hybrid hits, `--fts <Symbol>` for exact symbols, `zg --rg -n -w <symbol> src tests` for exhaustive callers); CodeGraph is not used. Never merge a PR, never arm auto-merge, never push to the base branch, never force-push over commits you did not write. Never touch the kanban board: card ids are context, not something to move or comment. Security details never go into public text; see the cycle_review node. Long commands: wait with ONE blocking call, never a polling loop; never end a reply while a command you started is still running, and never end with a progress report - the reply is the node result.'
- name: kind
  type: enum
  label: Change kind (auto reads it from the instruction, then the branch prefix)
  options:
  - auto
  - feature
  - fix
  - refactor
  - chore
  - docs
  - deps
  default: auto
- name: base
  type: text
  label: Base branch (an explicit base in the instruction wins)
  options: null
  default: main
- name: release
  type: enum
  label: Version bump (auto derives it from the kind, and for deps from the runtime dependencies; see the intake node)
  options:
  - auto
  - major
  - minor
  - patch
  - none
  default: auto
- name: commit_trailer
  type: text
  label: Trailer that ends every commit message (empty for none)
  options: null
  default: ''
- name: pr_footer
  type: text
  label: Last line of every PR description (empty for none)
  options: null
  default: ''
defaults:
  profile:
    name: osb-developer
    scope: auto
  max_retries: null
  timeout_seconds: null
  on_failure: blocked
supervisor: null
trigger:
  when:
  - prepare a pull request for an open-second-brain branch whose implementation is done
  - review, gate, version and open a PR for an open-second-brain change of any kind
  - get an open-second-brain branch to an open PR with green CI and addressed bot review
  avoid_when:
  - the change is not implemented yet (implement it first, or use osb-feature-release)
  - merging or releasing (the operator merges; osb-release publishes)
  examples:
  - prepare the PR for this branch, it is a fix for issue 190
  - open a docs PR from the current branch
requires:
  files:
  - CLAUDE.md
  commands:
  - zg
  - code-ranker
  - bun
  - git
  - gh
  - ocr
  - codex
  - claude
goal:
  statement: The branch is open as a pull request against the base, with green CI, bot review findings addressed or answered, the version and CHANGELOG handled as CLAUDE.md prescribes for the change kind, and nothing merged.
  criteria:
  - description: The PR is open, not merged, auto-merge is not armed, and its head is the reviewed and gated commit.
    check:
      type: manual
  - description: The dev quality cycle (skill dev-quality-cycle) ran on the final reviewed head before the push and converged by its own stop rule, the local CI gates and the architecture gate with zero new violations against the main baseline ran, with the gates re-run after any cycle fix, and the owner approved the push; CI is green on the final head, or the finish answer names exactly what is left for a human.
    check:
      type: manual
  - description: A release-bearing kind carries its version bump, CHANGELOG entry with link reference and a mermaid diagram that renders in the PR; a no-release kind carries none of the version changes.
    check:
      type: manual
effects:
- fs_read
- fs_write
- network
- external
nodes:
- id: start
  title: null
  expected_duration: null
  inputs: null
  outputs: null
  cache: null
  type: start
- id: intake
  title: Resolve the PR context and commit pending work
  expected_duration: 15m
  inputs: null
  outputs: null
  cache: null
  success_check: scripts/check-context.sh
  type: agent_task
  prompt: |
    Standing brief: {{params.brief}}
    Commit trailer: {{params.commit_trailer}}
    Parameters: kind={{params.kind}}, base={{params.base}}, release={{params.release}}
    Run input: {{run.instruction}}

    You prepare the context every later node relies on. Work in the
    repository root; do not change code beyond committing work that is
    already there.

    1. Base: an explicit base branch in the run input wins, else the
       base parameter. `git fetch origin <base>`.
    2. Kind (feature|fix|refactor|chore|docs|deps): the run input wins,
       then a kind parameter other than auto, then the branch prefix
       (feat/ fix/ refactor/ chore/ docs/ deps/ or chore/deps). If none
       of these decides it, fail naming the ambiguity; do not guess.
    3. Release bump: a release parameter other than auto wins (the run
       input may state one too). Otherwise the kind decides, following
       CLAUDE.md ("for any feature/fix PR that ships a release") and the
       history of main: feature -> minor, fix -> patch, refactor, chore,
       docs -> none (no version bump and no CHANGELOG entry, like #175,
       #142 and #121 on main). deps -> none when only development
       dependencies or tooling move (package.json devDependencies,
       bun.lock entries only they pull in, CI actions); deps -> patch
       when the diff adds, removes or changes a RUNTIME dependency
       (package.json dependencies, optionalDependencies or
       peerDependencies, or pyproject.toml project dependencies),
       because that changes what users install. Read the diff of those
       files to decide; say which rule applied in the intent.
    4. Branch: if HEAD is on the base branch with uncommitted work, create
       `<prefix>/<slug>` (prefix from the kind: feat, fix, refactor,
       chore, docs, deps) and move the work there. A detached HEAD, or
       a branch with no change against origin/<base> and nothing
       uncommitted, is a failure with that reason.
    5. Uncommitted implementation work: read it, then commit it as
       atomic conventional commits per the brief (formatted and linted,
       staged by name). Leave the ignored runtime state (.apb/runs/, .zvec-grep/) alone. If a
       change looks unrelated to the stated intent, leave it
       uncommitted and fail, naming the files.
    6. Record the context for the script nodes:
       `d=$(git rev-parse --path-format=absolute --git-path osb-pr-prepare); mkdir -p "$d"`
       and write "$d/context.env" with exactly these shell assignments:
       OSB_BASE=<base>, OSB_KIND=<kind>, OSB_RELEASE=<major|minor|patch|none>,
       OSB_BRANCH=<branch>. Remove a stale "$d/pr.env" only if its PR is
       not open for this branch (`gh pr view <n> --json state,headRefName`);
       keep it when it is, so a re-run updates the same PR.

    Write your verdict to $APB_STATUS_FILE with outputs
    {kind, release, base, branch, intent (one paragraph, English),
    issues (GitHub issue numbers the change addresses, or []),
    cards (kanban card ids from the run input, or []),
    commits_added (list of "sha title")}.
  profile: null
  max_retries: 1
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: zg_index
  title: Ensure the local zg index
  expected_duration: 5m
  inputs: null
  outputs: null
  cache: null
  type: script
  script: scripts/zg-index.sh
  runner: sh
  timeout_seconds: 1800
- id: docs_version
  title: Docs, version and CHANGELOG per the change kind
  expected_duration: 30m
  inputs: null
  outputs:
    files: []
    extract: node_output
  cache: null
  success_check: scripts/check-release.sh
  type: agent_task
  prompt: |
    Standing brief: {{params.brief}}
    Commit trailer: {{params.commit_trailer}}
    Context: {{nodes.intake.output}}

    Follow CLAUDE.md "Versioning" exactly. The release bump in the
    context (OSB_RELEASE in <git-dir>/osb-pr-prepare/context.env) decides:

    - major|minor|patch (the PR ships a release):
      1. CHANGELOG.md: a new `## [X.Y.Z] - <today, YYYY-MM-DD>` entry at
         the top in the house voice (read the last three entries first:
         an opening paragraph, then Fixed / Changed / Added with bold
         lead-ins, capability-first, true to the diff). An existing
         `## [Unreleased]` section becomes that entry rather than
         staying above it. Add the link reference
         `[X.Y.Z]: https://github.com/itechmeat/open-second-brain/compare/vPREV...vX.Y.Z`
         above the previous one. Security fixes are worded neutrally.
      2. package.json `version` only, then `bun run scripts/sync-version.ts`
         and `bun run scripts/sync-version.ts --check`. Never hand-edit
         the mirrored manifests.
    - none: no version bump, no CHANGELOG entry.

    For every kind: README "What is new" or the docs the change affects
    (install/, docs/, hooks/README.md, skills/) are updated when the
    change alters what they describe; after changing skills/ or
    hooks/hooks.json run `bun run sync-plugin-mirrors`. Commit as
    `chore(release): vX.Y.Z` for the bump and `docs(<scope>): ...` for
    docs.

    Wrap ONLY the result in <node_output> and </node_output>: the bump
    (PREV -> X.Y.Z, or none and why), the CHANGELOG heading, the docs
    touched, commit shas.
  profile: null
  max_retries: 1
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: qa_gates
  title: CI gates, run locally as CI runs them
  expected_duration: 25m
  inputs: null
  outputs: null
  cache: null
  type: script
  script: scripts/qa-gates.sh
  runner: sh
  timeout_seconds: 3600
- id: qa_check
  title: QA verdict
  expected_duration: null
  inputs: null
  outputs: null
  cache: null
  type: condition
  max_loops: 4
- id: qa_fix
  title: Fix the red QA gates
  expected_duration: 40m
  inputs: null
  outputs:
    files: []
    extract: node_output
  cache: null
  type: agent_task
  prompt: |
    Standing brief: {{params.brief}}
    Commit trailer: {{params.commit_trailer}}
    Gate output: {{nodes.qa_gates.output}}

    Make every red gate green in the branch. Full logs are in
    <git-dir>/osb-pr-prepare/qa-logs/<step>.log. The usual repairs:
    `bun run fmt`, `bun run lint:fix`, `bun run sync-plugin-mirrors`,
    `bun run scripts/sync-version.ts`, and for the openclaw-bundle gate
    a rebuild with the CI Bun: `PATH=~/.cache/osb-pr-prepare/bun-1.4.0/bun-linux-x64:$PATH
    bun run build:openclaw` (never with the local newer Bun). Fix
    failing tests at their cause, not by weakening assertions.

    A failing test that is environment-only (it fails on the merge base
    too, in this environment, for a reason outside the branch, such as
    the WSL loopback timeout in capability-tier) is not fixed here:
    prove it by running that one test on the merge base in a throwaway
    worktree, then append its exact `bun test` name (as printed after
    "(fail) ", without the timing) to
    <git-dir>/osb-pr-prepare/known-test-failures.txt and name it with
    the evidence in your output. Write the merge base you proved it on
    (`git merge-base origin/<base> HEAD`) to
    <git-dir>/osb-pr-prepare/known-test-failures.base: the QA gate
    ignores the list once the merge base moves. Never add a test that
    fails only on the branch.

    Commit fixes per the brief. Wrap ONLY the result in <node_output>
    and </node_output>: each red gate, the cause, the fix commit or the
    known-failure evidence.
  profile: null
  max_retries: null
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: arch_gate
  title: Architecture gate (code-ranker, regressions only)
  expected_duration: 2m
  inputs: null
  outputs: null
  cache: null
  type: script
  script: scripts/arch-gate.sh
  runner: sh
  timeout_seconds: 900
- id: arch_check
  title: Architecture verdict
  expected_duration: null
  inputs: null
  outputs: null
  cache: null
  type: condition
  max_loops: 3
- id: arch_fix
  title: Fix the architecture regressions
  expected_duration: 30m
  inputs: null
  outputs:
    files: []
    extract: node_output
  cache: null
  type: agent_task
  prompt: |
    Standing brief: {{params.brief}}
    Commit trailer: {{params.commit_trailer}}
    Gate output: {{nodes.arch_gate.output}}

    The code-ranker gate found violations this branch introduces against
    the merge base (pre-existing debt is excluded by the baseline).
    Before touching code, read `code-ranker docs ts <PRINCIPLE>` for each
    finding (for example ADP for a cycle, HK for coupling), then apply
    the smallest structural fix it prescribes, keeping behavior and
    public APIs intact. Re-run the gate yourself with
    `sh .apb/playbooks/osb-pr-prepare/$(cat .apb/playbooks/osb-pr-prepare/current)/scripts/arch-gate.sh`
    (the script node runs it again after you).
    Run the affected tests, commit as `refactor(<scope>): ...`.

    Wrap ONLY the result in <node_output> and </node_output>: each
    violation and the commit that removed it.
  profile: null
  max_retries: null
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: cycle_run
  title: Dev quality cycle, steps 1-3 (OCR, Codex, /security-review)
  expected_duration: 30m
  inputs: null
  outputs: null
  cache: null
  type: script
  script: scripts/cycle-run.sh
  runner: sh
  timeout_seconds: 5400
- id: cycle_review
  title: 'Dev quality cycle: verify, audits, fixes, convergence'
  expected_duration: 75m
  inputs: null
  outputs:
    files: []
    extract: node_output
  cache: null
  success_check:
    marker: 'CYCLE: done'
  type: agent_task
  prompt: |
    Standing brief: {{params.brief}}
    Commit trailer: {{params.commit_trailer}}
    Context: {{nodes.intake.output}}
    Runner output (steps 1-3): {{nodes.cycle_run.output}}

    Load the dev-quality-cycle skill by name and follow it: SKILL.md,
    references/steps.md, references/convergence.md and
    templates/report.md. The skill is the rule; this prompt only adds
    what is specific to Open Second Brain and to this playbook.

    1. Steps 1-3 already ran through the skill runner (the cycle_run
       node; its last line is `CYCLE-RUN: <status> exit=<n>
       summary=<path>`). Read summary.txt and the ocr, codex and
       security-review outputs in that run folder. `nothing-new` (runner
       exit 4) means the cycle already reviewed HEAD on an earlier
       pass: skip to the output below with `CYCLE: done (0 rounds, 0
       real, 0 fixed, 0 declined)` and that reason. `failed`: a step
       did not really review; rerun only that step with the skill
       runner once (`--steps <step>`, same range) and report it; never
       report a step that did not review as clean. `resumable`: a
       usage or session limit; run the printed resume command once
       after the reset when it is within 30 minutes, else fail this
       node naming the reset time and the resume command.
    2. Step 4: the security-audit skill in guidance mode, focused on
       the cycle range and the trust boundaries it touches (read
       callers with `zg --rg -n -w <symbol> src tests plugins
       scripts hooks skills` where a changed function is reached from
       an MCP tool, CLI verb, hook, HTTP transport, file import or
       config read). Never the full audit workflow.
    3. Step 5: the test-audit skill on every test file the range adds
       or changes, with the Open Second Brain commands from the brief
       instead of the OpenClaw tooling it names. Two project rules on
       top: a test that compares output embedding a timestamp or a
       generated id is normalised or rewritten; a regression test
       (kind fix, or any test that pins a bug) is proved to fail on
       the merge base for the intended reason (throwaway `git worktree
       add --detach "$(mktemp -d)" <merge-base>`, copy in only that
       test, `env HOME=$(mktemp -d) bun test <file>`, record the
       failure line, remove the worktree).
    4. Step 6 is the QA and architecture gate nodes that ran before
       you and the final_gates node after you; run the targeted tests
       of anything you fix (`env HOME=$(mktemp -d) bun test <paths>`).
    5. Findings: verify each against the code, classify and decide as
       references/convergence.md says (real only with a concrete
       failing scenario; decline the rest in one line). Fix the real
       ones in dedicated conventional commits per the brief, smallest
       diff; zg finds the callers and sibling implementations that
       must change alike (Python plugin mirror, Codex mirrors, docs).
       New rounds only as the convergence table says, scoped to the
       fix commits, through the skill runner (for example
       `<skill>/scripts/cycle.sh --range <before-fix>..HEAD --steps
       ocr`); stop by its stop rule. Long runner calls: one blocking
       wait, never a polling loop.
    6. Do not push and do not touch the version or CHANGELOG: the QA
       and architecture gates run again after you when you committed.
    7. Last, record the head the cycle reviewed: write the line
       `<branch> <git rev-parse HEAD>` to
       <git-dir>/osb-pr-prepare/cycle-reviewed (the cycle_run node of a
       later pass reviews only what came after it).

    Security dispositions (the repository is PUBLIC):
    - A confirmed issue the branch introduces (never released): fix it in
      the branch with a regression test, as an ordinary conventional commit.
    - A confirmed issue in code already released on the base that the
      diff touches: fix it in THIS public PR, worded neutrally, AND open a
      private DRAFT security advisory that carries the details. Both,
      always: the fix does not wait for the advisory, and the advisory is
      not skipped because the fix ships.
    - A confirmed issue in released code the diff does not touch: do not
      fix it here; open a private draft advisory only.
    Private advisory, created as a draft and never published by you:
    `gh api repos/itechmeat/open-second-brain/security-advisories -X POST
    -f summary=<short> -f description=<details and fix> -f severity=<low|medium|high|critical>`
    plus the required vulnerabilities field per the GitHub REST docs.
    The advisory is the ONLY place the exploit details, the attack
    narrative and the severity are written. Public artifacts (commit
    messages, code comments, test names, the PR title and body, PR
    comments and replies, CHANGELOG, docs, release notes) describe a
    security fix only in neutral behavioral terms ("validate X before Y",
    "refuse paths outside the vault"), with no exploit, no attack
    narrative, no severity, no advisory id and no words like vulnerability
    or exploit.

    Wrap ONLY the result in <node_output> and </node_output>. Required
    first line: `CYCLE: done (<rounds> rounds, <real> real, <fixed> fixed,
    <declined> declined)`. Then the report filled from the skill's
    templates/report.md (every step, fixed with sha, declined with the
    reason, not-this-change items, the next-round decision with its
    reason, skill update). Security findings appear only as counts and
    advisory references; this output stays in the run. A runner or
    skill that cannot be loaded is a node failure naming the error,
    never a review without the cycle.
  profile:
    name: osb-reviewer
    scope: auto
  max_retries: 1
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: final_gates
  title: QA and architecture gates again after the review
  expected_duration: 27m
  inputs: null
  outputs: null
  cache: null
  type: script
  script: scripts/final-gates.sh
  runner: sh
  timeout_seconds: 4500
- id: final_check
  title: Final gate verdict
  expected_duration: null
  inputs: null
  outputs: null
  cache: null
  type: condition
  max_loops: 3
- id: final_fix
  title: Fix the red final gates
  expected_duration: 40m
  inputs: null
  outputs:
    files: []
    extract: node_output
  cache: null
  type: agent_task
  prompt: |
    Standing brief: {{params.brief}}
    Commit trailer: {{params.commit_trailer}}
    Gate output: {{nodes.final_gates.output}}
    Cycle report: {{nodes.cycle_review.output}}

    The QA or the architecture gate turned red after the dev quality cycle
    pass. Make every red gate green in the branch without undoing a
    cycle fix: for QA, the repairs and the known-failure rule
    of the qa_fix node (full logs in <git-dir>/osb-pr-prepare/qa-logs/);
    for architecture, the code-ranker rule of the arch_fix node (read
    `code-ranker docs ts <PRINCIPLE>` first, smallest structural fix).
    Commit per the brief. A code fix (not a pure formatting or mirror
    sync) goes through the convergence table of the dev-quality-cycle
    skill before you finish: usually OCR on your fix commits only
    (`<skill>/scripts/cycle.sh --range <before-fix>..HEAD --steps ocr`);
    verify its findings like the cycle_review node does. Then write
    `<branch> <git rev-parse HEAD>` to
    <git-dir>/osb-pr-prepare/cycle-reviewed. The script node runs both
    gates again after you.

    Wrap ONLY the result in <node_output> and </node_output>: each red
    gate, the cause, the fix commit, and the cycle pass on the fix
    commits (range, findings, decision).
  profile: null
  max_retries: null
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: push_approval
  title: Owner approval of the push and the PR
  expected_duration: null
  inputs: null
  outputs: null
  cache: null
  type: human_review
  options:
  - approve
  - reject
  prompt: 'The dev quality cycle is closed and the final gates are green. Read the cycle report (cycle_review output) and the final gate verdict, then approve to push the branch and open or update the PR, or reject to stop the run before anything leaves the machine. An approval covers this branch: the CI-fix pushes of the same PR that follow it (ci_fix) need no new approval; CodeRabbit fixes are pushed under the host''s own exception once their cycle is clean.'
- id: push_pr
  title: Push and open (or update) the PR
  expected_duration: 25m
  inputs: null
  outputs:
    files: []
    extract: node_output
  cache: null
  success_check: scripts/check-pr.sh
  type: agent_task
  prompt: |
    Standing brief: {{params.brief}}
    PR footer (the exact last line of the description): {{params.pr_footer}}
    Context: {{nodes.intake.output}}
    Cycle report: {{nodes.cycle_review.output}}
    Push approval note: {{nodes.push_approval.review_note}}
    Docs and version: {{nodes.docs_version.output}}

    1. Push. If the diff against origin/<base> touches .github/workflows/,
       push over SSH so no token scope can refuse it:
       `git push [email protected]:itechmeat/open-second-brain.git HEAD:refs/heads/<branch>`
       then `git branch --set-upstream-to=origin/<branch>` after a
       `git fetch origin <branch>`; otherwise `git push -u origin <branch>`.
       Never push to the base, never force-push commits you did not write.
    2. PR text, in the voice of the recent PRs (`gh pr view 193` and
       `gh pr view 191` are the reference): title as a conventional
       summary, with ` (vX.Y.Z)` appended when the PR ships a release
       (`feat: <capability tagline> (v1.58.0)`, `fix(<scope>): ... (v1.57.2)`).
       Body: Summary (capability-first), a mermaid diagram of the
       process-level benefit (required when the PR ships a release,
       optional otherwise), What changed, Verification (the gates that
       ran, with counts; when the diff against origin/<base> exceeds
       100 files, one line naming the bot review as skipped, since
       CodeRabbit skips a change set over its 100-file limit), and
       `Closes #N` / `Refs #N` for the GitHub issues in the context.
       Kanban card ids stay out of the public text. Security fixes in
       neutral terms only. When the PR footer above is non-empty, the
       description ends with it verbatim; when it is empty, the
       description carries no footer and no AI-authorship marker.
    3. Mermaid: try a local parse first when it runs here
       (`bunx -p @mermaid-js/mermaid-cli mmdc -i <file>.mmd -o <file>.svg`;
       agent-browser's Chrome can serve as PUPPETEER_EXECUTABLE_PATH).
       The check that counts is the PR page: once the PR exists, open it
       with agent-browser and confirm the diagram rendered as a diagram
       (no "Unable to render rich display" box). Fix and
       `gh pr edit --body-file` until it does.
    4. Open or update: if an open PR for this branch exists
       (`gh pr view --json number,state`), update its title and body;
       else `gh pr create --base <base> --head <branch> --title ...
       --body-file ...`. Never `gh pr merge`, never `--auto`.
    5. Record `OSB_PR_NUMBER=<n>` and `OSB_PR_URL=<url>` in
       <git-dir>/osb-pr-prepare/pr.env.

    Wrap ONLY the result in <node_output> and </node_output>. Required
    first line: `PR: #<number> <url>`. Then the pushed head sha and the
    mermaid evidence (local render, and what the PR page showed).
  profile: null
  max_retries: 2
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: ci_wait
  title: Wait for CI (one blocking watch)
  expected_duration: 35m
  inputs: null
  outputs: null
  cache: null
  type: script
  script: scripts/ci-wait.sh
  runner: sh
  timeout_seconds: 6600
- id: ci_wait_final
  title: Wait for CI after the budget-capped bot review pass
  expected_duration: 35m
  inputs: null
  outputs: null
  cache: null
  type: script
  script: scripts/ci-wait.sh
  runner: sh
  timeout_seconds: 6600
- id: ci_check
  title: CI verdict
  expected_duration: null
  inputs: null
  outputs: null
  cache: null
  type: condition
  max_loops: 4
- id: ci_fix
  title: Fix the red CI checks and push
  expected_duration: 40m
  inputs: null
  outputs:
    files: []
    extract: node_output
  cache: null
  success_check: scripts/check-pr.sh
  type: agent_task
  prompt: |
    Standing brief: {{params.brief}}
    Commit trailer: {{params.commit_trailer}}
    CI output: {{nodes.ci_wait.output}}

    Diagnose each failed check from the job logs above (`gh run view
    --job <id> --log` for more). Reproduce it locally when the platform
    allows (the windows job cannot run here: reason from the log and
    the Windows notes in install/windows.md and CLAUDE.md). A flaky
    timing failure unrelated to the branch is re-run once with
    `gh run rerun <run-id> --failed` instead of a code change, and
    named as such; a rerun is only for failures outside the
    repository's code. An HTTP 429 or 5xx from an external service
    inside a repository script is fixed at the cause: a bounded retry
    in that script (a fixed attempt count and backoff, then the error
    by name), not a rerun. Otherwise fix at the cause, run the
    affected local gates and commit per the brief. A code fix (not a
    pure formatting or mirror sync) goes through the convergence table
    of the dev-quality-cycle skill before the push: usually OCR on your
    fix commits only (`<skill>/scripts/cycle.sh --range
    <before-fix>..HEAD --steps ocr`); verify its findings like the
    cycle_review node does, then write `<branch> <git rev-parse HEAD>`
    to <git-dir>/osb-pr-prepare/cycle-reviewed. Push only when that is
    clean, the same way push_pr did (SSH when .github/workflows/
    changed). The bot_review node after you handles the bot's findings
    on the new head. Do not edit the PR text unless the fix changes
    what it claims.

    Wrap ONLY the result in <node_output> and </node_output>: each failed
    check, the cause, the fix commit or the rerun, and the cycle pass on
    the fix commits (range, findings, decision).
  profile: null
  max_retries: null
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: bot_review
  title: Handle the bot review (CodeRabbit)
  expected_duration: 30m
  inputs: null
  outputs: null
  cache: null
  success_check: scripts/check-pr.sh
  type: agent_task
  prompt: |-
    Standing brief: {{params.brief}}
    Commit trailer: {{params.commit_trailer}}
    PR: read the number from <git-dir>/osb-pr-prepare/pr.env.

    This node starts IMMEDIATELY after the push, while CI is still running.
    Do not wait for the checks to conclude and do not watch them; the
    ci_wait node after you waits for the checks. Start the review work now.

    First wait for CodeRabbit's review OF THE CURRENT HEAD to be POSTED:
    it usually arrives minutes after the push, long before the checks
    end. Take the head with `git rev-parse HEAD` and poll
    `gh api --paginate --slurp repos/<owner>/<repo>/pulls/<n>/reviews` in one blocking loop
    (sleep 60 between calls, at most 10 minutes) until a CodeRabbit
    review's `commit_id` equals that head; an earlier review does not
    count. Then read what it said (`gh api --paginate --slurp .../pulls/<n>/comments` and `gh pr
    view <n> --comments`). If no review of the head appears in that
    window, say so in the reply and continue. Handle only comments you have not already
    answered in an earlier pass of this node.

    The operator may hand external review documents to the orchestrator
    mid-wave (paths under .reviews/ or pasted text). When this task's
    response carries them, treat every finding in them exactly like a
    CodeRabbit finding: verify against the current code, then fix or
    answer. Such findings are worked on immediately, never held back for
    CI.

    - Skipped (for example "files exceed the limit"): post one PR
      comment saying which internal review compensated (the
      dev quality cycle of this run: OpenCodeReview, Codex review,
      /security-review, security-audit and test-audit), in neutral terms.
    - Each finding: verify it against the current code with the
      receiving-code-review discipline. Valid: fix with the smallest
      diff. Not valid or no longer applicable: reply on the thread with
      a one-sentence technical reason. Valid fixes get a reply naming
      the commit.
    - Fixes go through the convergence table of the dev-quality-cycle
      skill (references/convergence.md, section 5): usually OCR on the
      fix commits only (`<skill>/scripts/cycle.sh --range
      <before-fix>..HEAD --steps ocr`), never a full cycle restart by
      itself. A code fix also passes the QA and architecture gates on
      the fix head: `sh .apb/playbooks/osb-pr-prepare/$(cat
      .apb/playbooks/osb-pr-prepare/current)/scripts/final-gates.sh`. Push only when both are
      clean.
    - Commit fixes per the brief (for example `fix: address CodeRabbit
      review feedback`) and push the same way push_pr did. A push here
      restarts CI; that is expected, because the ci_wait node after you
      waits for the new run.
    One pass per call; do not wait for a second bot pass.

    Write your verdict to $APB_STATUS_FILE with outputs
    {pushed: "yes" if you pushed commits, else "no", findings: <count>,
    fixed: [shas], answered: <count>, skipped_reason: <text or "">}.
  profile: null
  max_retries: 1
  timeout_seconds: null
  workdir: null
  isolation: null
  connectors: []
  interactive: false
- id: ready
  title: null
  expected_duration: 3m
  inputs: null
  outputs: null
  cache: null
  type: finish
  outcome: success
  prompt: |
    Compose the final answer for the operator from the run context:
    first line `PR: #<number> <url>`; then CI state as
    `gh pr checks <n>` reports it NOW (run it once; say green, or name
    what is red or pending); the kind, the version bump or none; a
    five-line summary of what the PR ships; what the dev quality cycle did (per step:
    findings, fixed, declined; security only "clean" or the count of
    fixed items and advisory drafts, never details; rounds and the
    convergence decision), the architecture gate and the final gates did; and a "Left for a human" list: gates that ended on their
    loop budget, known environment-only test failures, bot findings
    answered but not fixed, cycle findings declined or deferred, advisory drafts to publish, the merge
    itself. Plain text, English.
  profile: null
- id: blocked
  title: null
  expected_duration: 3m
  inputs: null
  outputs: null
  cache: null
  type: finish
  outcome: failure
  prompt: |
    The PR preparation stopped before a PR with green CI existed.
    Compose the answer from the run context: the node that stopped it
    and its last output (the reason, verbatim where short), whether a
    PR exists (`PR: #<n> <url>` or `PR: none`), what was already
    committed and pushed, and the exact next step a human should take.
    Plain text, English. No security details.
  profile: null
edges:
- from: start
  to: intake
  condition: null
  fallback: false
  join: null
- from: intake
  to: zg_index
  condition: null
  fallback: false
  join: null
- from: zg_index
  to: docs_version
  condition:
    type: node_status
    node: zg_index
    equals: success
  fallback: false
  join: null
- from: zg_index
  to: docs_version
  condition:
    type: node_status
    node: zg_index
    equals: failure
  fallback: false
  join: null
- from: docs_version
  to: qa_gates
  condition: null
  fallback: false
  join: null
- from: qa_gates
  to: qa_check
  condition: null
  fallback: false
  join: null
- from: qa_check
  to: arch_gate
  condition:
    type: node_status
    node: qa_gates
    equals: success
  fallback: false
  join: null
- from: qa_check
  to: qa_fix
  condition:
    type: output_match
    node: qa_gates
    pattern: 'QA-GATE: red'
  fallback: false
  join: null
- from: qa_check
  to: blocked
  condition: null
  fallback: true
  join: null
- from: qa_fix
  to: qa_gates
  condition: null
  fallback: false
  join: null
- from: arch_gate
  to: arch_check
  condition: null
  fallback: false
  join: null
- from: arch_check
  to: cycle_run
  condition:
    type: node_status
    node: arch_gate
    equals: success
  fallback: false
  join: null
- from: arch_check
  to: arch_fix
  condition:
    type: output_match
    node: arch_gate
    pattern: 'ARCH-GATE: violations'
  fallback: false
  join: null
- from: arch_check
  to: blocked
  condition: null
  fallback: true
  join: null
- from: arch_fix
  to: arch_gate
  condition: null
  fallback: false
  join: null
- from: final_gates
  to: final_check
  condition: null
  fallback: false
  join: null
- from: final_check
  to: push_approval
  condition:
    type: node_status
    node: final_gates
    equals: success
  fallback: false
  join: null
- from: final_check
  to: final_fix
  condition:
    type: output_match
    node: final_gates
    pattern: 'FINAL-GATES: red'
  fallback: false
  join: null
- from: final_check
  to: blocked
  condition: null
  fallback: true
  join: null
- from: final_fix
  to: final_gates
  condition: null
  fallback: false
  join: null
- from: push_pr
  to: bot_review
  condition: null
  fallback: false
  join: null
- from: ci_wait
  to: ci_check
  condition: null
  fallback: false
  join: null
- from: ci_check
  to: ci_fix
  condition:
    type: output_match
    node: ci_wait
    pattern: 'CI-GATE: red'
  fallback: false
  join: null
- from: ci_check
  to: blocked
  condition:
    type: node_status
    node: ci_wait
    equals: failure
  fallback: false
  join: null
- from: ci_check
  to: bot_review
  condition:
    type: output_field
    node: bot_review
    field: pushed
    equals: 'yes'
  fallback: false
  join: null
- from: ci_check
  to: ready
  condition:
    type: output_field
    node: bot_review
    field: pushed
    equals: 'no'
  fallback: false
  join: null
- from: ci_check
  to: blocked
  condition: null
  fallback: true
  join: null
- from: ci_fix
  to: bot_review
  condition: null
  fallback: false
  join: null
- from: bot_review
  to: ci_wait
  condition: null
  fallback: false
  join: null
  max_traversals: 2
- from: bot_review
  to: ci_wait_final
  condition: null
  fallback: true
  join: null
- from: ci_wait_final
  to: ready
  condition:
    type: node_status
    node: ci_wait_final
    equals: success
  fallback: false
  join: null
- from: ci_wait_final
  to: blocked
  condition: null
  fallback: true
  join: null
- from: cycle_run
  to: cycle_review
  condition: null
  fallback: false
  join: null
- from: cycle_review
  to: final_gates
  condition: null
  fallback: false
  join: null
- from: push_approval
  to: push_pr
  condition:
    type: review_status
    equals: approve
  fallback: false
  join: null
- from: push_approval
  to: blocked
  condition:
    type: review_status
    equals: reject
  fallback: false
  join: null