xiaozhi-esp32-server/westernization.md
lapy 13a627af6b chore(audit): generator code bundle no longer exempt from Han scan
The rebuilt bundle ships translated strings, so westernization_audit.sh now
scans generator/assets + index.html as live source (allowlisting the one
third-party opentype.js LCID font-name table line). The exception narrows to
generator/static device data, which the firmware consumes byte-for-byte.
westernization.md documents the checkout location and rebuild flow.
2026-10-12 14:16:35 +01:00

9.8 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:

  1. If a provider was deleted downstream, keep it deleted.
  2. If a provider was re-localized downstream, keep it re-localized and add any new upstream locale strings in the downstream style.
  3. If upstream added a new provider, check whether it is Chinese-only or Chinese-focused. If yes, do not surface it downstream.
  4. Keep backend logic improvements and upstream fixes whenever possible, but port them into the downstream provider set instead of reintroducing removed providers.
  5. Upstream wins for core abstractions, bug fixes, security fixes, framework updates, schema history, and generated artifacts.
  6. 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:

  1. providers-runtime
  2. admin-api
  3. admin-web-mobile
  4. docs-branding
  5. ops-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 output
  • main/manager-web/public/generator/index.html is tied to that output
  • main/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:

  1. update generator source (never the bundle directly)
  2. cd web && npm run build (default base ./ so the bundle works under whatever path the console mounts it at, e.g. /generator/)
  3. replace main/manager-web/public/generator with the fresh web/dist
  4. 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.

Audit Workflow

Use the audit script after meaningful rebase batches:

./scripts/westernization_audit.sh

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/** and index.html)
  • 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.java
  • main/manager-api/src/test/java/xiaozhi/modules/sys/H2JsonFunctions.java

Manager Web

cd main/manager-web
npm run build

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.sh passes
  • mvn -q -Dtest=LiquibaseWesternizationIntegrationTest test passes

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

Practical Order On Future Rebases

When upstream moves a lot, use this order:

  1. rebase or merge upstream into an integration branch
  2. restore provider/runtime deletions and relocalization
  3. restore admin API provider filtering and downstream cleanup migrations
  4. restore web/mobile surface cleanup
  5. restore docs/branding cleanup
  6. rebuild generator from source if needed
  7. run the audit script
  8. run subsystem validation
  9. 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.