Skip to content

feat: [ENG-2852] brv-bridge v2 — tool-mode adaptation#13

Open
cuongdo-byterover wants to merge 3 commits into
release/2.0.0from
feat/ENG-2852
Open

feat: [ENG-2852] brv-bridge v2 — tool-mode adaptation#13
cuongdo-byterover wants to merge 3 commits into
release/2.0.0from
feat/ENG-2852

Conversation

@cuongdo-byterover
Copy link
Copy Markdown
Collaborator

@cuongdo-byterover cuongdo-byterover commented May 20, 2026

Description

Bridge adaptation for ByteRover CLI v2 tool-mode. Hosts (OpenClaw plugin, future plugin integrations) talk to brv without a daemon-side LLM; the bridge speaks the new CLI surface end-to-end.

Linear: ENG-2852

Motivation

Tool-mode brv does not run an LLM in its daemon. The legacy bridge (persist()) assumed brv curate would call the daemon LLM to author HTML; in tool-mode it cannot. The bridge needs a new shape that matches the CLI's two-phase session protocol — agent authors HTML, bridge forwards a JSON envelope.

Implementation

Types (src/types.ts)

  • New QueryToolModeResult mirroring the CLI --format json shape: matchedDocs[], metadata{tier, durationMs, topScore, cacheHit, skippedSharedCount, totalFound}, status.
  • New CurateMeta, PersistHtmlInput/Options/Result/Error types.
  • New wire shapes BrvCurateKickoffData, BrvCurateContinueData.
  • PersistResult / PersistOptions marked @deprecated.

Bridge (src/bridge.ts)

  • recall() now concatenates matchedDocs[].rendered_md with \n\n---\n\n separators; reads metadata from data.metadata.* (not flat data.*).
  • New queryEnvelope() returns the full structured result for callers that need per-doc paths / scores.
  • New persistHtml() drives the 2-call session protocol with CURATE_KICKOFF_PLACEHOLDER ("_brv-bridge curate placeholder_") for the kickoff intent string.
  • persist() throws a clear migration error pointing callers at persistHtml().

Spawn helpers (src/process.ts)

  • brvQuery gains a limit param.
  • New brvCurateKickoff / brvCurateContinue helpers wrapping the two CLI invocations.
  • brvCurate marked @deprecated.

Test plan

  • npm run build clean
  • npm run lint 0 errors
  • Unit tests pass (npm test)
  • Tier-3 smoke against dev brv on proj/byterover-tool-mode:
    • recall() returns concatenated rendered_md + metadata
    • queryEnvelope() returns structured result
    • persistHtml() two-phase round-trip writes a topic file under .brv/context-tree/
  • End-to-end via brv-openclaw-plugin (sibling PR #26): curate from OpenClaw → topic lands

Breaking changes

  • persist() now throws — callers must migrate to persistHtml() and pre-author the <bv-topic> HTML themselves. This matches the v2 contract that the daemon no longer owns LLM authoring. v1 hosts will need an update.
  • PersistResult / PersistOptions deprecated; mark for removal in a follow-up minor.
    `

cuongdo-byterover and others added 3 commits May 18, 2026 15:19
Adapts the bridge to byterover-cli's tool-mode `brv` (M1-M4 ship). Drops
the legacy "byterover-side LLM authors HTML from raw text" flow and gains
a new persist surface that drives the curate session protocol internally.
After publish, downstream consumers (brv-openclaw-plugin v2 — ENG-2853 —
and any future host plugin) get a clean API that works against the
tool-mode CLI with no provider configured.

Breaking
- `BrvBridge.persist(text)` throws at runtime with a clear migration
  message pointing at `persistHtml`. Method signature kept so typed
  imports compile; the legacy text→HTML path required an LLM byterover
  no longer has. Removed entirely in v3.0.
- `RecallResult.content` is now the concatenation of
  `matchedDocs[].rendered_md` separated by `\n\n---\n\n`. The legacy
  `data.result` / `data.content` top-level fields silently returned ""
  under the new envelope; this rewires content from the new source.
- `BrvQueryData` shape mirrors `QueryToolModeResult` exactly:
  `{status, matchedDocs[], metadata}`. tier/durationMs/topScore moved
  from `data.*` to `data.metadata.*` — bridge reads them from the new
  location.
- `RecallMatchedDoc` includes the canonical `format` and `rendered_md`
  fields.

Added
- `BrvBridge.persistHtml({html, meta?, confirmOverwrite?})` — drives the
  kickoff + continuation session protocol (2 subprocess calls). Returns
  `{status: 'ok' | 'validation-failed', ...}`. Bridge does NOT loop on
  validation failure — calling agent owns retries.
- `BrvBridge.queryEnvelope(query, options)` — raw `QueryToolModeResult`
  passthrough for callers that want structured matched-docs (e.g. an
  agent-facing `brv-query` tool handler). Throws on subprocess failure
  rather than swallowing.
- `RecallOptions.limit` — passed through as `--limit <n>`.
- `CurateMeta` type — agent-supplied operation metadata
  (type/impact/reason/summary/previousSummary/confidence) that drives
  the HITL review pipeline. Mirrors byterover-cli's M4 curate-metadata
  schema. Bridge plumbs it through to the continuation envelope; older
  CLIs silently ignore it (the curate still succeeds, no HITL surfacing).
- `PersistHtmlInput / PersistHtmlOptions / PersistHtmlResult /
  PersistHtmlError` public types.
- `QueryToolModeResult / QueryToolModeMatchedDoc / QueryToolModeMetadata`
  re-exports — consumers can type tool handlers without re-declaring.
- `brvCurateKickoff` + `brvCurateContinue` subprocess helpers in
  `process.ts`. Reuse the existing `runBrv` discipline (timeout, abort
  signal, stdout cap, NDJSON parsing).

Changed
- `recall().content` joins `rendered_md` bodies with `\n\n---\n\n`.
  Empty entries are filtered out before joining so a missing rendered_md
  doesn't produce a spurious separator gap.
- `recall()` reads tier/durationMs/topScore from `data.metadata.*`.
- topScore only surfaced when `matchedDocs.length > 0` so cache hits
  with stripped metadata don't report a misleading "0 best match".

Deprecated
- `PersistOptions / PersistResult` types — kept exported as @deprecated
  for typed-import back-compat. Removed in v3.0.
- `brvCurate` subprocess helper in `process.ts` — bridge no longer calls
  it. Removed in v3.0.

Tests
- test/bridge.test.ts rewritten for the new envelope. 30 new cases added
  across: recall (content-from-rendered_md, no-matches branch, metadata
  nesting drift guard, empty-entry filtering, limit passthrough);
  queryEnvelope (raw passthrough, no-matches, throws on failure,
  cwd/limit options); persistHtml (happy path 2-subprocess sequence,
  sessionId plumbing, html+meta in continuation, confirmOverwrite,
  validation-failed branch, kickoff failure, missing sessionId,
  cwd/signal propagation, placeholder marker); persist (throws with
  v2.0/persistHtml/<bv-topic> markers in message).

Verified
- npm run typecheck: clean
- npm test: 44/44 passing (was 14; +30)
- npm run build: produces dist/ artifacts

Out of scope (deferred per plan)
- `brv curate --html` direct CLI flag (we use the 2-call session
  protocol). Cost: ~500ms extra per persist; session leak risk on
  validation failures. Revisit if metrics show problems.
- Session-leak cleanup. Sessions left in `correct-html` state persist
  on disk under `.brv/sessions/curate-<id>/` until a TTL cleanup ships
  (separate work).
- Per-tool concurrency / semaphore — callers serialize their own
  persistHtml calls (the OpenClaw agent does this).
- Direct transport client — bridge stays subprocess-based.

Plan: /Users/cuong/workspaces/vibing-zone/plans/05-plugin-adaptation/tasks/01-brv-bridge-v2.md
Linear: https://linear.app/byterover/issue/ENG-2852
Regenerated by the release pipeline; not part of the source tree. Stays
on disk locally; future regens won't be staged.
@cuongdo-byterover cuongdo-byterover changed the title Feat/eng 2852 feat: [ENG-2852] brv-bridge v2 — tool-mode adaptation May 20, 2026
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.

2 participants