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
35.7 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, a self-review against
  the base with zg reconnaissance, a test-audit of the tests the diff adds or changes, a focused security
  review of the diff, docs plus the version and CHANGELOG decision the change kind drives (CLAUDE.md),
  then before the push, in this order and each with its fix loop: the CI QA gates run locally exactly
  as CI runs them, the code-ranker architecture gate against the main baseline (zero new violations, else
  blocked), an OpenCodeReview review of the branch diff in delegation mode on a fixed model (profile osb-reviewer)
  that fixes the confirmed findings, and the QA and architecture gates again when that review changed
  anything; 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.2.0
params:
- name: brief
  type: text
  label: Standing brief for PR preparation (override to change the rules)
  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 query --mode direct --refresh wait "<question>"` for semantic and hybrid hits, `--fts <Symbol>`
    for exact symbols, `zg query --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 security_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)
  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)
  default: ''
- name: pr_footer
  type: text
  label: Last line of every PR description (empty for none)
  default: ''
defaults:
  profile: osb-developer
  on_failure: blocked
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
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: Self-review, the diff-scoped test-audit and security review, the local CI gates, the
      architecture gate with zero new violations against the main baseline and the OpenCodeReview delegation
      review ran before the push, with the gates re-run after any review fix; 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
  type: start
- id: intake
  title: Resolve the PR context and commit pending work
  type: agent_task
  expected_duration: 15m
  prompt: "Standing brief: {{params.brief}}\nCommit trailer: {{params.commit_trailer}}\nParameters: kind={{params.kind}},\
    \ base={{params.base}}, release={{params.release}}\nRun input: {{run.instruction}}\n\nYou prepare\
    \ the context every later node relies on. Work in the\nrepository root; do not change code beyond\
    \ committing work that is\nalready there.\n\n1. Base: an explicit base branch in the run input wins,\
    \ else the\n   base parameter. `git fetch origin <base>`.\n2. Kind (feature|fix|refactor|chore|docs|deps):\
    \ the run input wins,\n   then a kind parameter other than auto, then the branch prefix\n   (feat/\
    \ fix/ refactor/ chore/ docs/ deps/ or chore/deps). If none\n   of these decides it, fail naming the\
    \ ambiguity; do not guess.\n3. Release bump: a release parameter other than auto wins (the run\n \
    \  input may state one too). Otherwise the kind decides, following\n   CLAUDE.md (\"for any feature/fix\
    \ PR that ships a release\") and the\n   history of main: feature -> minor, fix -> patch, refactor,\
    \ chore,\n   docs -> none (no version bump and no CHANGELOG entry, like #175,\n   #142 and #121 on\
    \ main). deps -> none when only development\n   dependencies or tooling move (package.json devDependencies,\n\
    \   bun.lock entries only they pull in, CI actions); deps -> patch\n   when the diff adds, removes\
    \ or changes a RUNTIME dependency\n   (package.json dependencies, optionalDependencies or\n   peerDependencies,\
    \ or pyproject.toml project dependencies),\n   because that changes what users install. Read the diff\
    \ of those\n   files to decide; say which rule applied in the intent.\n4. Branch: if HEAD is on the\
    \ base branch with uncommitted work, create\n   `<prefix>/<slug>` (prefix from the kind: feat, fix,\
    \ refactor,\n   chore, docs, deps) and move the work there. A detached HEAD, or\n   a branch with\
    \ no change against origin/<base> and nothing\n   uncommitted, is a failure with that reason.\n5.\
    \ Uncommitted implementation work: read it, then commit it as\n   atomic conventional commits per\
    \ the brief (formatted and linted,\n   staged by name). Leave the ignored runtime state (.apb/runs/,\
    \ .zvec-grep/) alone. If a\n   change looks unrelated to the stated intent, leave it\n   uncommitted\
    \ and fail, naming the files.\n6. Record the context for the script nodes:\n   `d=$(git rev-parse\
    \ --path-format=absolute --git-path osb-pr-prepare); mkdir -p \"$d\"`\n   and write \"$d/context.env\"\
    \ with exactly these shell assignments:\n   OSB_BASE=<base>, OSB_KIND=<kind>, OSB_RELEASE=<major|minor|patch|none>,\n\
    \   OSB_BRANCH=<branch>. Remove a stale \"$d/pr.env\" only if its PR is\n   not open for this branch\
    \ (`gh pr view <n> --json state,headRefName`);\n   keep it when it is, so a re-run updates the same\
    \ PR.\n\nWrite your verdict to $APB_STATUS_FILE with outputs\n{kind, release, base, branch, intent\
    \ (one paragraph, English),\nissues (GitHub issue numbers the change addresses, or []),\ncards (kanban\
    \ card ids from the run input, or []),\ncommits_added (list of \"sha title\")}.\n"
  success_check: scripts/check-context.sh
  max_retries: 1
- id: zg_index
  title: Ensure the local zg index
  type: script
  script: scripts/zg-index.sh
  runner: sh
  timeout_seconds: 1800
  expected_duration: 5m
- id: self_review
  title: Self-review against the base (zg reconnaissance)
  type: agent_task
  expected_duration: 75m
  prompt: 'Standing brief: {{params.brief}}

    Commit trailer: {{params.commit_trailer}}

    Context: {{nodes.intake.output}}

    Index step: {{nodes.zg_index.output}}


    Review EVERYTHING on the branch against the merge base with

    origin/<base>, committed work included (`git diff $(git merge-base

    origin/<base> HEAD)...HEAD`), as a fresh reviewer who did not write

    it. Use the superpowers skills requesting-code-review and

    verification-before-completion.


    Reconnaissance and impact with zg, not CodeGraph. For every changed

    exported symbol, config key, CLI verb or MCP tool: find its callers

    and consumers (`zg query --rg -n -w <name> src tests plugins scripts

    hooks skills`), related mechanisms (`zg query --mode direct --refresh

    wait "<what the change does>"`), and sibling implementations that

    should have changed alike (Python plugin mirror, Codex mirrors,

    docs). If the index step failed, use `zg query --rg` only and say so.


    Check correctness, error paths, the engineering bar in the brief,

    tests that pin the behavior, and docs that describe it. Fix real

    findings in dedicated conventional commits with the smallest diff;

    a finding you reject is named with its reason. Do not bump the

    version or touch CHANGELOG here.


    Wrap ONLY the result in <node_output> and </node_output>: findings

    by severity with disposition (fixed in <sha> | rejected: reason),

    the zg queries that decided the impact analysis, remaining known

    issues (none, or argued).

    '
  outputs:
    extract: node_output
- id: test_audit
  title: Test-audit of the tests this diff adds or changes
  type: agent_task
  expected_duration: 40m
  prompt: 'Standing brief: {{params.brief}}

    Commit trailer: {{params.commit_trailer}}

    Context: {{nodes.intake.output}}


    Apply the test-audit skill (load it by name),

    authoring-gate mode, to exactly the test files this branch adds or

    changes: `git diff --name-only --diff-filter=AMR $(git merge-base

    origin/<base> HEAD) HEAD -- tests ''*.test.ts'' ''*_test.py''

    ''test_*.py''`. Tests the diff does not touch are out of scope: no

    sweep, no campaign, no deletion outside the diff.


    For each added or changed test: the four gate questions, the junk

    patterns, and the retention bar, plus one gate question of this

    project: does the test compare output that embeds a timestamp or a

    generated id (for example a second-granular run id), so that two

    runs differ by timing alone? Such a comparison is normalised (the

    volatile part masked or pinned) or the test is rewritten. Rewrite or

    remove a test that fails the gate, in the same branch.


    Regression tests (kind fix, or any test that pins a bug): prove each

    one fails on the pre-fix code for the intended reason. Take the

    merge base in a throwaway worktree (`git worktree add --detach

    "$(mktemp -d)" <merge-base>`), copy in only the new or changed test

    file, run it there (`env HOME=$(mktemp -d) bun test <file>`),

    record the failure line, then remove the worktree. A regression

    test that passes on the pre-fix code is rewritten until it fails

    there.


    The skill''s Validation and Landing sections name OpenClaw tooling

    (vitest, crabbox, scripts/pr); here use the Open Second Brain commands from the

    brief. Commit fixes as `test(<scope>): ...`.


    Wrap ONLY the result in <node_output> and </node_output>: per test

    file the verdict (kept | rewritten | removed) with the reason, and

    for each regression test the pre-fix failure line.

    '
  outputs:
    extract: node_output
- id: security_review
  title: Focused security review of the diff
  type: agent_task
  expected_duration: 40m
  prompt: "Standing brief: {{params.brief}}\nCommit trailer: {{params.commit_trailer}}\nContext: {{nodes.intake.output}}\n\
    \nApply the security-audit skill (load it by name)\nin GUIDANCE mode as a focused review. Never the\
    \ full audit workflow:\nno six phases, no output directory, no hunter or verifier fan-out,\nno report\
    \ artifacts. Scope: the diff against the merge base with\norigin/<base> and the trust boundaries it\
    \ touches (read callers with\n`zg query --rg` where a changed function is reached from an MCP\ntool,\
    \ CLI verb, hook, HTTP transport, file import or config read).\nFollow its core principles: a finding\
    \ needs a lower-trust principal,\nthe crossed boundary and a concrete result; source-first; no live\n\
    probing; run only the repository's own tests locally.\n\nDispositions:\n- A confirmed issue the branch\
    \ introduces (never released): fix it\n  in the branch with a regression test, as an ordinary\n  conventional\
    \ commit.\n- A confirmed issue in code already released on the base that the\n  diff touches: fix\
    \ it in THIS public PR, worded neutrally (below),\n  AND open a private DRAFT security advisory (below)\
    \ that carries\n  the details. Both, always: the fix does not wait for the advisory,\n  and the advisory\
    \ is not skipped because the fix ships.\n- A confirmed issue in released code the diff does not touch:\
    \ do\n  not fix it here; open a private draft advisory only.\nPrivate advisory, created as a draft\
    \ and never published by you:\n`gh api repos/itechmeat/open-second-brain/security-advisories -X POST\n\
    -f summary=<short> -f description=<details and fix> -f severity=<low|medium|high|critical>`\nplus\
    \ the required vulnerabilities field per the GitHub REST docs.\nThe advisory is the ONLY place the\
    \ exploit details, the attack\nnarrative and the severity are written.\n\nThe repository is PUBLIC.\
    \ Public artifacts - commit messages, code\ncomments, test names, the PR title and body, PR comments\
    \ and\nreplies, CHANGELOG, docs and release notes - never carry exploit\ndetails: they describe a\
    \ security fix only in neutral behavioral\nterms (\"validate X before Y\", \"refuse paths outside\
    \ the vault\"),\nwith no exploit, no attack narrative, no severity, no advisory id\nand no words like\
    \ vulnerability or exploit.\n\nWrap ONLY the result in <node_output> and </node_output>: confirmed\n\
    findings with disposition (fixed in <sha>, advisory <GHSA id or\ndraft URL>), needs-validation items\
    \ with the missing fact, and the\nboundaries reviewed. This output stays in the run; it is not public.\n"
  outputs:
    extract: node_output
- id: arch_gate
  title: Architecture gate (code-ranker, regressions only)
  type: script
  script: scripts/arch-gate.sh
  runner: sh
  timeout_seconds: 900
  expected_duration: 2m
- id: arch_check
  title: Architecture verdict
  type: condition
  max_loops: 3
- id: arch_fix
  title: Fix the architecture regressions
  type: agent_task
  expected_duration: 30m
  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.

    '
  outputs:
    extract: node_output
- id: docs_version
  title: Docs, version and CHANGELOG per the change kind
  type: agent_task
  expected_duration: 30m
  prompt: "Standing brief: {{params.brief}}\nCommit trailer: {{params.commit_trailer}}\nContext: {{nodes.intake.output}}\n\
    Review summary: {{nodes.self_review.output}}\n\nFollow CLAUDE.md \"Versioning\" exactly. The release\
    \ bump in the\ncontext (OSB_RELEASE in <git-dir>/osb-pr-prepare/context.env) decides:\n\n- major|minor|patch\
    \ (the PR ships a release):\n  1. CHANGELOG.md: a new `## [X.Y.Z] - <today, YYYY-MM-DD>` entry at\n\
    \     the top in the house voice (read the last three entries first:\n     an opening paragraph, then\
    \ Fixed / Changed / Added with bold\n     lead-ins, capability-first, true to the diff). An existing\n\
    \     `## [Unreleased]` section becomes that entry rather than\n     staying above it. Add the link\
    \ reference\n     `[X.Y.Z]: https://github.com/itechmeat/open-second-brain/compare/vPREV...vX.Y.Z`\n\
    \     above the previous one. Security fixes are worded neutrally.\n  2. package.json `version` only,\
    \ then `bun run scripts/sync-version.ts`\n     and `bun run scripts/sync-version.ts --check`. Never\
    \ hand-edit\n     the mirrored manifests.\n- none: no version bump, no CHANGELOG entry.\n\nFor every\
    \ kind: README \"What is new\" or the docs the change affects\n(install/, docs/, hooks/README.md,\
    \ skills/) are updated when the\nchange alters what they describe; after changing skills/ or\nhooks/hooks.json\
    \ run `bun run sync-plugin-mirrors`. Commit as\n`chore(release): vX.Y.Z` for the bump and `docs(<scope>):\
    \ ...` for\ndocs.\n\nWrap ONLY the result in <node_output> and </node_output>: the bump\n(PREV ->\
    \ X.Y.Z, or none and why), the CHANGELOG heading, the docs\ntouched, commit shas.\n"
  success_check: scripts/check-release.sh
  max_retries: 1
  outputs:
    extract: node_output
- id: qa_gates
  title: CI gates, run locally as CI runs them
  type: script
  script: scripts/qa-gates.sh
  runner: sh
  timeout_seconds: 3600
  expected_duration: 25m
- id: qa_check
  title: QA verdict
  type: condition
  max_loops: 4
- id: qa_fix
  title: Fix the red QA gates
  type: agent_task
  expected_duration: 40m
  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. 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.

    '
  outputs:
    extract: node_output
- id: ocr_review
  title: OpenCodeReview of the branch diff (delegation mode)
  type: agent_task
  profile: osb-reviewer
  expected_duration: 45m
  prompt: "Standing brief: {{params.brief}}\nCommit trailer: {{params.commit_trailer}}\nContext: {{nodes.intake.output}}\n\
    Self-review summary: {{nodes.self_review.output}}\n\nReview the whole branch diff against the merge\
    \ base with\norigin/<base> with OpenCodeReview (`ocr`) in delegation mode: load\nthe open-code-review\
    \ delegate-review skill by name\n(`open-code-review:delegate-review` as a plugin skill, or\n`open-code-review-delegate`)\
    \ and follow its workflow. In delegation\nmode OCR calls no LLM: it selects the reviewable files and\
    \ resolves\nthe review rules, and you perform the review. The review model is\ntherefore this node's\
    \ executor, pinned by the osb-reviewer profile\n(claude-opus-5-5, no fallback executor); `ocr review`,\
    \ `ocr scan`\nand any LLM endpoint or model configured for OCR itself are not\nused.\n\n1. `ocr delegate\
    \ preview --format json --from origin/<base> --to HEAD`\n   (the output names the merge base and the\
    \ reviewable and excluded\n   files).\n2. `ocr delegate rule --format json --from origin/<base> --to\
    \ HEAD <reviewable paths>`.\n3. For each reviewable file, keyed by (path, status): its diff\n   (`git\
    \ diff <merge_base>..HEAD -- <path>`), its rule group, and\n   the context you need (read callers\
    \ with `zg query --rg -n -w\n   <symbol> src tests plugins scripts hooks skills`). Mark it\n   reviewed,\
    \ or skipped with a concrete reason. Review large diffs\n   in batches by rule group; do not stop\
    \ at the first finding.\n4. Verify every finding against the current code with the\n   receiving-code-review\
    \ discipline. Confirmed: fix it with the\n   smallest diff, add or adjust a test when behavior changes,\
    \ run\n   the affected tests (`env HOME=$(mktemp -d) bun test <paths>`),\n   and commit per the brief\
    \ (`fix(<scope>): ...` or\n   `refactor(<scope>): ...`). Rejected or a likely false positive:\n  \
    \ one-sentence technical reason. A security-relevant finding\n   follows the security_review dispositions\
    \ and public-wording\n   rules of this playbook.\n5. Do not push and do not touch the version or CHANGELOG:\
    \ the QA\n   and architecture gates run again after you when you committed.\n\nWrap ONLY the result\
    \ in <node_output> and </node_output>. Required\nfirst line: `OCR-REVIEW: done (<reviewed>/<total>\
    \ files reviewed,\n<confirmed> confirmed, <fixed> fixed)`. Then total_files,\nreviewed_files, skipped_files\
    \ with reasons, coverage_rate, and the\nfindings by severity with disposition (fixed in <sha> | rejected:\n\
    reason). A preview or rule command that fails is a node failure\nnaming the error, never a review\
    \ without OCR.\n"
  success_check:
    marker: 'OCR-REVIEW: done'
  max_retries: 1
  outputs:
    extract: node_output
- id: final_gates
  title: QA and architecture gates again after the review
  type: script
  script: scripts/final-gates.sh
  runner: sh
  timeout_seconds: 4500
  expected_duration: 27m
- id: final_check
  title: Final gate verdict
  type: condition
  max_loops: 3
- id: final_fix
  title: Fix the red final gates
  type: agent_task
  expected_duration: 40m
  prompt: 'Standing brief: {{params.brief}}

    Commit trailer: {{params.commit_trailer}}

    Gate output: {{nodes.final_gates.output}}

    Review summary: {{nodes.ocr_review.output}}


    The QA or the architecture gate turned red after the OpenCodeReview

    pass. Make every red gate green in the branch without undoing a

    confirmed review 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. The script node runs both gates again after

    you.


    Wrap ONLY the result in <node_output> and </node_output>: each red

    gate, the cause, and the fix commit.

    '
  outputs:
    extract: node_output
- id: push_pr
  title: Push and open (or update) the PR
  type: agent_task
  expected_duration: 25m
  prompt: "Standing brief: {{params.brief}}\nPR footer (the exact last line of the description): {{params.pr_footer}}\n\
    Context: {{nodes.intake.output}}\nReview summary: {{nodes.self_review.output}}\nOpenCodeReview summary:\
    \ {{nodes.ocr_review.output}}\nDocs and version: {{nodes.docs_version.output}}\n\n1. Push. If the\
    \ diff against origin/<base> touches .github/workflows/,\n   push over SSH so no token scope can refuse\
    \ it:\n   `git push [email protected]:itechmeat/open-second-brain.git HEAD:refs/heads/<branch>`\n   then\
    \ `git branch --set-upstream-to=origin/<branch>` after a\n   `git fetch origin <branch>`; otherwise\
    \ `git push -u origin <branch>`.\n   Never push to the base, never force-push commits you did not\
    \ write.\n2. PR text, in the voice of the recent PRs (`gh pr view 193` and\n   `gh pr view 191` are\
    \ the reference): title as a conventional\n   summary, with ` (vX.Y.Z)` appended when the PR ships\
    \ a release\n   (`feat: <capability tagline> (v1.58.0)`, `fix(<scope>): ... (v1.57.2)`).\n   Body:\
    \ Summary (capability-first), a mermaid diagram of the\n   process-level benefit (required when the\
    \ PR ships a release,\n   optional otherwise), What changed, Verification (the gates that\n   ran,\
    \ with counts; when the diff against origin/<base> exceeds\n   100 files, one line naming the bot\
    \ review as skipped, since\n   CodeRabbit skips a change set over its 100-file limit), and\n   `Closes\
    \ #N` / `Refs #N` for the GitHub issues in the context.\n   Kanban card ids stay out of the public\
    \ text. Security fixes in\n   neutral terms only. When the PR footer above is non-empty, the\n   description\
    \ ends with it verbatim; when it is empty, the\n   description carries no footer and no AI-authorship\
    \ marker.\n3. Mermaid: try a local parse first when it runs here\n   (`bunx -p @mermaid-js/mermaid-cli\
    \ mmdc -i <file>.mmd -o <file>.svg`;\n   agent-browser's Chrome can serve as PUPPETEER_EXECUTABLE_PATH).\n\
    \   The check that counts is the PR page: once the PR exists, open it\n   with agent-browser and confirm\
    \ the diagram rendered as a diagram\n   (no \"Unable to render rich display\" box). Fix and\n   `gh\
    \ pr edit --body-file` until it does.\n4. Open or update: if an open PR for this branch exists\n \
    \  (`gh pr view --json number,state`), update its title and body;\n   else `gh pr create --base <base>\
    \ --head <branch> --title ...\n   --body-file ...`. Never `gh pr merge`, never `--auto`.\n5. Record\
    \ `OSB_PR_NUMBER=<n>` and `OSB_PR_URL=<url>` in\n   <git-dir>/osb-pr-prepare/pr.env.\n\nWrap ONLY\
    \ the result in <node_output> and </node_output>. Required\nfirst line: `PR: #<number> <url>`. Then\
    \ the pushed head sha and the\nmermaid evidence (local render, and what the PR page showed).\n"
  success_check: scripts/check-pr.sh
  max_retries: 2
  outputs:
    extract: node_output
- id: ci_wait
  title: Wait for CI (one blocking watch)
  type: script
  script: scripts/ci-wait.sh
  runner: sh
  timeout_seconds: 6600
  expected_duration: 35m
- id: ci_wait_final
  title: Wait for CI after the budget-capped bot review pass
  type: script
  script: scripts/ci-wait.sh
  runner: sh
  timeout_seconds: 6600
  expected_duration: 35m
- id: ci_check
  title: CI verdict
  type: condition
  max_loops: 4
- id: ci_fix
  title: Fix the red CI checks and push
  type: agent_task
  expected_duration: 40m
  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, commit per the brief and push the same way push_pr did

    (SSH when .github/workflows/ changed). 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, and the fix commit or the rerun.

    '
  success_check: scripts/check-pr.sh
  outputs:
    extract: node_output
- id: bot_review
  title: Handle the bot review (CodeRabbit)
  type: agent_task
  expected_duration: 30m
  prompt: "Standing brief: {{params.brief}}\nCommit trailer: {{params.commit_trailer}}\nPR: read the number\
    \ from <git-dir>/osb-pr-prepare/pr.env.\n\nThis node starts IMMEDIATELY after the push, while CI is\
    \ still running.\nDo not wait for the checks to conclude and do not watch them; the\nci_wait node\
    \ after you waits for the checks. Start the review work now.\n\nFirst wait for CodeRabbit's review\
    \ to be POSTED: it usually arrives\nminutes after the push, long before the checks end. Poll\n`gh\
    \ api repos/<owner>/<repo>/pulls/<n>/reviews` and\n`.../pulls/<n>/comments` in one blocking loop (sleep\
    \ 60 between calls,\nat most 10 minutes), then read what it said: `gh pr view <n>\n--comments`. If\
    \ no CodeRabbit review appears in that window, say so in\nthe reply and continue. Handle only comments\
    \ you have not already\nanswered in an earlier pass of this node.\n\nThe operator may hand external\
    \ review documents to the orchestrator\nmid-wave (paths under .reviews/ or pasted text). When this\
    \ task's\nresponse carries them, treat every finding in them exactly like a\nCodeRabbit finding: verify\
    \ against the current code, then fix or\nanswer. Such findings are worked on immediately, never held\
    \ back for\nCI.\n\n- Skipped (for example \"files exceed the limit\"): post one PR\n  comment saying\
    \ which internal review compensated (the\n  self-review, test-audit, security review and OpenCodeReview\
    \ pass\n  of this run), in neutral terms.\n- Each finding: verify it against the current code with\
    \ the\n  receiving-code-review discipline. Valid: fix with the smallest\n  diff. Not valid or no longer\
    \ applicable: reply on the thread with\n  a one-sentence technical reason. Valid fixes get a reply\
    \ naming\n  the commit.\n- Commit fixes per the brief (for example `fix: address CodeRabbit\n  review\
    \ feedback`) and push the same way push_pr did. A push here\n  restarts CI; that is expected, because\
    \ the ci_wait node after you\n  waits for the new run.\nOne pass per call; do not wait for a second\
    \ bot pass.\n\nWrite your verdict to $APB_STATUS_FILE with outputs\n{pushed: \"yes\" if you pushed\
    \ commits, else \"no\", findings: <count>,\nfixed: [shas], answered: <count>, skipped_reason: <text\
    \ or \"\">}."
  success_check: scripts/check-pr.sh
  max_retries: 1
- id: ready
  type: finish
  outcome: success
  expected_duration: 3m
  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 self-review, the

    test-audit, the security review (only "clean" or the count of fixed

    items and advisory drafts, never details), the architecture gate,

    the OpenCodeReview pass (coverage, confirmed and fixed counts) 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, advisory drafts to publish, the merge

    itself. Plain text, English.

    '
- id: blocked
  type: finish
  outcome: failure
  expected_duration: 3m
  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.

    '
edges:
- from: start
  to: intake
- from: intake
  to: zg_index
- from: zg_index
  to: self_review
  condition:
    type: node_status
    node: zg_index
    equals: success
- from: zg_index
  to: self_review
  condition:
    type: node_status
    node: zg_index
    equals: failure
- from: self_review
  to: test_audit
- from: test_audit
  to: security_review
- from: security_review
  to: docs_version
- from: docs_version
  to: qa_gates
- from: qa_gates
  to: qa_check
- from: qa_check
  to: arch_gate
  condition:
    type: node_status
    node: qa_gates
    equals: success
- from: qa_check
  to: qa_fix
  condition:
    type: output_match
    node: qa_gates
    pattern: 'QA-GATE: red'
- from: qa_check
  to: blocked
  fallback: true
- from: qa_fix
  to: qa_gates
- from: arch_gate
  to: arch_check
- from: arch_check
  to: ocr_review
  condition:
    type: node_status
    node: arch_gate
    equals: success
- from: arch_check
  to: arch_fix
  condition:
    type: output_match
    node: arch_gate
    pattern: 'ARCH-GATE: violations'
- from: arch_check
  to: blocked
  fallback: true
- from: arch_fix
  to: arch_gate
- from: ocr_review
  to: final_gates
- from: final_gates
  to: final_check
- from: final_check
  to: push_pr
  condition:
    type: node_status
    node: final_gates
    equals: success
- from: final_check
  to: final_fix
  condition:
    type: output_match
    node: final_gates
    pattern: 'FINAL-GATES: red'
- from: final_check
  to: blocked
  fallback: true
- from: final_fix
  to: final_gates
- from: push_pr
  to: bot_review
- from: ci_wait
  to: ci_check
- from: ci_check
  to: ci_fix
  condition:
    type: output_match
    node: ci_wait
    pattern: 'CI-GATE: red'
- from: ci_check
  to: blocked
  condition:
    type: node_status
    node: ci_wait
    equals: failure
- from: ci_check
  to: bot_review
  condition:
    type: output_field
    node: bot_review
    field: pushed
    equals: 'yes'
- from: ci_check
  to: ready
  condition:
    type: output_field
    node: bot_review
    field: pushed
    equals: 'no'
- from: ci_check
  to: blocked
  fallback: true
- from: ci_fix
  to: ci_wait
- from: bot_review
  to: ci_wait
  max_traversals: 2
- from: bot_review
  to: ci_wait_final
  fallback: true
- from: ci_wait_final
  to: ready
  condition:
    type: node_status
    node: ci_wait_final
    equals: success
- from: ci_wait_final
  to: blocked
  fallback: true