The October rebase silently shipped runtime-breaking merge artifacts that
neither the web build nor the test suites caught (blank models page,
ReferenceError on role open, broken provider management). Make every one
of those failure classes fail loudly and early:
- manager-web/scripts/integrity-check.js: AST pass (acorn + eslint-scope)
for undefined identifiers (lost imports, dropped function params and
const bindings), vue-template-compiler pass for mismatched tags, and a
duplicate-options-key pass (double 'computed:' clobbering). Negative-
tested against reproductions of all three shipped bugs.
- manager-web/scripts/check-i18n.js rewritten for the fork: base locale
is en, locales discovered dynamically, plus a pass that fails when any
$t('a.b') key referenced in src/ has no definition (upstream rebases
kept adding views with keys never added downstream).
- scripts/westernization_rebase_check.sh: one-command gate chaining audit,
integrity, i18n parity, snapshot/contract/unit tests and the production
build; heavier Java/Python suites run only when toolchains exist.
- scripts/translate_han_llm.py: vendored from the one-off /tmp tool used
for the translation sweep; repo-relative paths, endpoint/model via
TRANSLATE_API/TRANSLATE_MODEL env, cache gitignored.
- CI: the Vue job now runs integrity-check, check:i18n, test:snapshot and
test:contract before test:unit; new nightly Upstream Sync Check workflow
dry-merges upstream/main into a throwaway branch and runs the same web
gates so a breaking incoming merge alerts before a human sync.
- westernization.md: tooling table, five known merge-corruption failure
classes with symptoms and repair strategy, translator usage, updated
rebase order and good-outcome checklist.
acorn and eslint-scope are now explicit devDependencies.
15 KiB
Westernization Rebase Guide
This file is a downstream rebase playbook for re-westernizing the project after syncing from upstream.
It is written for future-me first: follow this instead of relying on memory.
Goal
The downstream branch exists to keep the upstream project fully westernized.
That means:
- remove Chinese-facing product surface
- preserve downstream provider deletions
- preserve downstream provider relocalization
- keep multilingual support where useful, but default the product to English
- backport upstream bug fixes and framework improvements without restoring Chinese-only integrations
Core Rules
Always apply these rules during rebase conflict resolution:
- If a provider was deleted downstream, keep it deleted.
- If a provider was re-localized downstream, keep it re-localized and add any new upstream locale strings in the downstream style.
- If upstream added a new provider, check whether it is Chinese-only or Chinese-focused. If yes, do not surface it downstream.
- Keep backend logic improvements and upstream fixes whenever possible, but port them into the downstream provider set instead of reintroducing removed providers.
- Upstream wins for core abstractions, bug fixes, security fixes, framework updates, schema history, and generated artifacts.
- Downstream wins for locale defaults, western provider allow-lists, public copy, branding, legal pages, and removal of Chinese-facing surfaces.
Rebase Strategy
Do not treat the downstream overlay as one giant replay.
Rebuild the downstream shape in these slices:
providers-runtimeadmin-apiadmin-web-mobiledocs-brandingops-tests
Use an integration branch first. Do not rewrite downstream main in place
until the integration branch is validated.
What To Check In Each Slice
1. Providers Runtime
Files and areas:
main/xiaozhi-server/core/providers/**main/xiaozhi-server/core/utils/**main/xiaozhi-server/plugins_func/**main/xiaozhi-server/config/**main/xiaozhi-server/requirements.txt- server Docker and compose files
Actions:
- remove Chinese-only ASR/LLM/TTS/news providers from shipped/default runtime
- keep western or provider-neutral replacements
- preserve downstream provider naming and localization
- keep runtime prompts, errors, MCP/tool text, and logs English-first
- keep server-facing defaults provider-neutral where possible
2. Admin API
Files and areas:
main/manager-api/src/main/java/**main/manager-api/src/main/resources/i18n/**main/manager-api/src/main/resources/db/changelog/**
Actions:
- preserve provider filtering and downstream westernized metadata
- never rewrite Liquibase history destructively
- add follow-up migrations only; keep changelog append-only
- keep Chinese-only providers out of surfaced configs, selectors, and defaults
- keep upstream backend fixes even when downstream surface differs
Important:
- historical Liquibase SQL is an intentional exception zone
- do not "clean it up" casually if it would rewrite shipped history
- if a new migration adds Chinese-facing defaults, add a downstream cleanup migration rather than editing old history
3. Admin Web And Mobile
Files and areas:
main/manager-web/src/**main/manager-web/public/**main/manager-mobile/src/**
Actions:
- keep supported languages shared and non-duplicated
- default to English
- keep non-Chinese locales where useful
- remove Chinese-facing public routes, legal pages, selectors, assets, and fallback copy from shipped downstream surfaces
- preserve upstream UI/framework improvements
4. Docs And Branding
Files and areas:
README*docs/**- internal reference docs used by downstream maintainers
Actions:
- rewrite docs in English or westernized multilingual form
- remove Chinese screenshots/copy where they are part of downstream surface
- prefer compact English reference docs over huge translated carry-overs
5. Ops And Tests
Files and areas:
- setup scripts
- Dockerfiles
- CI/test harnesses
main/xiaozhi-server/test/**
Actions:
- keep tests runnable after rebase
- keep public or interactive test harness text English-first
- preserve useful downstream validation tools
Generator Rule
The device-theme generator is a separate Vite/Vue app. Its built output is vendored into this repo:
main/manager-web/public/generator/assets/**is generated outputmain/manager-web/public/generator/index.htmlis tied to that outputmain/manager-web/public/generator/static/**is functional device data (charset codepoint tables, CJK font glyph tables, emoji gifs, wakeword model blobs) shipped byte-for-byte to the firmware toolchain
Do not hand-edit the built bundle unless absolutely necessary.
The generator source repo is a separate checkout:
- remote:
https://github.com/78/xiaozhi-assets-generator(westernization branch, translated locales/comments, relative asset base) - working copy during rebuild work:
/tmp/xiaozhi-assets-generator
Rebuild flow:
- update generator source (never the bundle directly)
cd web && npm run build(default base./so the bundle works under whatever path the console mounts it at, e.g./generator/)- replace
main/manager-web/public/generatorwith the freshweb/dist - run
./scripts/westernization_audit.sh
If Han-script appears in the generated code bundle, fix the generator source
first before attempting bundle surgery. The audit treats the code bundle as
live source; only generator/static data is exempt.
Verification Tooling (run these, don't trust the build)
npm run build treats broken Vue templates as warnings and the unit suites
do not mount full views, so a rebase can merge real breakage while everything
stays green. The 2026-10 rebase shipped three such silent regressions (blank
models page, ReferenceError: request is not defined when opening a role,
provider management rendered as garbage). All are now machine-checked:
| Check | Command | Catches |
|---|---|---|
| Integrity | node main/manager-web/scripts/integrity-check.js |
undefined identifiers (lost imports, dropped function params/const request bindings), mismatched template tags, duplicated Vue option keys (computed: twice clobbers the first) |
| i18n | cd main/manager-web && npm run check:i18n |
duplicate keys, cross-locale drift vs en, $t('...') keys with no definition in any locale |
| Snapshot contract | npm run test:snapshot |
agent snapshot API shape (restoreAgentSnapshot etc. were silently deleted once, while AgentSnapshotDialog.vue still called them) |
| Han audit | ./scripts/westernization_audit.sh |
Chinese text/paths outside exception zones |
| Everything | ./scripts/westernization_rebase_check.sh |
one gate chaining all of the above plus build and smoke suites |
CI runs the same set: Westernization audit job plus the Vue (manager-web)
job (integrity-check -> check:i18n -> test:snapshot -> test:contract -> test:unit). A nightly Upstream Sync Check workflow dry-merges
upstream/main and runs the web gates on the merged result, so an incoming
breaking merge alerts the night before a human syncs.
Known merge-corruption failure classes (2026-10 postmortem)
These are the shapes the auto-merge produced; the integrity checker flags all of them, but knowing the shapes speeds up conflict resolution:
- Lost import -
components: { CustomDialog }shorthand with no matchingimport. The chunk throws at eval time; webpack 5 caches the failed module, so vue-router silently registersdefault === undefinedand the page renders<!---->with no console error. - Dropped signature params / const bindings - method bodies referencing
request,onTerminalFailure,retryCount,retryWindowStartedAt,failCallbackafter the merge kept the old one-line signature. Compare againstupstream/mainwhen a method looks half-converted. - Whole methods deleted while callers survive in another merged file
(
getRAGModels, snapshot API). The integrity checker cannot see this (no undefined identifier), soApi.*cross-reference plus the snapshot contract tests exist; re-run the cross-reference from the postmortem after big merges (snippet in commit583c5304message area, or grepApi\.\w+\.\w+and diff against module exports). - Interleaved implementations - both an old
el-tableblock and a newCustomTableblock merged into one view (ProviderManagement). When tags mismatch like this, prefer taking upstream's newer version wholesale and re-applying the few translation strings, instead of surgical repair. - Half-converted components - root tag converted (
el-dialog->CustomDialog) but closing tag/footer wiring left behind (FirmwareDialog, AddWisdomBodyDialog, CustomDialog's duplicatedcomputed).
Translation tool
The Han->English batch translator used for sweeps is vendored:
# needs the local OpenAI-compatible endpoint (override via env)
TRANSLATE_API=http://10.0.1.9:2000/v1/chat/completions \
TRANSLATE_MODEL=qwen3.8:instruct \
python3 scripts/translate_han_llm.py [path ...] # no args = whole repo
It is placeholder-safe (printf/brace/tag/URL masking), batched, cached
(scripts/.translate_cache.json, gitignored) and resumable. Never translate
inside the generator bundle - fix generator source (see Generator Rule) and
rebuild.
Audit Workflow
Use the audit script after meaningful rebase batches:
./scripts/westernization_audit.sh
The audit is a single Python implementation
(scripts/westernization_audit.py, wrapped by
scripts/westernization_audit.sh) so local and CI runs cannot diverge.
It scans git ls-files -co --exclude-standard, i.e. tracked files are
inspected even when a broad gitignore rule (e.g. *.json) hides them from
ripgrep; files with a NUL byte or media/font/model extensions are skipped as
binary blobs.
What it enforces:
- live source/docs must be clean of Han-script and Chinese locale tags
- this includes the vendored generator code bundle
(
main/manager-web/public/generator/assets/**andindex.html) - this includes vendored model metadata (
.cdi3.json,.physics3.json) which ships editable display names - path names must be clean of Han-script
Intentional exception zones:
main/manager-api/src/main/resources/db/changelog(append-only Liquibase history; fresh installs are migrated and cleaned to English by the append downstream changeset)main/manager-web/public/generator/static/**(functional device data shipped byte-for-byte: charset codepoint lists, CJK glyph tables, wakeword blobs)- one allowlisted line inside the generator bundle: the third-party opentype.js LCID-to-BCP47 font-name table (it maps locale ids such as 1028)
If the audit fails outside those areas, fix the violations before moving on.
Verification Workflow
Run the owning subsystem checks after each slice when possible.
Python server
cd main/xiaozhi-server
PYTHONPATH=. pytest tests/ -q
Or the interactive harness:
cd main/xiaozhi-server && PYTHONPATH=. python3 ../digital-human/test_runner.py
Manager API
cd main/manager-api
mvn -q -DskipTests compile
mvn test -q
Liquibase final-state validation matters here. Do not rely only on compile or Spring tests that skip Liquibase.
Use the dedicated fresh-DB integration harness too:
cd main/manager-api
mvn -q -Dtest=LiquibaseWesternizationIntegrationTest test
What it checks:
- replays the full changelog chain on a fresh H2 database
- applies downstream append-only cleanup migrations
- writes a final seed dump to
main/manager-api/target/liquibase-h2-seed-dump.txt - asserts that westernized final-state rows are present
- asserts that Chinese-facing seeded rows/tokens do not survive in the final surfaced data
Harness files:
main/manager-api/src/test/java/xiaozhi/modules/sys/LiquibaseWesternizationIntegrationTest.javamain/manager-api/src/test/java/xiaozhi/modules/sys/H2JsonFunctions.java
Manager Web
cd main/manager-web
npm run check:integrity # AST/template/option-key checks (see tooling table)
npm run check:i18n
npm test
npm run build
Or from the repo root, everything at once:
./scripts/westernization_rebase_check.sh
Manager Mobile
cd main/manager-mobile
pnpm build:h5
pnpm type-check
If a verification step fails because of an upstream baseline issue, note that clearly and avoid mixing that fix with unrelated westernization work unless it blocks progress.
High-Risk Areas
Be extra careful in these zones:
- Liquibase history
- provider metadata and seeded defaults
- generated web assets
- locale registries
- firmware/device dictionaries and model voice lists
- anything that can silently re-surface a removed Chinese provider
Good Outcomes
A rebase is in good shape when all of these are true:
- deleted downstream providers stay deleted
- relocalized downstream providers stay relocalized
- upstream fixes are retained in surviving abstractions
- web/mobile shipped surfaces are English-first and non-Chinese-facing
- server runtime prompts and tool text are westernized
- docs and filenames are clean outside intentional exception zones
./scripts/westernization_audit.shpasses./scripts/westernization_rebase_check.shpasses (integrity, i18n, web tests, build)mvn -q -Dtest=LiquibaseWesternizationIntegrationTest testpasses
Bad Smells
Stop and correct course if any of these happen:
- a removed provider reappears in config, UI, migrations, or docs
- Chinese locale assumptions return as defaults
- generated assets are edited directly without checking source
- large translated docs get copied forward when a shorter English reference would do
- old migrations are rewritten instead of adding cleanup migrations
- the branch drifts into a single giant mixed overlay again
- the web build is green but a page renders blank - the build only warns on
broken templates; run
scripts/integrity-check.js, it makes those errors fatal - a merged view/API file "looks fine" but half its function signatures changed
style - diff the file against
upstream/main, not just against HEAD~1
Practical Order On Future Rebases
When upstream moves a lot, use this order:
- rebase or merge upstream into an integration branch
- scan the merge result for the five corruption shapes listed under "Known
merge-corruption failure classes" (
integrity-check.jsfinds 1, 2, 4, 5) - restore provider/runtime deletions and relocalization
- restore admin API provider filtering and downstream cleanup migrations
- restore web/mobile surface cleanup
- restore docs/branding cleanup
- rebuild generator from source if needed
- run
./scripts/westernization_rebase_check.sh(audit + web gates) - run subsystem validation (mvn, pytest)
- only then promote the integration branch
Final Reminder
The purpose of downstream is not "translate upstream."
The purpose is to preserve a westernized product surface while still inheriting upstream engineering improvements.