Skip to content

Latest commit

 

History

History
176 lines (119 loc) · 29 KB

bstack.md

File metadata and controls

176 lines (119 loc) · 29 KB

bstack

bstack is bercail's opinionated Pi. Pi signs in with a Claude plan (through Claude Code) and a ChatGPT plan, so one agent runs both, on subscriptions you already pay for. bstack sets Pi up the way bercail works: the job is a beads issue, agents stage and leave changes uncommitted for tuicr, Claude Opus does the work and makes the calls, and GPT judges as a second opinion.

It borrows from pstack (rigor, playbooks, roles by model strength, how/why/unslop), cursor-team-kit (babysit-pr and CI loops, which became autopilot), and gstack, on top of Shep's handoff workflow (credits).

Every install runs bstack: the desk agent is its Pi lead.

bercail bstack setup     # installs Pi and the Claude bridge; models are picked for you
bercail bstack status    # what is logged in, which model each role uses
dev                      # the desk starts Pi as the bstack lead

Roles and models

The lead is the Pi on the desk. It reads the job, picks a playbook, and hands steps to the other roles, which run as hc sibling agents from templates in ~/.config/herdr-core/templates/. A sibling knows only the brief the lead writes it, and the lead checks what comes back before it passes it on.

Role Runs as Default model Does
lead the desk Claude Opus plans, routes, decides, runs /validate, reports on the issue
build bstack-builder Claude Opus writes code from the lead's brief
judge bstack-judge GPT a second opinion from another provider: hard design calls, prose, and the check at /validate. It changes nothing; the lead decides, and says why when it goes against it
autopilot bstack-autopilot Claude Opus gets an open PR green: CI, review threads, conflicts. It may commit and push the PR's branch, never merge
Shep its own terminal Claude Opus the orchestrator: jobs, desks, cards
background Shep a worker with no space Claude Fable waits on CI, a desk or a trail, reports, and stops

Discuss, a card's side conversation, runs on Claude Opus, and bercail review-pr's reviewer on GPT. Through 2026-11-30 a lead starts the builder on Claude Fable for a job that touches no high-stakes path (the builder trial). The models are picked at setup and on each update: the newest of each plan, unless you pin one (Make it yours). Without a ChatGPT login the judge runs on Claude. A rate limit pauses a role until it resets, or moves it to Claude Fable (below).

How a desk finishes: /validate

A desk ends every build with /validate (Review it). It re-reads the job, runs the tests that cover the diff and the repo's verify-<repo> skill, runs unslop on the diff, and stages everything with git add. It writes what it ran, with exit codes and evidence, to .bercail/validate.json, and the change's description to .bercail/description.md, which bercail describe check holds against the staged tree. Then the judge reads the diff, the description and the issue: does the diff do what the issue asks, is every claim backed, and what could be removed. The lead fixes what holds up and reports.

/validate never commits, pushes or opens a PR. Shep reads the result in the issue's brief (the staged change's size, its stakes, and whether its description checks out), and lands the change only with a description that does.

How it runs

bercail bstack setup installs Pi (>=1.5.1) and npm:pi-claude-bridge@0.13.2. Claude uses your Claude Code login (claude auth login), not Pi's /login anthropic or per-token Extra Usage. GPT uses /login openai inside Pi. A desk runs Pi as the lead: bercail update writes its command line to pi/lead.json, and the desk shows its status and comes back after a reboot.

A desk uses your usual Pi settings, models and logins but leaves out the AGENTS.md in Pi's agent dir (~/.pi/agent). It keeps the project's context files and uses only the --append-system-prompt values from its command instead of discovering APPEND_SYSTEM.md. If a desk already received personal instructions before the update, start a fresh Pi session: resuming keeps the old transcript.

bercail renders the profile to ~/.local/share/bercail/pi/. Installing the bridge adds its pinned package to Pi's settings, leaving unrelated settings and auth intact. Each bercail update also sets compaction.modelOverrides there, reserveTokens: 40000 for every claude-bridge model Pi lists: Claude Code refuses a prompt ("Prompt is too long") once it is within about 23k tokens of the window (20k for output, 3k of margin), and Pi's default 16384 reserve would compact only after that. A larger reserve you set stays. bercail update also puts the pin in Pi's cache for -e packages (~/.pi/agent/tmp/extensions/npm/), the one folder every -e npm: package shares, when it holds another version or none: Pis that start together on such a cache each run npm install there at once, and one can start without the bridge, while a Pi that finds the exact pin there skips installing the bridge. Every role explicitly loads the bridge and the managed extensions/fallback.ts with -e, and unsets ANTHROPIC_API_KEY, ANTHROPIC_BASE_URL, and ANTHROPIC_AUTH_TOKEN so Claude runs on your plan. The desk and the role templates also set GIT_EDITOR=true, GIT_SEQUENCE_EDITOR=true and GIT_MERGE_AUTOEDIT=no: no one is at an agent's git to close an editor, so git never waits on one. A commit with no message aborts at once, a rebase -i takes its todo list as written, and a merge, an --amend or a rebase --continue keeps the message git prepared. Role boundaries and git rules remain instructions, not enforced tool restrictions. The builder, judge, and autopilot run as interactive hc sibling agents from templates in ~/.config/herdr-core/templates/. Pi handoffs use desks or interactive siblings, not one-shot runs.

A role agent and a desk get a scratch folder of their own as TMPDIR: /var/tmp/bercail-<uid>/<pid>, on disk rather than in /tmp, which is often a tmpfs that shares RAM. It is short on purpose: a Unix socket's path is at most 107 bytes (103 on macOS), and a test launcher's own temp folders, then a socket such as Chromium's org.chromium.Chromium.XXXXXX/SingletonSocket (45 bytes), all go inside it. At 29 bytes with a 7-digit pid and a 4-digit uid, it leaves 78. A launcher that wants scratch on disk should nest under $TMPDIR, not under the worktree, whose path is already long. systemd-tmpfiles removes files in /var/tmp that nobody touched for 30 days, a long-lived desk's included. The prompts send copies there (a base checkout, a copy of the worktree, test logs), and mktemp -d puts them there by itself. The guard's TMPDIR allowance lets the judge write there, and it still refuses the judge's writes to .bercail/description.md, validate.json, handoff-result.json and policy.toml, even in a copy there. A role template starts Pi through bercail scratch run, which removes the folder when Pi exits, closed pane included, unless something Pi left running still has it as TMPDIR; a later sweep removes it once that ends. A desk agent (bercail-desk-agent) with a desk record makes its folder before it starts Pi; one without a record has no watcher to sweep it, so it keeps the TMPDIR it was given. When Pi exits, the desk's watcher sweeps every folder whose run has ended, including those of siblings that were killed. A run has ended when its pid is gone and no process of yours still has the folder as TMPDIR. bercail doctor lists any folder that is left, with its size, and bercail scratch sweep removes them. The root is bercail's alone, so keep nothing of yours in it. Each folder has a lease beside it (.<pid>), and only a leased folder is removed, only while the root is a folder you own, not a link, that no one else can write to. Shep runs on a scratch folder of its own too, removed when it exits.

Agents and their tools still leave files in /tmp (a literal /tmp/<name>, a tool that ignores TMPDIR, a desk from before scratch), and systemd-tmpfiles clears it only after 10 days. So every bercail scratch sweep, which each recorded desk runs at its start and its end, also removes your own entries in /tmp in which nothing changed, and no file was read, for 2 days (--days N, 1 to 3650, for another cut-off). It keeps an entry that a live process of yours holds (a file it has open or maps, matched by inode, so by any path, a hard link or a bind mount included, the folder it works in, the program it runs, its TMPDIR as that process sees it), one with a mount inside or that a mount shows elsewhere (while a mount shows all of /tmp elsewhere, it removes nothing), one with anything inside that is not yours or that it cannot read, and one with a newline in a name. It never removes a socket or a folder holding one, dbus-*, systemd-*, .X*, tmux-*, ssh-* or hsperfdata_*, or another user's entry, and it makes a read-only folder of yours writable before it removes it. While a process has a TMPDIR whose link it cannot read, when reading what your processes hold fails for another reason than a process ending or one it may not read, or when it has fewer than 64 file descriptors to spare, it removes nothing. It reads mounts only in its own mount namespace: a mount in a container or sandbox counts only through what its processes hold. It sees only the TMPDIR a process started with, not one it set later, and cannot see what a process of yours with closed /proc entries (a non-dumpable one) holds, and an entry opened between its look and its removal still goes; that process keeps its open file. bercail scratch sweep --dry-run lists what it would remove, with sizes, and removes nothing. bercail doctor shows /tmp's use against its size and what the last sweep removed. The guard warns when an agent writes under a literal /tmp while its TMPDIR is elsewhere (warnings).

Shep, the lead, the builder, Discuss and autopilot run on Claude Opus; background Shep runs on Claude Fable (the fable line in pi/models, the lead's model when there is none); the judge and bercail review-pr's reviewer run on GPT, by default the newest Astra of the first connected provider (Sol when it has no Astra). Fable shares the Claude plan with Opus but has a limit of its own. After Pi exhausts its own rate-limit retries:

  • Paused. A 429, a usage limit, or a Claude plan usage rejection pauses the role until the reset the provider gives (pi-claude-cli gives it in its pi-claude-cli.rate-limit diagnostic, not in headers), for 5 minutes when it gives none, or for a second when that reset has already passed. Then the same request goes on, on the same model. While it waits, the desk shows a dialog with the reset time, so Pi reports it as blocked and Shep gets a blocked desk event. Esc in that dialog stops waiting and ends the run, and so does SIGTERM or SIGHUP, so closing the pane ends it too. A headless run waits the same way, without the dialog. A blocked desk refuses hc send without --force, so a child's report or Shep's follow-up to it is refused while it waits. Each pause is a bercail-fallback-pause entry in the session.
  • Fable stands in. When the judge's own model (GPT) is limited or dead, Claude Fable (the fable line in pi/models, or the same model on the other Claude provider when this Pi did not load that one) stands in, so /validate still finishes without spending Opus; with no Fable model the judge pauses; the judge's report says which model judged. When a role runs on Opus (the claude line's model, on claude-bridge or pi-claude-cli) and the limit holds that model alone (seven_day_opus, or any claim that is not a plan window), it goes on with Fable on its own provider instead of pausing. A plan window (five_hour, seven_day) limits Fable too, on both Claude providers, so that role pauses. If Fable is limited as well, the role pauses until whichever resets first. At the next user message after its own model's limit lifts, or at the end of a pause when that model reset first, the role goes back to it; that switch is a bercail-fallback-restore entry. With no ChatGPT login, the judge runs on Fable from the start. A role on any other model never switches.
  • Stopped. A 402, "out of credits", or "need a … subscription" does not reset on its own, and neither does a missing Claude plan login (claude auth status). The role stops with the fix in its message: add credits, or run claude auth login. A dead provider is logged once in ~/.local/state/bercail/fallback-dead.jsonl. A builder, judge, or autopilot that stops sends its parent the reason with hc send. A safety-blocked judge remains incomplete. Its parent cannot replace the missing review with self-approval.
  • Thinking level. Pi's model switch resets thinking to its defaultThinkingLevel (medium unless set). The extension's switches put the role's level back, so a :high role stays high on the stand-in. A level you set with /thinking becomes the desk's level.

The desk's session name, which the desk status shows, adds paused until <time> while it waits, stand-in <model> while a stand-in runs, and dead <provider> for dead providers.

The profile stores resolved claude=, fable= and gpt= lines in pi/models. bercail bstack status reports bridge availability and Claude Code subscription auth (authMethod claude.ai or oauth_token, not an API key). bercail doctor checks the installed bridge, flags missing or stale profile data, and lists the providers found dead in the last day. It probes no provider, so a provider you have since paid for stays listed until that day is over. A grok or fallback key from before v0.18, or a role set to grok, is ignored with a warning.

Reply pills

Every role started after bercail update loads pi-emphasis by John Lindquist (MIT): the lead desk, the builder, the judge, autopilot, Shep, background Shep and Discuss. bercail review-pr's reviewer does not, because its reply is a JSON block bercail reads. It changes what Pi draws, not what is stored, copied or exported:

  • [[Done]], [[Failed]], [[Needs you]] and the other status words become colored pills with an icon.
  • Known ## headings and bold lead labels, such as Cause:, get an icon, bold text takes the theme's link color, and ├── and └── tree lines are dimmed.
  • In Pi's terminal interface it adds a reply_style section to the system prompt, about 1,500 tokens by upstream's count, that tells the agent to write pills and labels. Headless runs (pi -p, JSON, RPC) get neither the section nor the drawing.

The icons and the rounded pill ends are Nerd Font symbols; without them you see boxes. Set these in the environment Pi starts in: PI_EMPHASIS_PILL_ICONS=0 and PI_EMPHASIS_ROUND_CAPS=0 for plain chips, PI_EMPHASIS_GUIDANCE=0 to keep the drawing but drop the prompt section, and PI_EMPHASIS_COLOR for another theme color for bold text.

bercail ships a copy of upstream's one file at a pinned commit, so it installs nothing and fetches nothing. bercail update deploys it to pi/extensions/pi-emphasis/, bercail doctor reports the pinned commit (ok pi-emphasis <commit>), and bercail uninstall removes it with the profile.

Provider stops and incomplete reviews

The extension classifies provider failures as provider_safety_block, auth_expired_or_denied, usage_limit, transient_transport, model_refusal, or unknown_provider_error. Safety evidence wins over mixed 429, 402, quota text or rejected rate-limit headers. Auth failures and unknown errors stop the role; they do not pause it or move the judge. pi-claude-cli's "Claude billing:" stop, a call charged or about to be charged to usage credits, is an unknown error, not a limit, so the fallback never waits it out or routes around it. The pause on a limit is separate from Pi's bounded transport retries.

A safety block records an incomplete attempt in a bercail-provider-error session entry, without copying the error body, credentials or request payload. Records identify the session, episode, attempt, role, phase and candidate. Set BERCAIL_PHASE and BERCAIL_CANDIDATE when launching a candidate-bound review. An absent candidate is unknown, not an inferred approval target. Files and completed verification evidence stay in place with their original labels. The parent notice names the unfinished review and asks for human review or the provider's access/review process. It does not request a replacement self-review, rewrite the prompt, switch providers or continue the blocked request.

Notice claims persist in the session, so duplicate events and a resumed session do not resend the same episode. Separate assistant attempts remain recorded. A claim precedes delivery: a crash in between can lose the notice. This is not an exactly-once delivery guarantee.

Pi 1.5.2 limitation: agent retries run before the extension's final settlement hook. Its native retry classifier has no safety precedence, so a safety error containing 429 can still be retried by Pi before bercail stops the role. Provider-level retries also run below this boundary when configured (their default is zero). This extension does not suppress those retries or change retry settings. Queued work can also run before settlement, and continue: false is not a veto on Pi's natural queued work. Upstream needs a non-retryable safety reason propagated through provider normalization, both retry layers and queued-work scheduling. A safety attempt remains incomplete even if a native retry later succeeds. Structured refusal events are distinguishable when a provider exposes them. Ordinary successful text, including a refusal or a harmless quotation, is not reliably classifiable without that signal.

Claude providers

bstack runs Claude through pi-claude-bridge today. The cross-platform plan replaces it on every OS with pi-claude-code, from Pi's maintainers, and keeps pi-claude-cli as the fallback. Each runs the unmodified claude binary on your plan. pi-claude-code runs claude -p with Claude Code's own tools off and lists Pi's tools through an inert MCP server, so Claude proposes a call and Pi runs it.

The Linux spike

Verdict on Linux: pass, with gates. On 29 Nov 2026 pi-claude-code did the same guarded work as the bridge. bstack keeps pi-claude-bridge until the swap clears the gates below. If correct usage-limit handling cannot be restored, or the relay's rewriting is not acceptable, the fallback is pi-claude-cli with its relay off (PI_CLAUDE_CLI_RELAY=off). Windows has no verdict yet.

It ran on Pi 1.6.1, Claude Code 2.1.332 and pi-claude-bridge 0.13.1, in scratch Pi profiles, with pi-claude-code pinned as git:github.com/earendil-works/pi-claude-code@d5b5e04c314d3452d357174d16d10dda34daa2d2; a full SHA works with pi install and -e. On 22 tool calls on Opus 5.5, with bstack's instructions, the guard and the fallback loaded, it took 71 to 74 s against the bridge's 63 to 64 s, with cache reads and writes within 7% of the bridge's, so the replay at each tool-use boundary hits the prompt cache; the plan's quota counter is account-wide and did not isolate the replay's cost. During that turn a desk peaked at 416 to 473 MB of resident memory, against the bridge's 411 to 456 MB. After a turn pi-claude-code keeps one warm claude for 5 minutes: over a one-minute idle sample five desks held 1.85 GB, against the bridge's 0.74 GB. On both providers every test command went through Pi, the guard blocked a --no-verify commit and a force push and neither ran, Esc and a closed pane left no claude running, and on a 200K model Pi's default reserve compacted at about 190k tokens with no "Prompt is too long". The procedure and raw logs are in the private archive pi-claude-code-spike-2026-11-29/MANIFEST.md.

Gates for the swap:

  • Prefill the pin. Five Pis started together on an empty -e cache all came up without the provider: Pi's installer cloned into the same folder five times. That is a race in Pi, not in pi-claude-code. Install the pin once before desks start, then check that every desk lists the models.
  • Usage limits. On a 429 from a stand-in with Anthropic's headers (not a real limit), pi-claude-code's error carried no reset or window: it attaches its claude-code.rate-limit diagnostic only to a successful turn. The fallback scheduled its retry 5 minutes out, where on the bridge it waited for the reset. The fix needs both ends: the diagnostic on the error upstream, and fallback.ts reading claude-code.rate-limit and counting claude-code among the providers that share the Claude plan.
  • The served model. pi-claude-code passes Claude Code's alias (opus), so the binary picks the model: Claude Code 2.1.278 ran Opus 5 under the id claude-code/claude-opus-5-5, and 2.1.280 is the earliest tested to run Opus 5.5. Require 2.1.280 or later, and check the model the session records, not only the id. pi --list-models also lacks Fable 5.2, and bstack picks its models from that list, so the swap has to handle Fable 5.2 and confirm the model it is served.

A 1M window was not tried, so keep the 40k reserve for claude-code/ ids until a long Opus session shows it is not needed.

Terms: pi-claude-code's relay rewrites the request Claude Code builds before it reaches Anthropic. It rebuilds every user message from Pi's history and drops Claude Code's reminders (its ARCHITECTURE.md lists the rest), and it has no switch to turn that off. The bridge sends Claude Code's request as built.

The Windows half needs a Windows x64 VM: claude.exe, claude.cmd and claude.ps1 with multi-line prompts, and Pi's powershell tool reaching the guard.

Statecharts

The statechart skill models a stateful change in TLA+ (a lifecycle, retry or resume, lock or lease, queue, recovery, or concurrent writers), checks it with tla-ts, a TLA+ model checker in TypeScript that runs TLC's command line, shows the owner a Mermaid chart in Pi's chat, and replays the model's steps on the real code. With Lean 4 there too, it also proves the model's safety rules in Lean for every value of a bound that only limits TLC's search, and charts the proof. It is pstack's statechart skill, vendored at a pinned commit (skills/statechart/UPSTREAM.md), with bstack's wrapper around it. The feature playbook calls it for such a change when the change needs a model check (below), and /statechart <target> runs it by hand.

It is off until you turn it on, because it installs tla-ts (about 36 MB) from npm and Lean 4 (about 3 GB) with mise:

[bstack]
statechart = true

Then bercail reconfigure (or the next bercail update) installs tla-ts into ~/.local/share/bercail/statechart/ with npm ci --ignore-scripts from bercail's lockfile (lib/statechart/), which pins every package by its sha512, writes its CLI's path to ~/.local/share/bercail/statechart.env, and gives every bstack agent the skill. It needs node and npm (Node.js 22.18 or later) and no Java. Once that lockfile is installed, a reconfigure runs no npm. It also installs Lean 4, the version lib/deps.json knows for lean, with mise's http backend from the release URL and sha256 that upstream's statechart pins (scripts/lean/toolchain.ts), and writes its root to statechart.env as LEAN_SYSROOT; once mise has it, nothing downloads. Without mise, or when that install fails, bercail warns and writes only tla-ts: the TLA+ check works, and proofs are skipped. bercail doctor checks tla-ts, node and Lean. With the key off, nothing is installed, the skill is not deployed, and /statechart says how to turn it on. Turning it off removes the skill, tla-ts and statechart.env; Lean stays in mise until you run mise uninstall http:lean. The TLC and Java that bercail installed through mise before tla-ts stay until you remove them with mise uninstall. A statechart skill of your own in ~/.agents/skills (pstack's) is never written over or removed: bercail warns and leaves it.

The skill's command, ~/.agents/skills/statechart/scripts/statechart-bstack, never installs anything: without tla-ts it exits 2 with the fix. On a .lean file it runs upstream's Lean path with LEAN_SYSROOT set from statechart.env (the environment wins), so upstream looks for Lean nowhere else and never installs it with mise. Without that Lean it exits 2 and says the TLA+ check works without it. It runs upstream's command, which calls java -cp tla2tools.jar, with a java shim that runs tla-ts so that it prints what TLC 1.7.4 prints (-Dtla-ts.tlc=1.7.4), so upstream's files stay as they are. TLA_TS in the environment wins over statechart.env. TLA2TOOLS and JAVA set together run TLC instead, for a reference run; one without the other exits 2. Each run stops after STATECHART_TIMEOUT seconds (600), through GNU coreutils' timeout (brew install coreutils on macOS): without it the command exits 2. The view module that labels the chart is JavaScript the command runs, and Lean runs a file's code while it checks it, so a review never runs a PR's spec, proof or view.

What reaches chat is chart.pi.md: the chart, then the states that break a rule and every arrow in words. A chart has 20 states or fewer. Over that, the owner gets the bug's path as text (see Shep's diagrams).

Chart first, check when it matters

Every lead draws a stateful change as a Mermaid chart, with no tools: the feature playbook (skills/bstack/SKILL.md) has the rules. The full check (model, report, replay) runs when the owner or the issue asks, when the flow already has a spec the repo keeps, or when correctness depends on event order or recovery and a failure could lose or duplicate durable work, break ownership or isolation, or do something irreversible. A high_stakes path is a reason to ask that last question, not a trigger. When a check is needed and the key is off, the lead says the check is blocked and asks to turn it on or waive it.

Cross-checking tla-ts against TLC

tla-ts is young. tests/statechart/cross-check.sh [spec-dir...] runs every config of each spec on tla-ts and on TLC 1.7.4. It fails when the exit code, report.md, the charts or a replay config's graph differ, or when either engine gives anything but holds (0) or breaks (1). It installs the tla-ts that lib/statechart's lockfile pins, with npm, and needs JAVA and TLA2TOOLS (the 1.7.4 jar, checked by its sha256), so only the machine that runs it needs Java. Run it on a tla-ts bump, on a change to statechart-bstack or its shim, and on a new spec that is the proof for a risky change.

bercail's own spec is Shep's inbox, in tests/statechart/shep-inbox/: the model, a config for the chart, the configs with planted bugs, and check.sh, which runs them all and rewrites the chart and the graph that tests/shep_inbox_statechart.test.ts replays on shep/pi/inbox.ts on every test run. CI runs check.sh on tla-ts on every push and fails when it writes anything other than what the repo keeps (see development). The guard card's spec, in tests/statechart/guard-card/, also has a Lean proof, GuardCard.lean: its eight safety rules hold for any number of class flips, where TLC checks two. Its check.sh proves it when Lean is there and keeps the result in proof/.

Where to find what

The bstack guide is the full story, with prompts to copy. Each fact lives on one page:

Topic Page
setup, sign-ins, how models are picked, status, /bstack-setup Set up bstack
The playbooks, the roles (lead, build, judge, autopilot), what a prompt holds Work with the bstack agent
/how, /why, taking over a branch Understand the code
The build playbooks, /unslop Build and clean the change
/validate Review it
/autopilot and what bstack-autopilot may do Ship with autopilot
/handoff, stages bstack and autopilot Run jobs in parallel
Pinning models, effort, what a rate limit does, the files bstack writes Make it yours
Prompts and pitfalls Recipes and pitfalls

The skills (bstack, how, why, unslop, unit-testing, autopilot, and statechart when it is on) are listed in commands, the [bstack] defaults in config, and the headless stages in handoff.