From cae01311cf26081847576c6dbf3c5468fdffca0c Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 31 Oct 2026 15:17:00 +0800 Subject: [PATCH] =?UTF-8?q?agent:=20Kimi=20Code=202.x's=20notice=20says=20?= =?UTF-8?q?to=20reopen=20Settings=20=E2=80=BA=20Providers,=20not=20to=20re?= =?UTF-8?q?start?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After magpie writes Kimi's config.toml, every Kimi was told "reads its settings at start-up — restart open kimi sessions". That holds for the old Python kimi-cli (~/.kimi). Kimi Code 2.x (~/.kimi-code, npm @moonshot-ai/kimi-code) watches config.toml and reloads it, so an open session takes the new models at once; only its web and desktop app's model picker is read again when Settings › Providers is opened again. jiabubu picked from that stale picker and got "Model \"magpie/...\" is not configured in config.toml". The notice now follows KimiDir's legacy flag: kimi-cli keeps the restart advice word for word, and Kimi Code 2.x is told "reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models". The same goes for Kimi in a WSL distro: wslKind gets an optional restartAt, which Kimi's kind uses to pick its notice from the distro's folder (a stopped distro reads as ~/.kimi-code, as kimiDir has it). Both new strings are in NOTICES and translated in zh, zh-TW, ja and de. Run (worktree at 027360021 + this commit, through mote-run / wsl-run): - gofmt -l internal/agent: nothing. go vet ./internal/agent, GOOS=linux go vet -tags nogui ./internal/agent ./internal/gui, GOOS=windows go vet ./internal/agent ./internal/gui: ok. - go test -count=1 -timeout 45m ./internal/agent: ok (157s), including the new TestKimiNoticeByKind and TestEveryNoticeIsTranslated. - Broken by hand: with kimi.go and wsl.go reverted, TestKimiNoticeByKind fails for Kimi Code 2.x both here and in WSL (the restart advice). - GUI (wsl-run): agent-notice-lang in WebKit 11/11 and Chromium 11/11. i18n-keys 3 of 4; "a plugin's words are its own" fails on "Unmarked" (plugins/routing vs internal/usage/search_calls_test.go), red on main, #4524. - go test ./internal/gui (at 0407d69e8 + this change) failed only in TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll, #4514) and real-window AppKit tests killed at their deadline on mote (#4125, #2645); the same five of them, run at clean origin/main 027360021, fail the same way. Not tried: a real Kimi Code app showing this notice in magpie's GUI. Kimi Code 2.4.1's reload behaviour is from an earlier sandbox run. --- internal/agent/kimi.go | 30 ++++++++++++++++-- internal/agent/kimi_notice_test.go | 49 ++++++++++++++++++++++++++++++ internal/agent/wsl.go | 8 ++++- internal/gui/assets/i18n.js | 10 ++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 internal/agent/kimi_notice_test.go diff --git a/internal/agent/kimi.go b/internal/agent/kimi.go index 43db92b40..a5c8e6258 100644 --- a/internal/agent/kimi.go +++ b/internal/agent/kimi.go @@ -309,7 +309,7 @@ func kimiIn(at place) *Agent { }, Notice: func() string { if Running(`(^|/)kimi( |$)`, `(^|/)kimi-cli( |$)`) { - return noticeKimi.String() + return kimiNotice(legacy).String() } return "" }, @@ -424,7 +424,31 @@ func kimiModelTableForKey(path, key string) (map[string]string, error) { return nil, nil } -// what kimi says after a change (notice.go) +// what kimi says after a change (notice.go). kimi-cli reads config.toml at +// start-up. Kimi Code 2.x watches it and reloads it, so an open session takes +// new models at once, but the model picker of its web and desktop app is +// read again only when Settings › Providers is opened again (jiabubu: a +// stale picker's pick said "is not configured in config.toml"). var ( - noticeKimi = newNotice("Kimi Code reads its settings at start-up — restart open kimi sessions to use this.") + noticeKimi = newNotice("Kimi Code reads its settings at start-up — restart open kimi sessions to use this.") + noticeKimiCode = newNotice("Kimi Code reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.") + noticeWSLKimi = newNotice("{agent} in WSL {distro} reads its settings at start-up — restart open kimi sessions to use this.") + noticeWSLKimiCode = newNotice("{agent} in WSL {distro} reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.") ) + +// kimiNotice is the advice after a change for kimi-cli (legacy) or Kimi +// Code 2.x. +func kimiNotice(legacy bool) notice { + if legacy { + return noticeKimi + } + return noticeKimiCode +} + +// kimiWSLNotice is kimiNotice for Kimi in a WSL distro. +func kimiWSLNotice(at place) notice { + if _, legacy := kimiDir(at); legacy { + return noticeWSLKimi + } + return noticeWSLKimiCode +} diff --git a/internal/agent/kimi_notice_test.go b/internal/agent/kimi_notice_test.go new file mode 100644 index 000000000..67845cbfa --- /dev/null +++ b/internal/agent/kimi_notice_test.go @@ -0,0 +1,49 @@ +package agent + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +// Kimi Code 2.x reloads config.toml as it runs, and only its web and +// desktop app's model picker needs Settings › Providers opened again +// (jiabubu: the stale picker's pick was "not configured in config.toml"), +// so it isn't told to restart its sessions; kimi-cli, which reads the file +// at start-up, still is. On this machine and in a WSL distro. +func TestKimiNoticeByKind(t *testing.T) { + was := Running + Running = func(...string) bool { return true } + t.Cleanup(func() { Running = was }) + t.Setenv("KIMI_SHARE_DIR", "") + t.Setenv("KIMI_CODE_HOME", "") + check := func(t *testing.T, where string, legacy bool, n string) { + t.Helper() + restart := strings.Contains(n, "restart open kimi sessions") + picker := strings.Contains(n, "Settings › Providers") + if legacy && (!restart || picker) || !legacy && (restart || !picker) { + t.Errorf("%s, kimi-cli %v: %q", where, legacy, n) + } + } + for _, c := range []struct { + dir string + legacy bool + }{{".kimi-code", false}, {".kimi", true}} { + home := syncHome(t) + os.MkdirAll(filepath.Join(home, c.dir), 0o755) + check(t, "here", c.legacy, kimi(home).Notice()) + + root := t.TempDir() + os.MkdirAll(filepath.Join(root, "home", "me", c.dir), 0o755) + k := wslKindOf("kimi") + _, has, versions := wslFinds(k) + d := distro{Name: "Ubuntu", Root: root, Home: "/home/me", Has: has, Versions: versions, + Gateway: "172.20.0.1", Mirrored: true, Running: true} + n := wslAgent(k, d).Notice() + if !strings.HasPrefix(n, "Kimi Code in WSL Ubuntu ") { + t.Errorf("WSL: %q", n) + } + check(t, "WSL", c.legacy, n) + } +} diff --git a/internal/agent/wsl.go b/internal/agent/wsl.go index b5fa1844c..1a2938c26 100644 --- a/internal/agent/wsl.go +++ b/internal/agent/wsl.go @@ -276,6 +276,9 @@ type wslKind struct { dir, bin string in func(place) *Agent // the agent at a place, as on this machine restart notice // advice after a change, when mirrored; "" none + // restartAt, when set, is restart's choice at a place (kimi-cli or Kimi + // Code 2.x, told by the folder there) + restartAt func(place) notice // version: the probe asks the distro's own bin its version (--version), // for an agent whose config depends on it version bool @@ -410,7 +413,7 @@ var wslKinds = []wslKind{ // Kimi Code's ~/.kimi-code, or the old kimi-cli's ~/.kimi where that is // all there is; a stopped distro's is looked at once it is started {id: "kimi", name: "Kimi Code", dir: ".kimi-code", bin: "kimi", in: kimiIn, - restart: newNotice("{agent} in WSL {distro} reads its settings at start-up — restart open kimi sessions to use this."), + restart: noticeWSLKimiCode, restartAt: kimiWSLNotice, asleep: func(key string) func(map[string]string) []Option { if key != "model" { return nil @@ -725,6 +728,9 @@ func wslAgent(k wslKind, d distro) *Agent { id := k.id + "@wsl:" + d.Name at := d.place(id) a := k.in(at) + if k.restartAt != nil { + k.restart = k.restartAt(at) + } a.ID, a.Name, a.Aliases, a.Bin, a.UA, a.WSL = id, k.name+" · WSL "+d.Name, nil, "", nil, d.Name a.wslVersion = at.version a.Gateway = d.base diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index 1816d3c11..ebb4387b2 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -4027,6 +4027,7 @@ const I18N = { "Install GitHub Copilot Chat in {agent} to see magpie's models in its Chat.": "在 {agent} 中安装 GitHub Copilot Chat,才能在它的 Chat 里看到 magpie 的模型。", "It reads its settings at start-up — restart open Command Code sessions to use this.": "它启动时读取设置,需重启已打开的 Command Code 会话才会生效。", "Kimi Code reads its settings at start-up — restart open kimi sessions to use this.": "Kimi Code 启动时读取设置,需重启已打开的 kimi 会话才会生效。", + "Kimi Code reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.": "Kimi Code 运行时即会读取此项;在其网页版或桌面版中,重新打开「设置 › 供应商」或刷新页面即可看到新模型。", "MothX reads its settings at start-up — restart open mothx sessions to use this.": "MothX 启动时读取设置,需重启已打开的 mothx 会话才会生效。", "Zoo Code reads magpie's profile when it starts — run Developer: Reload Window in VS Code to use this.": "Zoo Code 启动时读取 magpie 的配置档,需在 VS Code 中运行 Developer: Reload Window 才会生效。", "jcode reads its settings at start-up — restart open jcode sessions to use this.": "jcode 启动时读取设置,需重启已打开的 jcode 会话才会生效。", @@ -4091,6 +4092,7 @@ const I18N = { "{agent} in WSL {distro} reads its settings at start-up — restart open gemini sessions to see this.": "WSL {distro} 中的 {agent} 启动时读取设置,需重启已打开的 gemini 会话才能看到。", "{agent} in WSL {distro} reads its settings at start-up — restart open grok sessions to use this.": "WSL {distro} 中的 {agent} 启动时读取设置,需重启已打开的 grok 会话才会生效。", "{agent} in WSL {distro} reads its settings at start-up — restart open kimi sessions to use this.": "WSL {distro} 中的 {agent} 启动时读取设置,需重启已打开的 kimi 会话才会生效。", + "{agent} in WSL {distro} reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.": "WSL {distro} 中的 {agent} 运行时即会读取此项;在其网页版或桌面版中,重新打开「设置 › 供应商」或刷新页面即可看到新模型。", "{agent} in WSL {distro} takes magpie's gateway and model only from how it is started — type agy in a new terminal there: magpie put it in the shell's profile.": "WSL {distro} 中的 {agent} 只在启动时拿到 magpie 的网关和模型——在那里新开一个终端输入 agy:magpie 已把它写进 shell 的配置文件。", "{agent} in WSL {distro} reads its settings at start-up — restart open mothx sessions to use this.": "WSL {distro} 中的 {agent} 启动时读取设置,需重启已打开的 mothx 会话才会生效。", "{agent} in WSL {distro} reads its settings at start-up — restart open mcode sessions to use this.": "WSL {distro} 中的 {agent} 启动时读取设置,需重启已打开的 mcode 会话才会生效。", @@ -8260,6 +8262,7 @@ const I18N = { "Install GitHub Copilot Chat in {agent} to see magpie's models in its Chat.": "在 {agent} 中安裝 GitHub Copilot Chat,才能在它的 Chat 裡看到 magpie 的模型。", "It reads its settings at start-up — restart open Command Code sessions to use this.": "它啟動時讀取設定,需重啟已打開的 Command Code 會話才會生效。", "Kimi Code reads its settings at start-up — restart open kimi sessions to use this.": "Kimi Code 啟動時讀取設定,需重啟已打開的 kimi 會話才會生效。", + "Kimi Code reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.": "Kimi Code 執行時即會讀取此項;在其網頁版或桌面版中,重新開啟「設定 › 供應商」或重新整理頁面即可看到新模型。", "MothX reads its settings at start-up — restart open mothx sessions to use this.": "MothX 啟動時讀取設定,需重啟已打開的 mothx 會話才會生效。", "Zoo Code reads magpie's profile when it starts — run Developer: Reload Window in VS Code to use this.": "Zoo Code 啟動時讀取 magpie 的設定檔,需在 VS Code 中執行 Developer: Reload Window 才會生效。", "jcode reads its settings at start-up — restart open jcode sessions to use this.": "jcode 啟動時讀取設定,需重啟已打開的 jcode 會話才會生效。", @@ -8324,6 +8327,7 @@ const I18N = { "{agent} in WSL {distro} reads its settings at start-up — restart open gemini sessions to see this.": "WSL {distro} 中的 {agent} 啟動時讀取設定,需重啟已打開的 gemini 會話才能看到。", "{agent} in WSL {distro} reads its settings at start-up — restart open grok sessions to use this.": "WSL {distro} 中的 {agent} 啟動時讀取設定,需重啟已打開的 grok 會話才會生效。", "{agent} in WSL {distro} reads its settings at start-up — restart open kimi sessions to use this.": "WSL {distro} 中的 {agent} 啟動時讀取設定,需重啟已打開的 kimi 會話才會生效。", + "{agent} in WSL {distro} reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.": "WSL {distro} 中的 {agent} 執行時即會讀取此項;在其網頁版或桌面版中,重新開啟「設定 › 供應商」或重新整理頁面即可看到新模型。", "{agent} in WSL {distro} takes magpie's gateway and model only from how it is started — type agy in a new terminal there: magpie put it in the shell's profile.": "WSL {distro} 中的 {agent} 只在啟動時拿到 magpie 的閘道和模型——在那裡新開一個終端機輸入 agy:magpie 已把它寫進 shell 的設定檔。", "{agent} in WSL {distro} reads its settings at start-up — restart open mothx sessions to use this.": "WSL {distro} 中的 {agent} 啟動時讀取設定,需重啟已打開的 mothx 會話才會生效。", "{agent} in WSL {distro} reads its settings at start-up — restart open mcode sessions to use this.": "WSL {distro} 中的 {agent} 啟動時讀取設定,需重啟已打開的 mcode 會話才會生效。", @@ -12495,6 +12499,7 @@ const I18N = { "Install GitHub Copilot Chat in {agent} to see magpie's models in its Chat.": "{agent} の Chat に magpie のモデルを表示するには、GitHub Copilot Chat をインストールしてください。", "It reads its settings at start-up — restart open Command Code sessions to use this.": "起動時に設定を読み込むため、反映するには開いている Command Code セッションを再起動してください。", "Kimi Code reads its settings at start-up — restart open kimi sessions to use this.": "Kimi Code は起動時に設定を読み込みます。反映するには開いている kimi セッションを再起動してください。", + "Kimi Code reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.": "Kimi Code は実行中に読み込みます。Web 版やデスクトップ版では「設定 › プロバイダー」を開き直すか、ページを再読み込みすると新しいモデルが表示されます。", "MothX reads its settings at start-up — restart open mothx sessions to use this.": "MothX は起動時に設定を読み込みます。反映するには開いている mothx セッションを再起動してください。", "Zoo Code reads magpie's profile when it starts — run Developer: Reload Window in VS Code to use this.": "Zoo Code は起動時に magpie のプロファイルを読み込みます。反映するには VS Code で Developer: Reload Window を実行してください。", "jcode reads its settings at start-up — restart open jcode sessions to use this.": "jcode は起動時に設定を読み込みます。反映するには開いている jcode セッションを再起動してください。", @@ -12559,6 +12564,7 @@ const I18N = { "{agent} in WSL {distro} reads its settings at start-up — restart open gemini sessions to see this.": "WSL {distro} の {agent} は起動時に設定を読み込みます。反映するには開いている gemini セッションを再起動してください。", "{agent} in WSL {distro} reads its settings at start-up — restart open grok sessions to use this.": "WSL {distro} の {agent} は起動時に設定を読み込みます。反映するには開いている grok セッションを再起動してください。", "{agent} in WSL {distro} reads its settings at start-up — restart open kimi sessions to use this.": "WSL {distro} の {agent} は起動時に設定を読み込みます。反映するには開いている kimi セッションを再起動してください。", + "{agent} in WSL {distro} reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.": "WSL {distro} の {agent} は実行中に読み込みます。Web 版やデスクトップ版では「設定 › プロバイダー」を開き直すか、ページを再読み込みすると新しいモデルが表示されます。", "{agent} in WSL {distro} takes magpie's gateway and model only from how it is started — type agy in a new terminal there: magpie put it in the shell's profile.": "WSL {distro} の {agent} は magpie のゲートウェイとモデルを起動方法からのみ受け取ります。そこで新しいターミナルを開いて agy と入力してください。magpie がシェルのプロファイルに書き込みました。", "{agent} in WSL {distro} reads its settings at start-up — restart open mothx sessions to use this.": "WSL {distro} の {agent} は起動時に設定を読み込みます。反映するには開いている mothx セッションを再起動してください。", "{agent} in WSL {distro} reads its settings at start-up — restart open mcode sessions to use this.": "WSL {distro} の {agent} は起動時に設定を読み込みます。反映するには開いている mcode セッションを再起動してください。", @@ -16730,6 +16736,7 @@ const I18N = { "Install GitHub Copilot Chat in {agent} to see magpie's models in its Chat.": "GitHub Copilot Chat in {agent} installieren, um magpies Modelle in seinem Chat zu sehen.", "It reads its settings at start-up — restart open Command Code sessions to use this.": "Es liest seine Einstellungen beim Start – offene Command-Code-Sitzungen neu starten, damit es gilt.", "Kimi Code reads its settings at start-up — restart open kimi sessions to use this.": "Kimi Code liest seine Einstellungen beim Start – offene kimi-Sitzungen neu starten, damit es gilt.", + "Kimi Code reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.": "Kimi Code liest das im laufenden Betrieb; in seiner Web- oder Desktop-App Einstellungen › Anbieter neu öffnen oder die Seite neu laden, um neue Modelle zu sehen.", "MothX reads its settings at start-up — restart open mothx sessions to use this.": "MothX liest seine Einstellungen beim Start – offene mothx-Sitzungen neu starten, damit es gilt.", "Zoo Code reads magpie's profile when it starts — run Developer: Reload Window in VS Code to use this.": "Zoo Code liest das Profil von magpie beim Start – in VS Code Developer: Reload Window ausführen, damit es gilt.", "jcode reads its settings at start-up — restart open jcode sessions to use this.": "jcode liest seine Einstellungen beim Start – offene jcode-Sitzungen neu starten, damit es gilt.", @@ -16794,6 +16801,7 @@ const I18N = { "{agent} in WSL {distro} reads its settings at start-up — restart open gemini sessions to see this.": "{agent} in WSL {distro} liest seine Einstellungen beim Start – offene gemini-Sitzungen neu starten, um es zu sehen.", "{agent} in WSL {distro} reads its settings at start-up — restart open grok sessions to use this.": "{agent} in WSL {distro} liest seine Einstellungen beim Start – offene grok-Sitzungen neu starten, damit es gilt.", "{agent} in WSL {distro} reads its settings at start-up — restart open kimi sessions to use this.": "{agent} in WSL {distro} liest seine Einstellungen beim Start – offene kimi-Sitzungen neu starten, damit es gilt.", + "{agent} in WSL {distro} reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.": "{agent} in WSL {distro} liest das im laufenden Betrieb; in seiner Web- oder Desktop-App Einstellungen › Anbieter neu öffnen oder die Seite neu laden, um neue Modelle zu sehen.", "{agent} in WSL {distro} takes magpie's gateway and model only from how it is started — type agy in a new terminal there: magpie put it in the shell's profile.": "{agent} in WSL {distro} erhält magpies Gateway und Modell nur über die Art, wie es gestartet wird – dort in einem neuen Terminal agy eingeben: magpie hat es ins Profil der Shell geschrieben.", "{agent} in WSL {distro} reads its settings at start-up — restart open mothx sessions to use this.": "{agent} in WSL {distro} liest seine Einstellungen beim Start – offene mothx-Sitzungen neu starten, damit es gilt.", "{agent} in WSL {distro} reads its settings at start-up — restart open mcode sessions to use this.": "{agent} in WSL {distro} liest seine Einstellungen beim Start – offene mcode-Sitzungen neu starten, damit es gilt.", @@ -16988,6 +16996,7 @@ const NOTICES = [ "Install GitHub Copilot Chat in {agent} to see magpie's models in its Chat.", "It reads its settings at start-up — restart open Command Code sessions to use this.", "Kimi Code reads its settings at start-up — restart open kimi sessions to use this.", + "Kimi Code reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.", "MothX reads its settings at start-up — restart open mothx sessions to use this.", "Zoo Code reads magpie's profile when it starts — run Developer: Reload Window in VS Code to use this.", "jcode reads its settings at start-up — restart open jcode sessions to use this.", @@ -17048,6 +17057,7 @@ const NOTICES = [ "{agent} in WSL {distro} reads its settings at start-up — restart open gemini sessions to see this.", "{agent} in WSL {distro} reads its settings at start-up — restart open grok sessions to use this.", "{agent} in WSL {distro} reads its settings at start-up — restart open kimi sessions to use this.", + "{agent} in WSL {distro} reads this as it runs; in its web or desktop app, reopen Settings › Providers or reload the page to see new models.", "{agent} in WSL {distro} takes magpie's gateway and model only from how it is started — type agy in a new terminal there: magpie put it in the shell's profile.", "{agent} in WSL {distro} reads its settings at start-up — restart open mothx sessions to use this.", "{agent} in WSL {distro} reads its settings at start-up — restart open mcode sessions to use this.",