byterover-cli icon indicating copy to clipboard operation
byterover-cli copied to clipboard

Proj/language selection

Open danhdoan opened this issue 6 months ago • 2 comments

Summary

Brings the language-selection feature stack to main and resolves the divergence between this branch and main's recently-landed tool-mode response-file surface (ENG-3002) and <img> first-class inline content (ENG-3021).

After this lands:

  • Curate kickoff and correction prompts emit a language clause — either "Match the user's input language…" (auto, the default) or "…in <language>" (fixed). The calling agent's LLM is told which language to write the topic body in.
  • The preference is stored in global daemon settings (language.mode / language.code) since ENG-2974. A per-project .brv/config.json language field is still honored as a fallback for users who configured before the migration.
  • The MCP curate tool description carries the auto clause so the same instruction reaches non-CLI callers.

The recently-merged main features (--response-file /--delete-response-file and <img> inline support) are preserved unchanged — the language thread composes on top, not in place of.

What's included

Feature work (history-only — these landed on the branch already):

  • ENG-2687 — BrvConfig.language schema + language-clause builder
  • ENG-2688 — Threaded language through kickoffSession and continueSession; auto clause appended to MCP TOOL_DESCRIPTION
  • ENG-2689 — CJK bigram tokenizer wired into MiniSearch (INDEX_SCHEMA_VERSION bumped to 7)
  • ENG-2690 — brv query helper + cross-language curate→query roundtrip coverage in the auto-test harness
  • ENG-2691 — brv config set/get language.* CLI (now intercepted and redirected to brv settings set per ENG-2974)
  • ENG-2974 — Language preference moved from per-project config to global daemon settings; legacy brv config set language.* kept as a deprecation gate that names the new command

Merge-resolution work (new in this PR):

  • src/agent/infra/tools/implementations/search-knowledge-service.ts — UNION of ENG-3021's parsed.imageContent indexer wiring (from main) and ENG-2689's tokenizeWithCjk in MINISEARCH_OPTIONS (from this branch). INDEX_SCHEMA_VERSION happened to be at 7 on both sides — coincidence, both changes needed an index invalidation.
  • src/oclif/commands/curate/index.ts — Kept main's richer handleContinuation body (mutex checks + loadResponseFile + local pre-dispatch validation + dispatchContinuation helper + post-success --delete-response-file cleanup) and grafted the language thread on top:
    • resolveLanguagePreference(projectRoot) is called once after projectRoot is resolved
    • language is passed into dispatchContinuation(...)
    • dispatchContinuation's args widened to accept language?: BrvConfigLanguage and forwarded into continueSession({...}) Imports merged as a clean disjoint union — BrvConfigLanguage, ProjectConfigStore, SettingsEvents, SETTINGS_KEYS from this branch + CurateSessionEnvelope and the full curate-session helper set from main.
  • Lib-layer signatures (curate-session.ts) already accept language? on both KickoffOptions and ContinueOptions, so no lib changes were required.

Harness migration (local-auto-test/language-selection-e2e):

  • Migrated 11 cases from the deprecated brv config set language.* to brv settings set language.* + settings get verification. Settings are GLOBAL since ENG-2974, so each migrated case wraps its mutation in try/finally with resetLanguageSettings() to keep cases isolated.
  • Case 6 was repurposed from the obsolete cross-field "fixed- without-code" validation (no longer applicable — language.mode and language.code are independent settings keys) into a deprecation-gate test that confirms brv config set language.* rejects with code: 'deprecated-key' and names the new brv settings set ... command.
  • Pre-suite reset added in restartDaemon so a prior aborted run cannot leak global state into the next run.
  • README updated to reflect the new surface and renumbered to 22 cases.

Conflict-resolution summary (for future archaeology)

File Strategy
search-knowledge-service.ts UNION — both contributions preserved verbatim
curate/index.ts (imports) Disjoint UNION
curate/index.ts (handleContinuation) Kept main's body, grafted language thread via dispatchContinuation widening
curate-session.ts No change required — already a superset

Test plan

  • [x] npm run lint — 0 errors (280 pre-existing warnings on unrelated test files, none on merged files)
  • [x] npm test — 9006 / 9006 passing
  • [x] local-auto-test/curate-tool-mode-e2e — 20 / 20 (all --response-file / --delete-response-file cases + all language-clause cases pass)
  • [x] local-auto-test/language-selection-e2e — 22 / 22 after the brv settings set migration
  • [x] Manual: brv settings set/get language.mode|code round-trips; brv config set language.* deprecation message names the new brv settings set command

Reviewer call-outs

  • The dispatchContinuation widening (added language?: BrvConfigLanguage to its args type) is the only behavioural change to main's response-file surface — all other main-side contracts are byte-equivalent. Worth a focused read on src/oclif/commands/curate/index.ts.
  • The harness migration is intentionally scoped to language settings only. The tool-mode harness's language smoke cases pass without migration because they use the .brv/config.json project-config fallback tier that resolveLanguagePreference still honors.
  • INDEX_SCHEMA_VERSION was bumped to 7 by both branches independently (CJK tokenizer on this branch, <img> indexer on main). Existing cached indexes were already invalidated by whichever side landed first; no additional bump needed.

Out of scope

  • Sunset of the project-config language field (the resolveLanguagePreference fallback). Tracked separately — needs raw-overrides exposure on the settings transport so mode: 'auto' from daemon can short-circuit the fallback cleanly.
  • Sunset of brv config set/get entirely — the surface still hosts the language.* deprecation gate and the applyConfigSet dispatcher for the next project-config key that needs to land.

danhdoan avatar Jun 01 '26 04:06 danhdoan

Claude finished @danhdoan's task in 4m 49s —— View job


Claude Code Review

  • [x] Read CLAUDE.md and gather context
  • [x] Review merge-resolution changes (search-knowledge-service.ts, curate/index.ts)
  • [x] Review language-clause & curate-prompt-builder
  • [x] Review settings surface migration (events, validator, format-settings)
  • [x] Review CJK tokenizer
  • [x] Review WebUI/TUI surface
  • [x] Post inline comments for issues found
  • [x] Post summary with score

Summary

Score: 4.5 / 5 — solid, well-tested, conservative merge. The merge-resolution is clean and additive; the language-clause threading composes on top of main's response-file / <img> surface without breaking either contract. The deferred concerns (precedence quirk, project-config sunset) are correctly scoped out and documented.

Strengths

  • Single source of truth for the language clause (language-clause.ts) — every emission site (kickoff, correction, MCP tool description) routes through one helper. Wording revisions are a one-file change.
  • CJK tokenizer is well-engineered — script-boundary splits, BMP-correct for…of iteration, single-char unigram fallback, comprehensive test coverage including cross-script isolation regressions. Empirical baseline ("MiniSearch 7.2.0 returned []") in the docstring is exactly the kind of forensic note that ages well.
  • Schema defends against silent fallback to English — isBrvConfigJson rejects {mode: 'fixed'} without code at load time, structurally closing the "silently writes in English" failure mode.
  • Strict TDD discipline — unit tests for language-clause, brv-config, curate-prompt-builder, curate-session, cjk-tokenizer PLUS a full-pipeline integration test (language-roundtrip.test.ts) covering Russian / Vietnamese / Chinese / Japanese end-to-end against a real on-disk config.
  • Deprecation gate is clean — brv config set language.* rejects with a structured code: 'deprecated-key' that names the new command, instead of silently succeeding or silently no-op'ing.
  • Daemon read uses a tight retry budget (maxRetries: 1, retryDelayMs: 0) — prevents a ~9s curate stall when the daemon is unreachable, and is asserted with a unit test that caps connector.callCount.

Findings (all non-blocking — see inline comments)

  1. readLanguageFromSettings precedence: explicit daemon mode: 'auto' can be overridden by stale project-config fixed. Documented but worth surfacing during sunset.
  2. Surface asymmetry: brv config get language.* still reads the legacy fallback while brv config set is gated — could mislead a mid-migration user.
  3. Enum invalid-value error surfaces as code: 'invalid_value' rather than a more specific 'invalid_enum_option' or 'invalid_value_type' with expected: 'enum'.
  4. CJK Extension A (0x3400-0x4DBF) is excluded — fine, but suggested as a cheap follow-up for zh-TW rare-char coverage.
  5. WebUI general.tsx panel ordering doesn't match CATEGORY_ORDER (LanguagePanel rendered before Updates, but listed after).
  6. Minor enum-settings-row.tsx if (next === null) return looks like dead code unless the Select callback type is string | null.
  7. buildLanguageClause silently degrades {mode: 'fixed', code: undefined} → auto, with no logger breadcrumb — fine today, worth instrumenting if future call sites bypass BrvConfig.fromJson.

Risk profile: low. Merge-resolution is byte-equivalent for main-side contracts (per the PR's own claim); the only behavioral widening is dispatchContinuation's language?: BrvConfigLanguage param, which is opt-in and fully covered by curate-prompt-builder.test.ts. Test plan checks out — full suite passes 9006/9006, both relevant local-auto-test harnesses green.

Recommendation: ship after addressing finding #1's UX surfacing (the "I clicked auto but it's still Russian" failure mode is the most likely user-visible footgun during the migration window). Other findings can fold into follow-ups. · Branch: proj/language-selection

github-actions[bot] avatar Jun 01 '26 04:06 github-actions[bot]

Claude finished @danhdoan's task in 5m 21s —— View job


Claude finished @danhdoan's task —— View job


Claude Code Review

  • [x] Read CLAUDE.md and PR diff
  • [x] Review merge-resolution changes (search-knowledge-service.ts, curate/index.ts)
  • [x] Review language-clause & curate-prompt-builder
  • [x] Review settings surface (events, validator, format-settings, handlers)
  • [x] Review CJK tokenizer
  • [x] Review WebUI/TUI settings surfaces
  • [x] Post inline comments and final score

Summary

Score: 3.5 / 5 — solid feature work and a clean merge resolution, but one ship-blocking documentation defect and a state-trap created by the brv config removal that need attention before merge. The underlying code is well-designed and well-tested; the issues are in reaching users with correct instructions and giving them a way out of pre-migration state.

Strengths

  • Single source of truth for the language clause — language-clause.ts is the only file that emits clause text; kickoff, correction prompt, and MCP tool description all import from it. Wording revisions are a one-file change.
  • Defense-in-depth schema validation — isBrvConfigJson rejects {mode: 'fixed'} without code at load time, structurally closing the "silently writes in English" failure mode. buildLanguageClause defends against the same shape anyway.
  • CJK tokenizer is well-engineered — script-boundary splits, BMP-correct iteration, single-char unigram fallback, and an empirical baseline in the docstring ("MiniSearch 7.2.0 returned []") that ages well. Tests cover cross-script isolation and corpus invariance.
  • Tight retry budget for the daemon settings read (maxRetries: 1, retryDelayMs: 0) prevents a ~9s curate kickoff stall when the daemon is unreachable; asserted with a connector.callCount cap so a future loosening can't slip through.
  • Strict TDD discipline visible across 13 changed/added test files — language-clause, cjk-tokenizer, read-language-from-settings, full-pipeline language-roundtrip.test.ts covering Russian / Vietnamese / Chinese / Japanese end-to-end.
  • Merge resolution is clean — search-knowledge-service.ts is a verbatim UNION of CJK tokenizer + <img> indexer (both invalidate via the same INDEX_SCHEMA_VERSION = 7 bump); curate/index.ts widens dispatchContinuation to thread language without disturbing main's response-file / overwrite contract.

Findings (inline comments on each)

  1. Ship-blocker — CHANGELOG.md references commands that no longer exist. The Unreleased entry describes brv config set/get language.* and the restoration recipe (brv config set language.code en + brv config set language.mode fixed) as the user-facing surface. Commit d7f3bf6 removed brv config entirely in this PR; the canonical surface is brv settings set/get language.mode|code. Users following the release notes will hit Command not found. Code suggestion attached.
  2. WebUI panel ordering doesn't match CATEGORY_ORDER — general.tsx renders LanguagePanel before UpdatesPanel; TUI and brv settings text both sort by the shared constant. The docstring on CATEGORY_ORDER warns about exactly this split-source drift. Cheapest fix is to swap the two JSX lines.
  3. Project-config language fallback is now a one-way trap. With brv config removed, a user with a stale .brv/config.json {language: fixed, code: 'ru'} who toggles daemon language.mode to auto cannot make auto take effect — readLanguageFromSettings returns undefined for non-fixed daemon mode and the fallback wins. Two paths: (a) have readLanguageFromSettings return {mode: 'auto'} explicitly so a daemon auto short-circuits the fallback, or (b) drop the project-config fallback entirely as a follow-up. (a) is small, well-tested, and unblocks (b).
  4. MCP tool description is auto-only — buildLanguageClause() (no arg) builds once at server boot, so a user with mode: 'fixed', code: 'ru' who curates via the MCP brv-curate tool will see saved memory in English even though oclif brv curate honors fixed. Code comment documents the limitation but no UX breadcrumb. Suggest either a docs note in brv connectors install README or threading the clause through per-call responses.
  5. CJK tokenizer excludes Extension A (0x3400-0x4DBF) — ~6,500 codepoints in active zh-TW / zh-HK use. BMP-safe, single-line fix, but INDEX_SCHEMA_VERSION would need a bump. Non-blocking; flag as zh-TW backlog item.
  6. Dead-code if (next === null) return in enum-settings-row.tsx — Radix Select.onValueChange emits string, not string | null. Drop the check or surface the edge case explicitly with a toast.

Out-of-scope items the PR correctly defers

  • Sunset of the project-config language field (tracked).
  • MCP per-call language clause (tracked above).

Risk profile: medium, driven mostly by finding #1 (user-facing docs lie about the surface). Code-level correctness is high; merge resolution is byte-equivalent for main-side contracts as claimed.

Recommendation: address finding #1 before merge — it's a 4-line CHANGELOG edit and prevents every reader from running broken commands. Finding #3 is the next-most-important since it's the "I clicked auto but it's still Russian" footgun for migrating users and the PR's own "Out of scope" doesn't fully cover it. The others fold cleanly into follow-ups. · Branch: proj/language-selection

github-actions[bot] avatar Jun 01 '26 08:06 github-actions[bot]