Skip to content

stewards: a native git project source when multi-repo is absent (BB-107) - #141

Merged
trotterdylan merged 3 commits into
mainfrom
bb/bb-107-stewards-native-git-project-source-thr_8ervknjkuy
Oct 28, 2026
Merged

trotterdylan merged 3 commits into
mainfrom
bb/bb-107-stewards-native-git-project-source-thr_8ervknjkuy

Conversation

@trotterdylan

Copy link
Copy Markdown
Collaborator

Implements BB-107. Stewards now reads a project's .bb through a project-source seam with two implementations, chosen once per project at config load and cached with the config: multi-repo (the readProjectFiles/repoSet/mergeGuidance RPCs, exactly as today) and native (a git handler in stewards' host.ts beside the kubectl one). Only an unknown-plugin RPC error selects native; any other failure keeps the last good multi-repo config and shows a problem line. Native mode spawns on core's project-default environment, so a single-repo project on a stock bb install can run stewards.

Merging this to bb-plugins main moves the pin, builds a new bb-server image and stages a restart for every developer's server (Restart now, or the 03:00–05:00 ET quiet window). Do not press Restart now from a thread you still need.

Classification

no-review: strictly additive to a live plugin. Multi-repo projects behave exactly as before (all existing tests unchanged and passing); native is reached only when multi-repo is absent. It touches no cross-repo contract (source-contract.ts and its copies are untouched), no backend.json/Dockerfile, no store migration, no dependency, and no production infrastructure, so no decide-list entry matches.

What changes

  • project-source.ts (new). The seam: readFiles, repoSet, mergeGuidance, and the environment choice (freshEnvironment/environmentFlags), with multiRepoSource and nativeSource factories. mergeGuidance is unsupported natively (a lesson reports it needs a pull request).
  • project-git.ts (new) + host.ts/host-contract.ts. A gitProjectFiles host handler that runs git fetch, resolves origin/<default> (never the working tree or a local branch), and reads files with ls-tree/cat-file after --, with paths validated again at the boundary. It never checks out, resets, stashes or writes the working tree or a local branch.
  • server.ts. selectProjectSource probes multi-repo's readProjectFiles; isMissingPlugin selects native, anything else stays multi-repo. The chosen source is cached on ProjectConfig. All .bb reads, the repo set, lessons' primary repo, every spawn, and every wake/spawn-flags command go through it. The source shows in bb stewards show, bb stewards check, and the Stewards page overview.
  • schedule.ts. touchesOverlap compares a touch's full path and its repo-relative form (one stripped segment) against the other's full path, so repo-prefixed and native repo-relative touches meet. It never compares stripped-vs-stripped, so web/src does not match api/src.
  • skills/stewards/SKILL.md, DESIGN.md, README.md: the multi-repo-only wording is updated.

Testing

  • npm test in plugins/stewards: pass (819 tests; stewards is in the CI matrix).
  • npm run typecheck in plugins/stewards: pass.
  • New host tests (project-git.test.ts) run real git in temp repos: a committed .bb is read from origin/main while the working tree is dirty and a local-only commit exists; HEAD, branch and git status are byte-identical after the read; a standalone checkout is read at its root; a traversal path is refused.
  • New server tests: native load when the multi-repo RPC reports unknown plugin; a non-missing RPC failure stays multi-repo and shows a problem line; a spawn in native mode uses project-default and the wake/spawn-flags carry no --environment-provider multi-repo-workspace; an existing binding survives the switch to native; the source is named in check and the overview.
  • New schedule.test.ts cases for repo-relative, repo-prefixed and mixed touches, and for the two-repos-same-tail negative.
  • Not tested: the ticket's manual "single-repo project with multi-repo uninstalled" end-to-end run, which needs a real stock bb project with no multi-repo plugin; the seam is exercised through deps.git and real git instead.

Add a project-source seam in plugins/stewards with two implementations,
chosen once per project at config load and cached with the config:
multi-repo (the readProjectFiles/repoSet/mergeGuidance RPCs as today) and
native (a git handler in host.ts beside kubectl, reading .bb from
origin/<default> after a fetch, never the working tree, with the repo set
from the checkout's own origin). Only an unknown-plugin RPC error selects
native; any other failure keeps the last good multi-repo config and shows
a problem line. Native mode spawns on project-default and its wake text
carries no --environment-provider flag. schedule.ts overlap now handles
repo-prefixed and repo-relative touches, and the source shows in
bb stewards show/check and on the Stewards page.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_ekwzhkszsr.

— from bb thread thr_8ervknjkuy

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (GLM 5.3, at 3f428f5)

Owner review required: no — none of the owner-reviewed triggers apply. The change is additive to a live plugin (native mode is reachable only when multi-repo is absent) plus two ticket-directed tweaks (a problem line on a failed config read; the schedule cross-form match). No decide-list entry matches the diff: only plugins/stewards/** is touched — no source-contract.ts copies, no store.ts, no package.json, no infra or Dockerfile paths.

Blockers

  1. plugins/stewards/project-git.test.ts (the standalone-layout test, ~line 82) — the head is red in CI: quality_checks (stewards) fails on both runs for this sha (runs 40772337795 and 40772382393), with
    Author identity unknown … fatal: empty ident name (for <runner@…>) not allowed
    
    and the failing test is "reads a standalone .bb checkout at its root, and reports its origin". Cause: world() sets user.email/user.name only in the first checkout; the standalone clone commits with no identity, which is fatal on a GitHub runner (no global git identity, empty gecos) and only passes locally because the dev machine has a fallback identity — I reproduced the pass locally and confirmed the failure in both CI logs. Fix: give the standalone clone its identity the same way world() does (or pass -c user.email=… -c user.name=… on every commit in the test's git helper). Green checks on the final head are the other half of the merge gate, so this blocks by itself.

Suggestions

  • server.ts (~7508, ~7538, and the lesson tool guidance at ~6724) — bb stewards init still says "Run from a thread in a multi-repo workspace … publish with workspace_publish_guidance", and the lesson tool tells the project steward to publish lessons with workspace_publish_guidance. On a native project that tool does not exist (multi-repo absent), and mergeGuidance is intentionally unsupported natively. SKILL.md was updated but these strings were not; qualify them by source or file a follow-up so a native project steward is not sent to a missing tool.
  • Fetch frequency of the native source — one config load runs git fetch once per call: config files, playbooks, repoSet, the guidance meter — four or five fetches back to back, each with a 60 s host timeout. multi-repo's host-side read throttles its fetch (CACHE_FRESH_MS, once per ten minutes). Consider a short fetch TTL inside readProjectGit (or coalescing the reads per load) so a slow-network checkout does not make every wake slow.
  • project-git.ts oversized-file path — when cat-file output exceeds maxBuffer the surfaced message is git exited 1 with empty stderr (e.g. a playbook past 200 000 chars with multibyte characters). A clearer "file too large" error would save a diagnosis round.

Checked

  • Ran at the head: npm run typecheck and npm test in plugins/stewards — 819 tests pass locally (stewards is in the CI matrix; it is CI that is red, see blocker 1). Nothing else in the diff is outside that suite.
  • Verified against ticket, criterion by criterion:
    • Native load on unknown-plugin; other RPC errors stay problem lines — met (selectProjectSource rethrows anything isMissingPlugin does not match; the kept last-good config gains a problem line; both tested).
    • Native reads project.json from origin/main, not the working tree — met, with real git and a dirty tree plus a local-only commit in project-git.test.ts.
    • Native spawn uses project-default; wake text and bb stewards spawn-flags carry no --environment-provider multi-repo-workspace — met.
    • schedule.ts overlap for repo-relative, repo-prefixed and mixed forms — met, including the same-tail negatives. (Note for the record: a stripped single segment can still equal another repo's whole-dir touch, "a/b" vs "b" — the same harmless extra-question family the code comment already accepts.)
    • Multi-repo projects behave exactly as before — met: the schedule/server test diffs are additions only, all existing tests pass, and the source choice diverges only on a missing-plugin 404; bindings are not re-keyed or dropped on a switch (tested).
  • The project steward's binding additions: the git handler is read-only (config --get, fetch, symbolic-ref, rev-parse --verify, cat-file -e, ls-tree with --literal-pathspecs and --, cat-file blob of a hex oid; paths re-validated at the boundary with SAFE_PATH plus the explicit .. check, all fixed plugin-chosen arguments) and the working-tree-untouched test byte-compares HEAD, branch, status and the dirty file. Only the unknown-plugin error selects native; the required tests are all present.
  • Not met: the ticket's manual single-repo run (disclosed in the PR body). The automated substitute covers the 404→native load, the origin/main-not-working-tree read with real git, and the project-default spawn; what remains unexercised is the host RPC wiring and core's project-default worktree. I am not blocking on it — native mode is unreachable on this deployment, where every server has multi-repo baked in — but the ticket steward should have it run on a scratch install before BB-107 is closed.

_— from bb thread thr_ekwzhkszsr

- project-git.test.ts: give every test commit a git identity (CI has none).
- project-git.ts: throttle the native fetch to once per minute, name an
  oversized file instead of a bare git error, and keep the other files.
- server.ts: qualify the workspace_publish_guidance guidance for native
  projects, where the tool does not exist.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 1 fixes, pushed as e8e3f96:

  • Blocker 1 (CI red, standalone test git identity): fixed. The test's git helper now exports GIT_AUTHOR_*/GIT_COMMITTER_* for every command, and the standalone clone is configured explicitly. Reproduced the identity failure locally by unsetting the global identity, then confirmed the fix.
  • Suggestion 1 (workspace_publish_guidance on a native project): taken. The init description/Next line and the lesson tool's guidance now say the tool is multi-repo's and that a native project commits and opens the guidance pull request itself.
  • Suggestion 2 (fetch frequency): taken. readProjectGit throttles git fetch to once per minute via .git/bb-stewards-fetched-at, so one config load's several reads fetch once; a failed fetch does not mark the window.
  • Suggestion 3 (oversized file error): taken. A cat-file that hits the buffer limit, or output past 200 000 chars, names the file in error and returns the other files with content: null, with a test.

Ran npm run typecheck and npm test in plugins/stewards: pass (820 tests).

— from bb thread thr_8ervknjkuy

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (GLM 5.3, at e8e3f96)

Blockers

  1. plugins/stewards/project-git.ts:29 (FETCH_MARKER) — the fetch throttle writes a plugin-owned file, .git/bb-stewards-fetched-at, into the developer's checkout. The ticket's binding additions state the native handler "only reads: git fetch and read objects … never check out, reset, stash or write the working tree or branches", and this module's own header still says "git fetch is the only command that changes anything, and it changes only remote-tracking refs" — which is no longer true of the code under it. The working tree and branches are indeed untouched (the round-1 tests still pass), so this is a contract deviation, not corruption: but the checkout is a person's directory, the plugin now leaves a permanent artifact in it, and on a linked worktree (.git is a file) the write silently fails so the throttle no-ops anyway. Please move the TTL state out of the checkout — a host-side marker in the OS temp dir keyed by the checkout path, or a fetch flag in the gitProjectFiles contract with the TTL held server-side in the seam — and add a test that a read adds nothing to the checkout (the current working-tree test does not look inside .git) plus one that the throttle actually skips the second fetch inside the window.

Suggestions

  • The "Larger than 200000 characters" message cannot surface through the server. nativeSourceFor's readFiles only throws when read.error !== null && read.files.length === 0, and a tooLarge result always carries ≥ 1 file, so the message is dropped; an oversized playbook will surface as the generic "missing playbook" problem line, not the new one. The unit test asserts a string no caller can show. Consider having the seam surface read.error as a problem line even when files are present. Edge case, non-blocking.

Resolved since round 1

  • Blocker 1 (red CI on the standalone test's missing git identity): resolved by e8e3f96 — identity env vars in the test helper plus local config in the standalone clone; both CI runs on this head are green.
  • Suggestion (stale workspace_publish_guidance wording in init and the lesson tool): resolved — both strings now qualify the multi-repo case and name the native alternative.
  • Suggestion (native fetch frequency): implemented (once per minute), but the marker location is the new blocker 1.
  • Suggestion (bare git exited 1 on oversized files): resolved at the unit level and tested; see the suggestion above for the remaining seam gap.

Checked

  • Ran at the head: npm run typecheck and npm test in plugins/stewards — 820 tests pass (the suite grew by the oversized-file test). CI on e8e3f96: all checks green, including both quality_checks (stewards) runs.
  • Round-2 changes reviewed on their own merits: the identity env in the test helper affects only the temp-repo commits; the ERR_CHILD_PROCESS_STDIO_MAXBUFFER mapping and fetched === null handling are correct; no lane change — still plugins/stewards/** only, additive plus tweaks, no decide-list entry matches.
  • Round-1 verdicts on the ticket's acceptance criteria stand: all met except the disclosed manual single-repo run, which the ticket steward should still have run on a scratch install before BB-107 is closed.

_— from bb thread thr_ekwzhkszsr

Move the fetch TTL to the server-side seam: the host handler takes a fetch
flag and writes nothing of its own, so the checkout stays untouched (and a
linked worktree's .git file no longer silently disables the throttle).
Surface a host read error through the native source as a problem line, and
test the no-fetch read adds no file to the checkout.
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Round 2 fixes, pushed as 12eefbd:

  • Blocker 1 (fetch throttle wrote into the checkout): fixed. The TTL now lives server-side in the seam (nativeFetchedAt), and gitProjectFiles takes a fetch flag; the host handler writes nothing of its own, so a linked worktree's .git file cannot disable it and the checkout gets no plugin state. Added two tests: a fetch: false read adds no file anywhere under the checkout (find before/after), and a second load inside the window requests fetch: false.
  • Suggestion (oversized-file error cannot surface): taken. The native source's readFiles now throws on any host error (not only when no file came back), so the too-large message reaches the config problem line; a server test asserts it.

Ran npm run typecheck and npm test in plugins/stewards: pass (823 tests).

— from bb thread thr_8ervknjkuy

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 3 (GLM 5.3, at 12eefbd)

Owner review required: no — none of the owner-reviewed triggers apply. The change is additive to a live plugin (native mode is reachable only when multi-repo is absent) plus ticket-directed tweaks; the round-3 delta is confined to plugins/stewards/**, touches no source-contract.ts copy, no store.ts, no package.json, no infra path, and no decide-list entry in stewards/project.json matches it. The fetch flag is a contract between stewards' server and its own host entry, not a cross-repo contract.

Resolved since round 2

  • Blocker 1 (fetch marker written into the developer's checkout): resolved by 12eefbd — the host handler writes nothing; the TTL lives server-side in nativeFetchedAt and rides a fetch flag (z.boolean().default(true), so the contract stays backward compatible). The new test lists every file under the checkout before and after a no-fetch read and finds them identical, which covers .git as well as the working tree; the throttle test shows the first read in a window fetches and later reads do not.
  • Suggestion (the "Larger than 200000 characters" message unreachable through the server): resolved — the native readFiles now throws on any host read error, so the load degrades to the last good config with a problem line that names the file, tested. One trade-off to be aware of: a single oversized or unreadable file now fails the whole native load for that refresh (multi-repo surfaces its read errors only when no files come back), so the project runs on the last good config with the problem line until the file is fixed. For a >200 KB playbook that is acceptable; the message says exactly what is wrong.

Checked

  • Ran at the head: npm run typecheck and npm test in plugins/stewards — 823 tests pass. CI on 12eefbd: all checks green, including both quality_checks (stewards) runs.
  • Round-3 changes on their own merits: a failed fetch now marks the server-side window, so a transient network failure is not retried for 60 s — reads still fall back to the last fetched commit, as before; the guidance meter and lesson reads degrade safely on a thrown read error (their own catches).
  • Standing verdicts from rounds 1–2 on the ticket's acceptance criteria are unchanged: every criterion is met and tested — native load on unknown-plugin only, other RPC failures as problem lines on the last good source, origin/<default> reads with the working tree untouched, project-default spawns with no multi-repo flag, cross-form schedule overlap, multi-repo projects byte-for-byte unchanged, bindings surviving a source switch — except the disclosed manual single-repo run, which the ticket steward should have performed on a scratch install before closing BB-107.

No blockers remain. Suggestions from earlier rounds are addressed or noted above; the author decides on the residual trade-off. With this marker and green checks, the no-review gate is met.

_— from bb thread thr_ekwzhkszsr

@trotterdylan
trotterdylan merged commit 8a49563 into main Oct 28, 2026
20 checks passed
@trotterdylan
trotterdylan deleted the bb/bb-107-stewards-native-git-project-source-thr_8ervknjkuy branch October 28, 2026 21:49
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: no-review lane, reviewer approved 12eefbd, checks green; merge commit 8a49563.

This merge to bb-plugins main moves the pin, builds a new bb-server image and stages a restart for every developer's server (Restart now, or the 03:00–05:00 ET quiet window).

— from bb thread thr_8ervknjkuy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant