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
chore(apb): run the owner dev quality cycle in osb-pr-prepare (#265)
Serg Eroshe63410769dafc
diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/playbook.yaml b/.apb/playbooks/osb-pr-prepare/1.4.0/playbook.yamlnew file mode 100644index 00000000..f1f7a4c5--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/playbook.yaml@@ -0,0 +1,990 @@+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.0+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 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 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. 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 query --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, 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.+ 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 to be POSTED: it usually arrives+ minutes after the push, long before the checks end. Poll+ `gh api repos/<owner>/<repo>/pulls/<n>/reviews` and+ `.../pulls/<n>/comments` in one blocking loop (sleep 60 between calls,+ at most 10 minutes), then read what it said: `gh pr view <n>+ --comments`. If no CodeRabbit review 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. Push only when that is 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: ci_wait+ 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: nulldiff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/arch-gate.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/arch-gate.shnew file mode 100755index 00000000..3afdba90--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/arch-gate.sh@@ -0,0 +1,51 @@+#!/bin/sh+# Architecture gate: code-ranker in baseline mode. The merge base with+# origin/<base> is analyzed as the baseline and the committed HEAD as the+# candidate (both from `git archive`, so untracked files and local tool+# directories never enter the graph); only violations the branch introduces+# fail the gate. Pre-existing debt on the base is not this PR's to fix.+#+# Exit 0: no new violation. Exit 1: new violations (the output starts with+# `ARCH-GATE: violations`, followed by code-ranker's fix prompt). Exit 2: the+# tool itself failed (`ERROR:`), which no code change in the branch can fix.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -euo pipefail+. "$(dirname "$0")/lib.sh"++root=$(repo_root)+cd "$root"+load_ctx+command -v code-ranker >/dev/null 2>&1 || die "code-ranker is not on PATH"++mb=$(git merge-base "origin/$OSB_BASE" HEAD) || die "no merge base with origin/$OSB_BASE"+work=$(mktemp -d "${TMPDIR:-/tmp}/osb-arch-gate.XXXXXX")+trap 'rm -rf "$work"' EXIT+mkdir -p "$work/base" "$work/head"+git archive "$mb" | tar -x -C "$work/base"+git archive HEAD | tar -x -C "$work/head"++# Explicit plugins so base and head are analyzed with the same languages.+plugins=(--plugins ts --plugins python --plugins md)+cd "$work" # code-ranker writes its default HTML viewer under the cwd+code-ranker report base "${plugins[@]}" --output.mode quiet \+ --output.json.path "$work/base.json" --output.html.path "$work/base.html" >/dev/null 2>"$work/report.err" ||+ die "code-ranker report on the merge base failed: $(cat "$work/report.err")"++set +e+code-ranker check head "${plugins[@]}" --baseline "$work/base.json" \+ --output-format prompt --output.mode summary >"$work/check.out" 2>&1+rc=$?+set -e++if [ "$rc" -eq 0 ]; then+ cat "$work/check.out"+ echo "ARCH-GATE: pass (no new violation against $mb)"+ exit 0+fi+if grep -q 'new violation(s) vs baseline' "$work/check.out"; then+ echo "ARCH-GATE: violations (new against merge base $mb)"+ sed "s#$work/##g" "$work/check.out"+ exit 1+fi+cat "$work/check.out"+die "code-ranker check failed without a violation verdict (exit $rc)"diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-context.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-context.shnew file mode 100755index 00000000..cba70848--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-context.sh@@ -0,0 +1,24 @@+#!/bin/sh+# success_check of `intake`: the recorded PR context is complete and true.+# apb runs every script through `sh`; re-exec under bash for pipefail.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -euo pipefail+. "$(dirname "$0")/lib.sh"++cd "$(repo_root)"+load_ctx++case " $OSB_KINDS " in *" $OSB_KIND "*) ;; *) die "OSB_KIND=$OSB_KIND is not one of: $OSB_KINDS" ;; esac+case " $OSB_RELEASES " in *" $OSB_RELEASE "*) ;; *) die "OSB_RELEASE=$OSB_RELEASE is not one of: $OSB_RELEASES" ;; esac++branch=$(git symbolic-ref --quiet --short HEAD) || die "HEAD is detached; the PR needs a branch"+[ "$branch" = "$OSB_BRANCH" ] || die "checked-out branch $branch differs from OSB_BRANCH=$OSB_BRANCH"+[ "$branch" != "$OSB_BASE" ] || die "the PR branch is the base branch $OSB_BASE"+git rev-parse --verify --quiet "origin/$OSB_BASE" >/dev/null || die "origin/$OSB_BASE does not exist; fetch it"+mb=$(git merge-base "origin/$OSB_BASE" HEAD) || die "no merge base between origin/$OSB_BASE and HEAD"+git diff --quiet "$mb" HEAD && die "the branch carries no change against origin/$OSB_BASE"+git diff --quiet || die "tracked files have unstaged changes; the intake commits the implementation first"+git diff --cached --quiet || die "the index holds staged, uncommitted changes"++echo "context ok: kind=$OSB_KIND release=$OSB_RELEASE base=$OSB_BASE branch=$OSB_BRANCH merge-base=$mb"+echo "commits: $(git rev-list --count "$mb"..HEAD), files: $(git diff --name-only "$mb" HEAD | wc -l)"diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-pr.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-pr.shnew file mode 100755index 00000000..2450e8be--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-pr.sh@@ -0,0 +1,27 @@+#!/bin/sh+# success_check of `push_pr` (and of the fix nodes that push): the PR recorded+# in pr.env is open, not merged, targets the base branch, and its head is+# exactly the local HEAD, which the remote branch also carries.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -euo pipefail+. "$(dirname "$0")/lib.sh"++cd "$(repo_root)"+load_ctx+load_pr++head=$(git rev-parse HEAD)+git diff --quiet && git diff --cached --quiet || die "uncommitted tracked changes: commit and push them"+remote=$(git ls-remote origin "refs/heads/$OSB_BRANCH" | cut -f1)+[ "$remote" = "$head" ] || die "origin/$OSB_BRANCH is '${remote:-absent}', local HEAD is $head: push"++info=$(gh pr view "$OSB_PR_NUMBER" --json state,headRefOid,baseRefName,headRefName,url \+ -q '[.state,.headRefOid,.baseRefName,.headRefName,.url]|@tsv') || die "gh pr view $OSB_PR_NUMBER failed"+IFS=$'\t' read -r state pr_head pr_base pr_branch url <<<"$info"+[ "$state" = OPEN ] || die "PR #$OSB_PR_NUMBER is $state, expected OPEN (this playbook never merges)"+[ "$pr_base" = "$OSB_BASE" ] || die "PR #$OSB_PR_NUMBER targets $pr_base, expected $OSB_BASE"+[ "$pr_branch" = "$OSB_BRANCH" ] || die "PR #$OSB_PR_NUMBER is from $pr_branch, expected $OSB_BRANCH"+[ "$pr_head" = "$head" ] || die "PR #$OSB_PR_NUMBER head is $pr_head, local HEAD is $head"+auto=$(gh pr view "$OSB_PR_NUMBER" --json autoMergeRequest -q '.autoMergeRequest != null')+[ "$auto" = false ] || die "PR #$OSB_PR_NUMBER has auto-merge armed; merging is the operator's call: gh pr merge --disable-auto $OSB_PR_NUMBER"+echo "PR ok: #$OSB_PR_NUMBER $url open on $OSB_BASE at $head"diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-release.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-release.shnew file mode 100755index 00000000..819e85e7--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/check-release.sh@@ -0,0 +1,55 @@+#!/bin/sh+# success_check of `docs_version`: the version and CHANGELOG state match what+# the change kind decided (CLAUDE.md "Versioning").+#+# Release-bearing PR (OSB_RELEASE major|minor|patch):+# - package.json carries the expected bump of the base version;+# - the first `## [` heading of CHANGELOG.md is `## [X.Y.Z] - YYYY-MM-DD`+# (no `[Unreleased]` left above it);+# - the `[X.Y.Z]: .../compare/vPREV...vX.Y.Z` link reference exists;+# - `sync-version --check` passes and everything is committed.+# No-release PR (OSB_RELEASE none): package.json still carries the base version.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -euo pipefail+. "$(dirname "$0")/lib.sh"++cd "$(repo_root)"+load_ctx++prev=$(git show "origin/$OSB_BASE:package.json" | json_version)+now=$(json_version <package.json)++if [ "$OSB_RELEASE" = none ]; then+ [ "$now" = "$prev" ] || die "kind $OSB_KIND ships no release, but package.json moved $prev -> $now"+ base_first=$(git show "origin/$OSB_BASE:CHANGELOG.md" | grep -m1 -E '^## \[' || true)+ head_first=$(grep -m1 -E '^## \[' CHANGELOG.md || true)+ [ "$head_first" = "$base_first" ] ||+ die "kind $OSB_KIND ships no release, but the first CHANGELOG heading moved '$base_first' -> '$head_first'"+ echo "release check ok: no release, version stays $now"+ exit 0+fi++expected=$(python3 - "$prev" "$OSB_RELEASE" <<'PY'+import sys+major, minor, patch = (int(p) for p in sys.argv[1].split("."))+bump = sys.argv[2]+if bump == "major":+ major, minor, patch = major + 1, 0, 0+elif bump == "minor":+ minor, patch = minor + 1, 0+else:+ patch += 1+print(f"{major}.{minor}.{patch}")+PY+)+[ "$now" = "$expected" ] || die "package.json is $now; a $OSB_RELEASE bump of $prev is $expected"++first=$(grep -m1 -E '^## \[' CHANGELOG.md || true)+printf '%s\n' "$first" | grep -qE "^## \[$expected\] - [0-9]{4}-[0-9]{2}-[0-9]{2}\$" ||+ die "the first CHANGELOG heading is '$first', expected '## [$expected] - <date>'"+grep -qE "^\[$expected\]: https://github\.com/itechmeat/open-second-brain/compare/v$prev\.\.\.v$expected\$" CHANGELOG.md ||+ die "CHANGELOG.md lacks the link reference [$expected]: https://github.com/itechmeat/open-second-brain/compare/v$prev...v$expected"++bun run scripts/sync-version.ts --check >/dev/null 2>&1 || die "sync-version --check fails: run bun run scripts/sync-version.ts"+git diff --quiet && git diff --cached --quiet || die "version or CHANGELOG changes are not committed"+echo "release check ok: $prev -> $expected ($OSB_RELEASE), CHANGELOG heading and link reference present"diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/ci-wait.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/ci-wait.shnew file mode 100755index 00000000..131add6e--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/ci-wait.sh@@ -0,0 +1,69 @@+#!/bin/sh+# Waits for the PR's checks on the current head with ONE blocking command,+# `gh pr checks --watch` (no polling loop of our own), then prints the verdict.+# The checks include CodeRabbit's status, so a green result also means the bot+# review has finished (or was skipped).+#+# The watch runs WITHOUT --fail-fast: the verdict waits until every check has a+# terminal state. A fast failure (a scan failing in seconds) must not start the+# fix round while a slow job (windows) is still running, or a late failure of+# that job needs a second fix round. The red verdict lists every failed check.+#+# Before the watch, the script makes sure the CI workflow run for THIS head+# commit exists. Right after a push, `gh pr checks` can still show the previous+# commit's finished checks and would return at once with a stale verdict. That+# registration wait is bounded (REGISTRATION_TRIES x REGISTRATION_SLEEP) and+# ends as soon as GitHub lists the run.+#+# Exit 0 green, 1 red (failed-job logs follow), 2 setup error.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -euo pipefail+. "$(dirname "$0")/lib.sh"++REGISTRATION_TRIES=18+REGISTRATION_SLEEP=10+WATCH_TIMEOUT=6000 # the windows job alone has taken 45 minutes on a slow runner+WATCH_INTERVAL=60 # gh's own refresh period while it blocks+LOG_TAIL=250+CI_WORKFLOW=ci.yml++cd "$(repo_root)"+load_ctx+load_pr++head=$(git rev-parse HEAD)+pr_head=$(gh pr view "$OSB_PR_NUMBER" --json headRefOid -q .headRefOid)+[ "$pr_head" = "$head" ] || die "PR #$OSB_PR_NUMBER head $pr_head is not local HEAD $head: push first"++run_id=""+for _ in $(seq "$REGISTRATION_TRIES"); do+ run_id=$(gh run list --commit "$head" --workflow "$CI_WORKFLOW" --limit 1 --json databaseId -q '.[0].databaseId // empty')+ [ -n "$run_id" ] && break+ sleep "$REGISTRATION_SLEEP"+done+[ -n "$run_id" ] || die "no $CI_WORKFLOW run registered for $head after $((REGISTRATION_TRIES * REGISTRATION_SLEEP))s"++set +e+timeout "$WATCH_TIMEOUT" gh pr checks "$OSB_PR_NUMBER" --watch --interval "$WATCH_INTERVAL" >/dev/null 2>&1+rc=$?+set -e+echo "checks for PR #$OSB_PR_NUMBER at $head (CI run $run_id):"+gh pr checks "$OSB_PR_NUMBER" 2>&1 || true++if [ "$rc" -eq 0 ]; then+ echo "CI-GATE: green"+ exit 0+fi+if [ "$rc" -eq 124 ]; then+ echo "CI-GATE: red (checks still pending after ${WATCH_TIMEOUT}s)"+ exit 1+fi+failed=$(gh pr checks "$OSB_PR_NUMBER" --json name,bucket -q '[.[] | select(.bucket == "fail" or .bucket == "cancel") | .name] | join(", ")' 2>/dev/null || true)+echo "CI-GATE: red (failed: ${failed:-the check list could not be read, see the checks above})"+# Per failed job, not `--log-failed` on the run: the job logs stay readable+# even when another workflow run on the same head is still in progress.+for job in $(gh run view "$run_id" --json jobs -q '.jobs[] | select(.conclusion == "failure") | .databaseId'); do+ echo "--- failed job $job of run $run_id (log tail) ---"+ gh run view --job "$job" --log 2>&1 | tail -n "$LOG_TAIL" || true+done+exit 1diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/cycle-run.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/cycle-run.shnew file mode 100755index 00000000..d663d369--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/cycle-run.sh@@ -0,0 +1,65 @@+#!/bin/sh+# Steps 1-3 of the dev quality cycle (skill dev-quality-cycle): OpenCodeReview+# on the claude-code provider, the read-only Codex review and Claude Code's+# /security-review, through the skill's own runner `scripts/cycle.sh`. The+# skill owns the commands, flags, effort levels and failure detection; this+# script only picks the range and records where the run folder is.+#+# Range: what the cycle has not reviewed yet, never what was merely pushed. The+# cycle_review and final_fix nodes record the head the cycle reviewed in+# <git-dir>/osb-pr-prepare/cycle-reviewed as "<branch> <sha>". When that record+# names this branch and its sha is an ancestor of HEAD, the range is <sha>..HEAD;+# otherwise it is the whole branch against origin/<base>. The runner exits 4+# when the range is empty (HEAD already reviewed).+#+# The skill lives in $DEV_QUALITY_CYCLE_DIR, default ~/.agents/skills/dev-quality-cycle.+#+# Output: the runner's log, then one marker line+# `CYCLE-RUN: ok|failed|resumable|nothing-new exit=<n> summary=<path>`+# Exit 0 for every marker: the cycle_review node reads the outputs and decides.+# Exit 2: setup error (`ERROR:`), which no code change can fix.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -uo pipefail+. "$(dirname "$0")/lib.sh"++cd "$(repo_root)"+load_ctx++skill="${DEV_QUALITY_CYCLE_DIR:-$HOME/.agents/skills/dev-quality-cycle}"+runner="$skill/scripts/cycle.sh"+[ -x "$runner" ] || die "the dev-quality-cycle skill runner is missing: $runner"++git rev-parse -q --verify "origin/$OSB_BASE^{commit}" >/dev/null ||+ die "origin/$OSB_BASE is unknown: fetch it first"+range_args=(--base "origin/$OSB_BASE")+reviewed_file="$CTX_DIR/cycle-reviewed"+if [ -s "$reviewed_file" ]; then+ read -r reviewed_branch reviewed_sha <"$reviewed_file"+ if [ "$reviewed_branch" = "$OSB_BRANCH" ] && [ -n "${reviewed_sha:-}" ] &&+ git merge-base --is-ancestor "$reviewed_sha" HEAD 2>/dev/null; then+ range_args=(--range "$reviewed_sha..HEAD")+ fi+fi++# What the change is for: OCR --background-file and the Codex prompt.+intent="$CTX_DIR/cycle-intent.md"+{+ printf 'Open Second Brain change of kind %s on branch %s against %s.\n' "$OSB_KIND" "$OSB_BRANCH" "$OSB_BASE"+ printf 'Commits:\n'+ git log --no-merges --format='- %s' "origin/$OSB_BASE..HEAD"+} >"$intent"++log="$CTX_DIR/cycle-run.log"+"$runner" "${range_args[@]}" --context-file "$intent" --exclude 'bun.lock,uv.lock' . >"$log" 2>&1+rc=$?+cat "$log"+summary=$(sed -n 's/^Summary: //p' "$log" | tail -1)+case "$rc" in+ 0) status=ok ;;+ 1) status=failed ;;+ 3) status=resumable ;;+ 4) status=nothing-new ;;+ *) die "the cycle runner exited $rc (usage or setup error); see $log" ;;+esac+echo "CYCLE-RUN: $status exit=$rc summary=${summary:-none}"+exit 0diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/final-gates.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/final-gates.shnew file mode 100755index 00000000..70e51eb3--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/final-gates.sh@@ -0,0 +1,43 @@+#!/bin/sh+# Final gates before the push: the QA gates (qa-gates.sh) and the+# architecture gate (arch-gate.sh) again, after the OpenCodeReview pass may+# have committed fixes. When HEAD is still the commit the QA gates last+# passed on, nothing changed since the green QA and architecture gates (the+# architecture gate runs after the QA gates and any fix it needed moves+# HEAD), so the re-run is skipped.+#+# Exit 0: both green, or skipped (`FINAL-GATES: pass`). Exit 1: a red gate+# (`FINAL-GATES: red`, followed by the markers and output of the red gates).+# Exit 2: a setup or tool error (`ERROR:`), which no code change can fix.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -uo pipefail+here=$(dirname "$0")+. "$here/lib.sh"++cd "$(repo_root)"+load_ctx++head=$(git rev-parse HEAD)+green="$CTX_DIR/qa-green-head"+if [ -f "$green" ] && [ "$(cat "$green")" = "$head" ]; then+ echo "FINAL-GATES: pass (HEAD $head unchanged since the green QA and architecture gates)"+ exit 0+fi++qa_out=$(sh "$here/qa-gates.sh" 2>&1)+qa_rc=$?+arch_out=$(sh "$here/arch-gate.sh" 2>&1)+arch_rc=$?++if [ "$qa_rc" -eq 0 ] && [ "$arch_rc" -eq 0 ]; then+ printf '%s\n%s\n' "$qa_out" "$arch_out"+ echo "FINAL-GATES: pass (QA and architecture gates green at $head)"+ exit 0+fi+if [ "$qa_rc" -eq 2 ] || [ "$arch_rc" -eq 2 ]; then+ printf '%s\n%s\n' "$qa_out" "$arch_out"+ die "a gate could not run (qa exit $qa_rc, arch exit $arch_rc)"+fi+echo "FINAL-GATES: red (qa exit $qa_rc, arch exit $arch_rc)"+printf '%s\n%s\n' "$qa_out" "$arch_out"+exit 1diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/lib.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/lib.shnew file mode 100755index 00000000..287d0c71--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/lib.sh@@ -0,0 +1,95 @@+# Shared helpers for the osb-pr-prepare script nodes. Sourced, never run.+#+# apb hands a script node no parameters and no environment of its own, so the+# per-run facts (base branch, change kind, release bump, PR number) travel in+# files under the repository's git directory, which git never tracks:+#+# $(git rev-parse --git-path osb-pr-prepare)/context.env written by `intake`+# $(git rev-parse --git-path osb-pr-prepare)/pr.env written by `push_pr`+# $(git rev-parse --git-path osb-pr-prepare)/known-test-failures.txt+# written by `qa_fix`+#+# A missing file is an explicit error naming the node that should have written+# it, never a silent default.++# The CI toolchain pin (.github/workflows/ci.yml, `bun-version`).+OSB_CI_BUN_VERSION=1.4.0+# The CI Python pin (.github/workflows/ci.yml, `python-version`).+OSB_CI_PYTHON_VERSION=3.11+# The only local embedding model the zg index uses: no remote provider, no key.+OSB_ZG_MODEL=local/potion-code-16m-v2+OSB_KINDS="feature fix refactor chore docs deps"+OSB_RELEASES="major minor patch none"++die() {+ printf 'ERROR: %s\n' "$*"+ exit 2+}++repo_root() {+ git rev-parse --show-toplevel 2>/dev/null || die "not inside a git work tree"+}++ctx_dir() {+ git rev-parse --path-format=absolute --git-path osb-pr-prepare+}++load_ctx() {+ CTX_DIR=$(ctx_dir)+ [ -f "$CTX_DIR/context.env" ] ||+ die "$CTX_DIR/context.env is missing: the intake node did not record the PR context"+ # shellcheck disable=SC1091+ . "$CTX_DIR/context.env"+ for v in OSB_BASE OSB_KIND OSB_RELEASE OSB_BRANCH; do+ eval "val=\${$v:-}"+ [ -n "$val" ] || die "$v is not set in $CTX_DIR/context.env"+ done+}++load_pr() {+ [ -f "$CTX_DIR/pr.env" ] ||+ die "$CTX_DIR/pr.env is missing: the push_pr node did not record the PR number"+ # shellcheck disable=SC1091+ . "$CTX_DIR/pr.env"+ [ -n "${OSB_PR_NUMBER:-}" ] || die "OSB_PR_NUMBER is not set in $CTX_DIR/pr.env"+}++json_version() {+ # Reads the "version" field of a package.json given on stdin.+ python3 -c 'import json,sys; print(json.load(sys.stdin)["version"])'+}++# Puts the CI-pinned Bun first on PATH. The Linux release zip is cached under+# ~/.cache/osb-pr-prepare; the download happens once and needs no sudo. Local+# Bun (1.4.x newer than the pin) bundles openclaw/index.js differently, so the+# bundle-in-sync gate is only meaningful with the pinned build.+use_ci_bun() {+ cache="${XDG_CACHE_HOME:-$HOME/.cache}/osb-pr-prepare/bun-$OSB_CI_BUN_VERSION"+ case "$(uname -m)" in+ x86_64) asset=bun-linux-x64 ;;+ aarch64 | arm64) asset=bun-linux-aarch64 ;;+ *) die "no Bun $OSB_CI_BUN_VERSION release asset known for $(uname -m)" ;;+ esac+ bin="$cache/$asset/bun"+ if [ ! -x "$bin" ]; then+ mkdir -p "$cache"+ url="https://github.com/oven-sh/bun/releases/download/bun-v$OSB_CI_BUN_VERSION/$asset.zip"+ curl -fsSL -o "$cache/$asset.zip" "$url" || die "download failed: $url"+ python3 -m zipfile -e "$cache/$asset.zip" "$cache" || die "unzip failed: $cache/$asset.zip"+ chmod +x "$bin"+ fi+ got=$("$bin" --version) || die "cached Bun at $bin does not run"+ [ "$got" = "$OSB_CI_BUN_VERSION" ] || die "cached Bun at $bin reports $got, expected $OSB_CI_BUN_VERSION"+ PATH="$(dirname "$bin"):$PATH"+ export PATH+}++# Prints the interpreter path of the CI-pinned Python, installing it through uv+# (user-level, no sudo) when missing.+ci_python() {+ command -v uv >/dev/null 2>&1 || die "uv is not on PATH; it provides Python $OSB_CI_PYTHON_VERSION"+ uv python find "$OSB_CI_PYTHON_VERSION" 2>/dev/null && return 0+ uv python install "$OSB_CI_PYTHON_VERSION" >/dev/null 2>&1 ||+ die "uv could not install Python $OSB_CI_PYTHON_VERSION"+ uv python find "$OSB_CI_PYTHON_VERSION"+}diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/qa-gates.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/qa-gates.shnew file mode 100755index 00000000..dc1c6d66--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/qa-gates.sh@@ -0,0 +1,132 @@+#!/bin/sh+# Open Second Brain's own QA gates, as the CI `validate` job runs them+# (.github/workflows/ci.yml), in the same order and with the same toolchain+# pins: Bun 1.4.0 (cached release binary) and Python 3.11 (uv). Every step+# runs even after a failure, so one pass shows the whole picture; the full+# log of each step lands in <git-dir>/osb-pr-prepare/qa-logs/<step>.log and+# only the tail of a failing step is printed.+#+# Known environment-only test failures: a test named in+# <git-dir>/osb-pr-prepare/known-test-failures.txt (one exact `bun test` name+# per line) does not fail the gate. Only `qa_fix` adds a name there, and only+# after proving the same test fails on the merge base in this environment.+#+# On green, the tested HEAD is recorded in <git-dir>/osb-pr-prepare/qa-green-head+# for final-gates.sh.+#+# The CI `windows` job cannot run here; CI covers it after the push.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -uo pipefail+. "$(dirname "$0")/lib.sh"++root=$(repo_root)+cd "$root"+load_ctx+command -v bun >/dev/null 2>&1 || die "bun is not on PATH"+use_ci_bun+py=$(ci_python) || exit 2++logs="$CTX_DIR/qa-logs"+rm -rf "$logs"+mkdir -p "$logs"+known="$CTX_DIR/known-test-failures.txt"+test_home=$(mktemp -d "${TMPDIR:-/tmp}/osb-qa-home.XXXXXX")+bundle=$(mktemp "${TMPDIR:-/tmp}/osb-openclaw-rebuild.XXXXXX.js")+trap 'rm -rf "$test_home" "$bundle"' EXIT+TAIL_LINES=80+failed=()++step() {+ # step <name> <command...>: runs one gate, records PASS/FAIL.+ name=$1+ shift+ if "$@" >"$logs/$name.log" 2>&1; then+ echo "PASS $name"+ else+ echo "FAIL $name (log: $logs/$name.log)"+ tail -n "$TAIL_LINES" "$logs/$name.log" | sed 's/^/ /'+ failed+=("$name")+ fi+}++report_only() {+ name=$1+ shift+ "$@" >"$logs/$name.log" 2>&1+ echo "INFO $name (report-only, exit $?; log: $logs/$name.log)"+}++openclaw_bundle_in_sync() {+ bun build src/openclaw/index.ts --outfile "$bundle" --target=node --format=esm \+ --external openclaw/plugin-sdk/plugin-entry &&+ diff -q "$bundle" openclaw/index.js+}++bun_test() {+ # Throwaway HOME, as the project's test discipline requires.+ HOME="$test_home" bun test >"$logs/bun-test.raw" 2>&1+ rc=$?+ cat "$logs/bun-test.raw"+ [ "$rc" -eq 0 ] && return 0+ sed -n 's/^(fail) \(.*\) \[[0-9.]*m\{0,1\}s\]$/\1/p; t; s/^(fail) \(.*\)$/\1/p' "$logs/bun-test.raw" |+ LC_ALL=C sort -u >"$logs/bun-test.failed"+ [ -s "$logs/bun-test.failed" ] || {+ echo "bun test exited $rc without a (fail) line: a crash, not a test failure"+ return 1+ }+ if [ -f "$known" ]; then+ unknown=$(LC_ALL=C sort -u "$known" | LC_ALL=C comm -23 "$logs/bun-test.failed" -)+ else+ unknown=$(cat "$logs/bun-test.failed")+ fi+ if [ -z "$unknown" ]; then+ echo "only known environment-only failures failed:"+ sed 's/^/ known: /' "$logs/bun-test.failed"+ return 0+ fi+ echo "failing tests not on the known list:"+ printf '%s\n' "$unknown" | sed 's/^/ /'+ return 1+}++python_tests() {+ PATH="$root/scripts:$PATH" HOME="$test_home" "$py" -m unittest discover -s tests/python -v+}++anti_drift_ran() {+ (+ cd tests/python &&+ PATH="$root/scripts:$PATH" HOME="$test_home" "$py" -m unittest test_static_schemas -v >"$logs/anti-drift.raw" 2>&1+ cat "$logs/anti-drift.raw"+ grep -q "test_static_schemas_match_live_tools_list" "$logs/anti-drift.raw" || exit 1+ if grep -qE 'test_static_schemas_match_live_tools_list.* \.\.\. skipped' "$logs/anti-drift.raw"; then+ echo "anti-drift skipped itself; the live server was not reachable"+ exit 1+ fi+ )+}++echo "QA gates for $OSB_BRANCH ($(git rev-parse --short HEAD)), Bun $(bun --version), $("$py" --version)"+step install bun install --frozen-lockfile+step sync-version bun run sync-version:check+step sync-plugin-mirrors bun run sync-plugin-mirrors:check+step openclaw-bundle openclaw_bundle_in_sync+step link-ratchet bun run link-ratchet:check+report_only check-paths bun run check:paths+step fmt bun run fmt:check+step lint bun run lint+step typecheck bun run typecheck+step bun-test bun_test+step python-tests python_tests+step anti-drift anti_drift_ran+step python-compile "$py" -m compileall -q plugins/hermes+step hermes-scan bun run check:hermes-scan++if [ "${#failed[@]}" -eq 0 ]; then+ # final-gates.sh skips its re-run while HEAD is still this commit.+ git rev-parse HEAD >"$CTX_DIR/qa-green-head"+ echo "QA-GATE: green"+ exit 0+fi+echo "QA-GATE: red (${failed[*]})"+exit 1diff --git a/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/zg-index.sh b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/zg-index.shnew file mode 100755index 00000000..3236afa1--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/1.4.0/scripts/zg-index.sh@@ -0,0 +1,20 @@+#!/bin/sh+# Idempotent: makes sure the workspace has a ready zg (zvec-grep) index built+# with a LOCAL embedding model. A missing index is created, an existing one is+# refreshed incrementally and keeps its stored model (the env default only+# applies to a new index). No remote provider, no credential, no daemon+# (`--mode direct`). The index lives in <root>/.zvec-grep, which the repository+# .gitignore lists, so neither git nor oxfmt sees it.+[ -n "${BASH_VERSION:-}" ] || exec bash "$0" "$@"+set -euo pipefail+. "$(dirname "$0")/lib.sh"++cd "$(repo_root)"+command -v zg >/dev/null 2>&1 || die "zg is not on PATH"+git check-ignore -q .zvec-grep/ || die ".zvec-grep/ is not ignored: add it to the repository .gitignore"++export ZVEC_GREP_EMBEDDING="$OSB_ZG_MODEL"+export ZVEC_GREP_DEVICE=cpu+zg index --mode direct 2>&1+zg status --mode direct --check-ready 2>&1+echo "ZG-INDEX: ready"diff --git a/.apb/playbooks/osb-pr-prepare/current b/.apb/playbooks/osb-pr-prepare/currentindex 26aaba0e..e21e727f 100644--- a/.apb/playbooks/osb-pr-prepare/current+++ b/.apb/playbooks/osb-pr-prepare/current@@ -1 +1 @@-1.2.0+1.4.0\ No newline at end of filediff --git a/.apb/playbooks/osb-pr-prepare/meta/1.4.0.yaml b/.apb/playbooks/osb-pr-prepare/meta/1.4.0.yamlnew file mode 100644index 00000000..7b000642--- /dev/null+++ b/.apb/playbooks/osb-pr-prepare/meta/1.4.0.yaml@@ -0,0 +1,3 @@+created_by: user+run_id: null+classification: nulldiff --git a/.apb/profiles/osb-reviewer/profile.yaml b/.apb/profiles/osb-reviewer/profile.yamlindex 169829db..ade40906 100644--- a/.apb/profiles/osb-reviewer/profile.yaml+++ b/.apb/profiles/osb-reviewer/profile.yaml@@ -3,6 +3,7 @@ description: Code reviewer for Open Second Brain pull requests; runs OpenCodeRevexecutor:agent: claudemodel: claude-opus-5-5+ fallbacks: []soul: anyskills: []environment: fulldiff --git a/tests/cli/brain/verbs/storage.test.ts b/tests/cli/brain/verbs/storage.test.tsindex 43b0eaa5..3b507781 100644--- a/tests/cli/brain/verbs/storage.test.ts+++ b/tests/cli/brain/verbs/storage.test.ts@@ -17,7 +17,7 @@* answer as an empty vault.*/-import { afterEach, beforeEach, describe, expect, test } from "bun:test";+import { afterEach, beforeEach, describe, expect, setSystemTime, test } from "bun:test";import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";@@ -152,6 +152,8 @@ async function drive(argv: ReadonlyArray<string>): Promise<{ captured: Captured;}}+const DAY_MS = 86_400_000;+async function runJsonReport(): Promise<{ code: number; report: StorageReportJson }> {const { captured, code } = await drive(["--json"]);return { code, report: JSON.parse(captured.stdout) as StorageReportJson };@@ -206,11 +208,25 @@ describe("o2b brain storage", () => {// warn's 30 - and past critical's 7 - on every machine.const cap = Math.floor(total * 2.0);configureCap(cap);- seedSample("2026-10-14T00:00:00.000Z", total - total / 10, "seed-older");- seedSample("2026-10-15T00:00:00.000Z", total, "seed-newer");- seedSample("2026-10-16T00:00:00.000Z", total + total / 20, "seed-newest");+ // Seed the two days before today and today itself (UTC midnights), so+ // the verb's fresh census always lands on the newest seeded day; fixed+ // dates turned into a fourth distinct day once the calendar moved past+ // them and flattened the trend out of the warn band. The clock is+ // frozen at today's UTC noon so the census cannot cross midnight.+ const today = Math.floor(Date.now() / DAY_MS) * DAY_MS;+ const seedDay = (daysAgo: number): string => new Date(today - daysAgo * DAY_MS).toISOString();+ seedSample(seedDay(2), total - total / 10, "seed-older");+ seedSample(seedDay(1), total, "seed-newer");+ seedSample(seedDay(0), total + total / 20, "seed-newest");- const { code, report } = await runJsonReport();+ setSystemTime(new Date(today + DAY_MS / 2));+ let run: Awaited<ReturnType<typeof runJsonReport>>;+ try {+ run = await runJsonReport();+ } finally {+ setSystemTime();+ }+ const { code, report } = run;expect(code).toBe(0);const forecast = report.forecast;