8000 i18n: localize extension output (zero-dep catalogs; zh-Hans + en-US) — DRAFT by bu5hm4nn · Pull Request #2 · bu5hm4nn/pi-agent-team · GitHub
[go: up one dir, main page]

Skip to content

i18n: localize extension output (zero-dep catalogs; zh-Hans + en-US) — DRAFT - #2

Draft
bu5hm4nn wants to merge 26 commits into
mainfrom
wave-i18n
Draft

bu5hm4nn wants to merge 26 commits into
mainfrom
wave-i18n

Conversation

@bu5hm4nn
@bu5hm4nn bu5hm4nn commented Oct 3, 2026 •
Copy link
Copy Markdown
Owner

Summary

Zero-required-runtime-dependency English/Chinese localization for the extension's UI and all authored agent-facing runtime text.

locale selection → M registry + en-US / zh-Hans catalogs
                 → menus, help, notices and errors
                 → team system preamble, tool/schema descriptions
                 → incoming-message scaffolding and reminders
  • English is the default; positive zh* signals select zh-Hans (including zh-Hant fallback).
  • Selection: --team-lang > TEAM_LANG > team-config lang > LC_ALL > LC_MESSAGES > LANG > Intl.
  • Team roster preamble, registered tool descriptions/parameter descriptions/guidelines, incoming message/reply instructions, reminder scaffolding and roster results now use the same catalogs. The earlier exemption retaining Chinese model-facing text is removed.
  • Shipped agent skill is English and advises following the human's conversation language. Chinese comments/JSDoc and developer test titles remain unchanged.
  • Tool identifiers, wire protocol, opaque user payloads and routing IDs remain unchanged. No Pi/Jiti modifications or new dependencies.
  • This branch remains the base for the hyperswarm and messaging PRs; it retains its original tool API. The latest send/ask/reply and hyperswarm surfaces are also localized on the published combined-internal integration branch.
  • No fork-only coordination documents or backlog files are included.

Evidence

  • Before: English-locale regression tests failed because the real extension factory injected Chinese team prompt/message scaffolding.
  • After: dual-locale tests exercise registered tools/schemas, before_agent_start including an empty roster, incoming message/reply wiring, reminders and locale switching.
  • At 5d3e782: npm test -- --test-concurrency=2 — 328 tests: 322 passed, 6 existing SWIM availability skips, 0 failures. Focused locale/runtime suite: 81/81.
  • Combined integration at 44f07b0: 478 tests: 472 passed, 6 existing skips, 0 failures. Focused suite: 115/115; four-participant real-broker E2E 2/2, retaining 87 exact socket deliveries and 36 once-only reminders.
  • Syntax/whitespace checks pass; conformance suite unchanged. Independent GPT-6 Astra read-only review approved both revisions (reviewer inspected tests/logs, did not independently execute them).
  • Concurrency 2 is a host-resource workaround; package test scripts are unchanged.

Merge Danger

Door: Two-way — no migration or protocol change.

Blast Radius: Presentation — UI, agent instructions and injected scaffolding.

Registered tool/schema text retains its registration-time locale after /team lang; runtime prompts/messages update immediately. The shipped skill is static English. Pi's existing native-module hot-reload cache issue is outside this PR: fully restart Pi after updating rather than relying on /reload to refresh imported helpers.

Record the council-reviewed Phase 1 owner decisions (generated topic
capability, HMAC token possession proof, punch URI shape, accepted native
dependency) and split story 07 into 07a (transport + URI docs, Phase 1)
and 07b (delivery docs, Phase 2).
Rebases the decision of record onto the base branch: story 12 (Phase 1
follow-ups) and the commissioned i18n wave (stories 13-18, Phase 4) plus the
i18n-default-english decision and the codes-in-text-at-the-edge architecture.
Owner picked the immediate-default variant: en-US is the default, and the
completeness test enforces key parity per commit so a call site is migrated
only after its English string exists. Story 17 completes the catalog and
guards instead of flipping the default.
Catalog content lands incrementally with the migrated call sites (14-16), in
both locales at once, so per-commit completeness holds.
Two pre-existing test-infra fixes, rebased onto the base branch because the
i18n work needs a working suite here: Node 24 no longer expands directory
arguments to node --test, so the scripts use globs; and
e2e/transport-swim.test.js skips its conformance suite when the Go sidecar is
absent instead of hanging.
…e hyperswarm

Under the i18n-below-hyperswarm topology the base cannot see the Phase 1
strings. Story 13 becomes base-local (no dependencies); stories 14-16 migrate
the pre-existing surface; new story 19 localizes the Phase 1 additions on the
hyperswarm branch above.
Zero-dependency i18n foundation: en-US base/default, zh-Hans source
catalog, a symbolic message-key registry (M), and a startup-frozen
translator with {name} interpolation and Intl.PluralRules selection.

resolveLocale first-hit-wins: --team-lang > TEAM_LANG > team-config
lang > LC_ALL > LC_MESSAGES > LANG > Intl; POSIX values are normalized
and only a positive zh* signal selects zh-Hans (zh-Hant degrades), every
other locale renders en-US. Missing keys fall back en-US -> key and warn
once per key in dev/test. Guards: catalog completeness, placeholder
parity, and M/catalog orphan checks. No call site is migrated here.
Story 13: the packaging guard scans src/ recursively. Story 14: wire the
startup singleton with resolveLocale. Story 18: assert the --team-lang flag is
threaded into env.teamLang.
The files[] coverage check only listed top-level src/*.js, so src/locales/*.js
were invisible: a locale file omitted from package.json files[] would ship a
package that fails at import while the repo stayed green. Walk src/ recursively
instead. No existing assertion is weakened.
The index.ts user-visible output now goes through the catalog: every
ctx.ui.notify site, the tool renderCall/renderResult output, the new Text(...)
  renders and the status lines. 35 keys are added to messages.js (M.notify.*,
M.status.*, M.tool.*), zh-Hans (verbatim source text) and en-US (faithful
translation) in this same commit, so the catalog-completeness guard stays green
and the en default can never leak a raw key.

The startup singleton is wired at extension load: setLocale(resolveLocale(
process.env, {})). The team-config lang field is not threaded (story 18), nor is
--team-lang or /team lang.

Interactive ui.select/input/confirm prompts, flag/command descriptions and
model-facing text are intentionally untouched (stories 18 and the model-facing
protocol decision). Code comments and JSDoc stay Chinese.
- add _one/_other forms for tool.moreLines, tool.cardMoreLines and status.line
  in both catalogs, dropping the redundant base keys; count-bearing call sites
  no longer render the raw key
- add a guard test: every M key whose catalog value carries {count} must
  resolve for count=1 and count=5 in both locales
- apply the council-accepted en-US wording verbatim
- rename the two remaining locals that shadowed the imported t()
src/dispatch.js no longer holds any user-visible prose: every success line and
error it produces now renders via t(), keyed by the outcome
(dispatch.status.*, dispatch.peers.*, dispatch.send.*, dispatch.reply.*,
dispatch.mode.*, dispatch.create.*, dispatch.join.*, dispatch.label.*,
dispatch.leave.*, dispatch.missingTeam.*, dispatch.target.*). The module still
returns the same structured results, intentions and party codes; the strings in
lines/error are just sourced from the catalog at the call site.

OPTION_HELP was frozen at import, so a locale chosen at startup never reached
it. It is now optionHelp(), evaluated per call, backed by the options.help key.

97 new logical keys (101 catalog entries: four plural bases carry _one/_other)
land in src/messages.js, zh-Hans (existing Chinese verbatim) and en-US (faithful
English translation) in this same commit, so key parity holds. Four count-bearing
strings use _one/_other: dispatch.status.online, dispatch.peers.hostGroup,
dispatch.send.bulk, dispatch.send.sent.

dispatch.test.js and options.test.js now pin setLocale("zh-Hans") at file top,
so their existing Chinese assertions pass unchanged; no assertion was weakened
or rewritten. Validation reasons that still originate in options.js/team-config.js
are left for story 16, which owns those modules.

Verification: npm test 306 pass / 0 fail / 6 skipped (SWIM sidecar absent);
git diff --check clean; node --check on every changed .js. A scratch harness
compared 38 dispatch scenarios against the pre-change implementation under
zh-Hans: all byte-identical except the random token and temp config path.
…uard

Council-accepted English: 'reply strategy' unhyphenated, 'seed format', the
seed-address direction corrected to this machine's address that other nodes
reach, 'other nodes: {others}' instead of '{others} others', 'Joined team',
'Teams configured on this machine', clearer reply.invalid / replyOff /
teamUnbound / mode.note2, and 'shown only once'. Adds the four new
count-bearing dispatch bases to the plural guard's precondition list.
HANDOFF describes the two-stack topology and the i18n progress. Story 12 gains
U8: the team-name rule copy is wrong in the source and needs a bilingual fix.
…hrough t()

Route the user-visible error and diagnostic strings in the pre-existing
modules through t(), so the selected locale reaches them at the source:
session.js, team-config.js, mode.js, options.js and transport-swim.js.
Keys are namespaced session.* / config.* / mode.* / options.* /
transport.*; zh-Hans carries the existing Chinese verbatim and en-US the
faithful translation. Messages that carry a numeric count use _one/_other
(session.pendingOverflow, options.labelsTooMany) so the plural guard stays
green. Rename the local `t` bindings in session.js and team-config.js that
would shadow the imported translator.

transport.js, transport-mesh.js and ws.js contain no user-visible prose —
only wire codes and protocol diagnostics — so they are unchanged, as is the
model-facing buildPayload prompt text in session.js.

Pin the session, team-config and mode test files to zh-Hans; the Chinese
assertions are unchanged, options.test.js and dispatch.test.js were already
pinned.
Story 18 gains the index.ts execute-result text; new story 20 makes the
model-facing payload locale-aware; story 12 gains U9 (swim sidecar path
discrepancy) and U10 (name-length mismatch).
Add src/i18n-sink-guard.test.js: a dependency-free scanner that strips
line/block comments (so Chinese comments and JSDoc are ignored), then
flags CJK string/template literals in src/*.js and index.ts outside the
catalogs. Every current exception is registered in an explicit allowlist
grouped by one-line reason (D1/backlog-20 model-facing text, backlog-18
help/UI text, i18n runtime diagnostics). Self-tests prove the scanner
ignores comments and flags a new literal, and a stale-entry test forces
the allowlist to shrink as stories 18/20 migrate.

Add en-US representative coverage: exact English renders for each
namespace in i18n.test.js, a dispatch-level en-US path test in
dispatch.test.js, and an assertion that the default locale (no override,
no zh*) resolves to en-US. The existing zh-Hans-pinned assertions are
untouched and remain the byte-identical Chinese-catalog regression proof.

No production code changes: the catalog-completeness, placeholder-parity,
orphan-reachability and count-plural guards already pass with no gap found.
…r sink entries

- i18n.test.js: the default-locale assertions no longer rely on empty env
  falling through to the host Intl locale. Assert an explicit non-zh LANG
  (fr_FR.UTF-8) falls back to en-US instead; void/empty-string signals are
  verified solely by the adaptive Intl test. Removes host-coupled flakes on
  zh-locale hosts.
- i18n-sink-guard.test.js: move the team_roster execute() result literals
  ('\n可用分组:...' and '没有其他节点在线') from the backlog-18 human-visible
  group to the D1/backlog-20 model-facing group, so story 18 does not migrate
  text D1 keeps Chinese and story 20 can find them.
- i18n-sink-guard.test.js: document two known scanner boundaries — raw-source
  matching lets '\u4e2d\u6587' escape detection by design, and a regex literal
  right after ')' can desync the lexer. Documentation only; detection unchanged.
Story 18, the last human-visible migration surface.

- index.ts: route the remaining human-visible literals through t() — the
  registerFlag and registerCommand descriptions, the ui.select/ui.input
  prompts and option labels, and the tool execute() failure/receipt lines
  (发送失败/失败/回执行). All keys added to M and to both catalogs; zh-Hans
  values are verbatim from the old literals, en-US faithful.
- /team lang: reports the effective locale and its source and can set it.
  Setting persists to the current team config's `lang` field; runtime text
  follows immediately while the registration descriptions stay frozen until
  the next reload. Its output goes through t().
- Thread --team-lang: index.ts now passes pi.getFlag("team-lang") as
  env.teamLang (via startupLocaleEnv) alongside process.env, and reads the
  team-config lang field at load (env team) and session_start (flag team).
  i18n.js gains resolveLocaleInfo (resolveLocale now delegates to it),
  classifyLocale, startupLocaleEnv and an exported SUPPORTED_LOCALES.
  i18n.test.js asserts the flag reaches the top of the detection chain.
- i18n-sink-guard.test.js: drop the 70 migrated backlog-18 allowlist entries;
  the D1/backlog-20 model-facing groups stay (buildPayload scaffold, injected
  prompts, system-prompt fragment, tool descriptions and the team_roster
  execute-result group remain Chinese).

Validation: npm test 316 pass / 0 fail / 6 skipped; sink guard green
(no stale entries, no unlisted CJK); git diff --check clean.
Apply the council-confirmed English wording to the en-US catalog
(lang.set/setUnpersisted/unsupported, tool.notConnected, flag.team,
flag.teamUrl, command.team, ui.modeBrokerRecommend, ui.modeMeshNoCenter,
ui.modeSwimMembers, ui.inputSeeds, ui.placeholderToken, ui.labelOpAdd,
ui.labelOpRemove, ui.replyMirror) and align the README Language section
with the new reload semantics.

Restore the double space after the emoji in the zh-Hans menu labels
ui.menuSendToNode and ui.menuManageLabels for verbatim fidelity.

Model-facing Chinese stays unchanged (decision D1).
Remove AGENTS.md, HANDOFF.md and backlog/ (and the .gitignore entry for the
latter): these are this fork's planning artefacts, not part of the extension, so
the upstream diff should not carry them.
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

0