A Chinese window said "ZCode 已接入 magpie. ZCode reads its providers at
start-up — restart ZCode …": the notice an agent gives after a change
(state.notice) was English text written in place in each agent's file, and
i18n.js had no entry for any of them.
What changed:
- internal/agent/notice.go: a notice is a template registered with
newNotice ("Restart {agent} to …"), filled with say(kv...); Notices()
lists every one. All the agents' notices (claude, codex daemon, zcode,
agy, cursor-local, wsl, AstrBot's added today, …) are now such templates, the issue's list
being a sample of them.
- i18n.js: every template has a zh, zh-TW, ja and de translation, and
NOTICES lists them. tNotice() reads a notice of several joined: longest
template first, a {slot} never runs over a sentence's end, and a notice
with any part that has no template (a plugin's own) reads as given
rather than half in each language. withNotice() joins the status line
and the notice with 。 in zh/ja.
- app.js: the six places that showed state.notice use withNotice.
Tests:
- TestEveryNoticeIsTranslated: every Notices() template is in NOTICES and
in each language table, with the same slots. Fails with the zh ZCode
line deleted from i18n.js (tried).
- TestNoticesAreTemplates: an AST scan for English written in place as a
Notice. Fails with zcode.go's literal put back (tried).
- tests/agent-notice-lang.test.cjs: every template, filled, alone and
joined, plus a plugin's notice, and connecting ZCode as the reporter
did; en, zh, zh-TW, ja, de at 1100 and 420px, Chromium and WebKit:
22/22. Its zh subtests fail without the zh line.
Run: go test -tags nogui ./internal/agent ./internal/gui; gofmt -l;
GOOS=linux and GOOS=windows go vet -tags nogui ./internal/agent
./internal/gui; the full GUI suite (node --test, both engines, -concurrency 6,
machine load ~140): 5130/5195, 64 failing in 22 files. Rerun alone, 16
files pass; mobile-web, old-webkit, panel-usage and routing-context/
group/keys-fold fail the same on the base commit, b6a263b9.
go test -tags nogui -timeout 40m ./... on the rebased tree: every package
ok but internal/gateway, whose TestQueuedStreamKeptAliveForTheMinute hit
its 1.5s read deadline at a machine load of ~130; it passes -count=3 run
alone, and this change touches nothing it runs.
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package agent
|
|
|
|
import (
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
// notice is advice an agent gives after a change (Agent.Notice), as an
|
|
// English template whose {slots} hold only names, paths, versions and
|
|
// commands. Each one is made with newNotice, so Notices lists every one:
|
|
// the GUI shows a notice in the reader's language by matching the English
|
|
// it gets to these templates (NOTICES and tNotice in i18n.js), and
|
|
// TestEveryNoticeIsTranslated holds each to a translation in every
|
|
// language the GUI has (#1508). A notice of several sentences is notices
|
|
// joined with a space.
|
|
type notice string
|
|
|
|
var notices []notice
|
|
|
|
// newNotice is the template en, listed in Notices; called only to set a
|
|
// package var, never per call.
|
|
func newNotice(en string) notice {
|
|
n := notice(en)
|
|
notices = append(notices, n)
|
|
return n
|
|
}
|
|
|
|
// say is the notice with its slots filled: say("agent", "Codex", …).
|
|
func (n notice) say(kv ...string) string {
|
|
s := string(n)
|
|
for i := 0; i+1 < len(kv); i += 2 {
|
|
s = strings.ReplaceAll(s, "{"+kv[i]+"}", kv[i+1])
|
|
}
|
|
return s
|
|
}
|
|
|
|
// String is the notice as it reads with no slots to fill.
|
|
func (n notice) String() string { return string(n) }
|
|
|
|
// Notices are the templates of every notice magpie's own agents give.
|
|
func Notices() []string {
|
|
out := make([]string, 0, len(notices))
|
|
for _, n := range notices {
|
|
out = append(out, string(n))
|
|
}
|
|
slices.Sort(out)
|
|
return slices.Compact(out)
|
|
}
|