Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
privacy: masked words can match in any case, by a switch under Masked words (ZoeCats)
yetonedd7915243b28
diff --git a/internal/gateway/redact_test.go b/internal/gateway/redact_test.goindex 0369cdf59..799cbded7 100644--- a/internal/gateway/redact_test.go+++ b/internal/gateway/redact_test.go@@ -182,6 +182,9 @@ func TestCountTokensRedacted(t *testing.T) {{"secrets", settings.Settings{Redact: true}, key, "{{API_KEY_"},{"personal", settings.Settings{RedactPersonal: true}, "13812345678", "{{PHONE_"},{"words", settings.Settings{RedactWords: []string{"Nightjar"}}, "Nightjar", "{{TERM_"},+ // a word in other capitals only when the user asked for any case+ {"words_as_written", settings.Settings{RedactWords: []string{"Nightjar"}}, "NIGHTJAR", ""},+ {"words_any_case", settings.Settings{RedactWords: []string{"Nightjar"}, RedactWordsAnyCase: true}, "NIGHTJAR", "{{TERM_"},{"rules", settings.Settings{Redact: true, RedactRules: []redact.Rule{{Kind: "GW_KEY", Prefix: "acme-"}}}, "acme-Zx9ab12cdEF", "{{GW_KEY_"},{"rules_off", settings.Settings{RedactRules: []redact.Rule{{Kind: "GW_KEY", Prefix: "acme-"}}}, "acme-Zx9ab12cdEF", ""},{"off", settings.Settings{}, key, ""},diff --git a/internal/gui/api.go b/internal/gui/api.goindex e3e61cbe0..7809cecae 100644--- a/internal/gui/api.go+++ b/internal/gui/api.go@@ -1181,6 +1181,10 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {if _, sent := fields["noAutoDownload"]; !sent {in.NoAutoDownload = cur.NoAutoDownload}+ // nor whether the masked words match in any case+ if _, sent := fields["redactWordsAnyCase"]; !sent {+ in.RedactWordsAnyCase = cur.RedactWordsAnyCase+ }// nor how long an image is given to be drawnif _, sent := fields["imageTimeout"]; !sent {in.ImageTimeout = cur.ImageTimeoutdiff --git a/internal/gui/api_settings_test.go b/internal/gui/api_settings_test.goindex e7dfd1351..d8cf3d6aa 100644--- a/internal/gui/api_settings_test.go+++ b/internal/gui/api_settings_test.go@@ -271,3 +271,28 @@ func TestSettingsColorblindMode(t *testing.T) {}}}++// Masked words in any case is the Privacy page's: a page from before it+// sends no redactWordsAnyCase, and its save leaves the user's choice as it+// was; a page that sends it sets it (ZoeCats on Discord).+func TestSettingsRedactWordsAnyCaseKept(t *testing.T) {+ t.Setenv("XDG_CONFIG_HOME", t.TempDir())+ h := Handler(nil, nil)+ for _, c := range []struct {+ body string+ want bool+ }{+ {`{"theme":"dark","redactWords":["Nightjar"],"redactWordsAnyCase":true}`, true},+ {`{"theme":"light","redactWords":["Nightjar"]}`, true},+ {`{"theme":"light","redactWords":["Nightjar"],"redactWordsAnyCase":false}`, false},+ } {+ rec := httptest.NewRecorder()+ h.ServeHTTP(rec, httptest.NewRequest("POST", "/api/settings", strings.NewReader(c.body)))+ if rec.Code != http.StatusOK {+ t.Fatalf("saving %s: %d %s", c.body, rec.Code, rec.Body)+ }+ if got := settings.Load(); got.RedactWordsAnyCase != c.want || !reflect.DeepEqual(got.RedactWords, []string{"Nightjar"}) {+ t.Fatalf("after %s: any case %v, words %v; want %v", c.body, got.RedactWordsAnyCase, got.RedactWords, c.want)+ }+ }+}diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.jsindex 180bcf60f..1ee4156e7 100644--- a/internal/gui/assets/app.js+++ b/internal/gui/assets/app.js@@ -21814,6 +21814,9 @@ function renderRedact(s, keep) {i.onkeydown = (e) => { e.stopPropagation(); if (e.key === "Enter") save(); else if (e.key === "Escape") { i.value = words; i.blur(); } };i.onblur = save;row(t("Masked words"), t("Your own words to keep from vendors, separated by commas"), i);+ // plain words, matched as written unless the user asks for any case+ row(t("Masked words in any case"), t("A word also matches in other capitals: Nightjar masks NIGHTJAR and nightjar too"),+ onOff(s.redactWordsAnyCase, (redactWordsAnyCase) => savePrefs({ ...keep, redactWordsAnyCase }))).id = "redactWordsAnyCaseRow";renderRedactRules(s, row);renderMaskActions(s);renderMaskTry(s);@@ -23558,7 +23561,7 @@ function prefsKeep(s) {uiFont: s.uiFont || null, codeFont: s.codeFont || null,otel: s.otel || {},trayUsages: s.trayUsages || [],- redact: !!s.redact, redactPersonal: !!s.redactPersonal, redactKinds: s.redactKinds || {}, redactWords: s.redactWords || [], codexWarmup: s.codexWarmup || "",+ redact: !!s.redact, redactPersonal: !!s.redactPersonal, redactKinds: s.redactKinds || {}, redactWords: s.redactWords || [], redactWordsAnyCase: !!s.redactWordsAnyCase, codexWarmup: s.codexWarmup || "",claudeWarmup: s.claudeWarmup || "", codexWarmAt: s.codexWarmAt || "", claudeWarmAt: s.claudeWarmAt || "",codexWarmAts: warmTimes(s.codexWarmAts, s.codexWarmAt), claudeWarmAts: warmTimes(s.claudeWarmAts, s.claudeWarmAt), workbuddyCheckin: !!s.workbuddyCheckin, traeCheckin: !!s.traeCheckin, minimaxCheckin: !!s.minimaxCheckin, qoderCheckin: !!s.qoderCheckin, noStats: !!s.noStats, noUsageStats: !!s.noUsageStats,memberModel: !!s.memberModel, noLoopGuard: !!s.noLoopGuard, claudeLeanPrompt: !!s.claudeLeanPrompt, refusalRetries: s.refusalRetries ?? null,diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.jsindex 19e6dab84..9ebcba4b3 100644--- a/internal/gui/assets/i18n.js+++ b/internal/gui/assets/i18n.js@@ -1158,6 +1158,8 @@ const I18N = {"The bucket in s3://, gs://, oss://, cos:// and storage URLs; the path in it stays": "s3://、gs://、oss://、cos:// 和存储链接里的桶名;桶内路径不动","Email addresses and account names on Usage and Routing are blurred, for a screenshot to share": "用量和路由页上的邮箱和账号名会被模糊处理,方便截图分享","Masked words": "脱敏词",+ "Masked words in any case": "脱敏词不区分大小写",+ "A word also matches in other capitals: Nightjar masks NIGHTJAR and nightjar too": "大小写不同也算同一个词:Nightjar 也会遮住 NIGHTJAR 和 nightjar","Find with a local model": "用本地模型查找","Delete model": "删除模型","Delete the model?": "删除模型?",@@ -5022,6 +5024,8 @@ const I18N = {"The bucket in s3://, gs://, oss://, cos:// and storage URLs; the path in it stays": "s3://、gs://、oss://、cos:// 和儲存連結裡的桶名;桶內路徑不動","Email addresses and account names on Usage and Routing are blurred, for a screenshot to share": "用量和路由頁上的郵箱和帳號名會被模糊處理,方便截圖分享","Masked words": "脫敏詞",+ "Masked words in any case": "脫敏詞不分大小寫",+ "A word also matches in other capitals: Nightjar masks NIGHTJAR and nightjar too": "大小寫不同也算同一個詞:Nightjar 也會遮住 NIGHTJAR 和 nightjar","Find with a local model": "用本機模型查找","Delete model": "刪除模型","Delete the model?": "刪除模型?",@@ -8856,6 +8860,8 @@ const I18N = {"The bucket in s3://, gs://, oss://, cos:// and storage URLs; the path in it stays": "s3://、gs://、oss://、cos:// やストレージ URL のバケット名。中のパスはそのまま","Email addresses and account names on Usage and Routing are blurred, for a screenshot to share": "使用量とルーティングのページのメールアドレスとアカウント名をぼかします(スクリーンショットの共有用)","Masked words": "マスクする語",+ "Masked words in any case": "マスクする語の大文字・小文字を区別しない",+ "A word also matches in other capitals: Nightjar masks NIGHTJAR and nightjar too": "大文字・小文字が違っても同じ語として扱います:Nightjar で NIGHTJAR や nightjar もマスクされます","Find with a local model": "ローカルモデルで検出","Delete model": "モデルを削除","Delete the model?": "モデルを削除しますか?",@@ -12720,6 +12726,8 @@ const I18N = {"The bucket in s3://, gs://, oss://, cos:// and storage URLs; the path in it stays": "Der Bucket in s3://, gs://, oss://, cos:// und Speicher-URLs; der Pfad darin bleibt","Email addresses and account names on Usage and Routing are blurred, for a screenshot to share": "E-Mail-Adressen und Kontonamen auf „Nutzung“ und „Routing“ werden unscharf dargestellt, für einen Screenshot zum Teilen","Masked words": "Maskierte Wörter",+ "Masked words in any case": "Maskierte Wörter ohne Groß-/Kleinschreibung",+ "A word also matches in other capitals: Nightjar masks NIGHTJAR and nightjar too": "Ein Wort passt auch in anderer Schreibung: Nightjar maskiert auch NIGHTJAR und nightjar","Find with a local model": "Mit lokalem Modell finden","Delete model": "Modell löschen","Delete the model?": "Modell löschen?",diff --git a/internal/gui/tests/redact-words-any-case.test.cjs b/internal/gui/tests/redact-words-any-case.test.cjsnew file mode 100644index 000000000..38bd8adbc--- /dev/null+++ b/internal/gui/tests/redact-words-any-case.test.cjs@@ -0,0 +1,107 @@+// Run with Node's test runner and Playwright on the module path; see README.md.+// Settings › Privacy's "Masked words in any case" (ZoeCats on Discord): a row+// under Masked words, Off unless the user turned it on, so an existing+// user's words are matched as written as before. A click on On saves+// redactWordsAnyCase with the words and the rest of the settings as they+// were, and moves nothing; a later save from the page keeps it. In every+// language, Chromium and WebKit, in a wide window and a narrow one.+const assert = require("node:assert/strict");+const fs = require("node:fs/promises");+const path = require("node:path");+const { test } = require("node:test");+const { chromium, webkit } = require("playwright");+const { watchSettingsReads, settingsDrawn } = require("./reader.cjs");++const assets = path.resolve(__dirname, "../assets");+const words = {+ en: { name: "Masked words in any case", on: "On", off: "Off" },+ zh: { name: "脱敏词不区分大小写", on: "开启", off: "关闭" },+ "zh-TW": { name: "脫敏詞不分大小寫", on: "開啟", off: "關閉" },+ ja: { name: "マスクする語の大文字・小文字を区別しない", on: "オン", off: "オフ" },+ de: { name: "Maskierte Wörter ohne Groß-/Kleinschreibung", on: "An", off: "Aus" },+};++function serve(lang, saved) {+ let settings = { lang, theme: "light", redact: true, redactPersonal: false, redactWords: ["Nightjar"] };+ const state = { agents: [], profiles: [], settings };+ return async (r) => {+ const url = new URL(r.request().url());+ const json = (data) => r.fulfill({ json: data });+ if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });+ if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });+ if (url.pathname === "/api/state") return json(state);+ if (url.pathname === "/api/settings") {+ if (r.request().method() === "POST") {+ settings = JSON.parse(r.request().postData());+ saved.push(settings);+ }+ return json(settings);+ }+ if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });+ if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });+ if (url.pathname.startsWith("/api/")) return json({});+ const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);+ const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];+ await r.fulfill({ body: await fs.readFile(file), contentType });+ };+}++for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {+ for (const [lang, w] of Object.entries(words)) {+ for (const width of [1100, 640]) {+ test(`${engine} ${lang} ${width}px: masked words match in any case only when turned on`, async (t) => {+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));+ t.after(() => browser.close());+ const page = await (await browser.newContext({ viewport: { width, height: 1400 } })).newPage();+ page.setDefaultTimeout(5000);+ const errors = [], saved = [];+ page.on("pageerror", (e) => errors.push(e.message));+ await page.route("**/*", serve(lang, saved));+ await watchSettingsReads(page);+ await page.goto("http://magpie.test/?view=settings&tab=privacy");+ const row = page.locator("#redactWordsAnyCaseRow");+ await row.waitFor();+ await settingsDrawn(page);++ const m = await row.evaluate((r) => {+ const sub = r.querySelector(".sub"), list = document.querySelector("#redactList").getBoundingClientRect(), b = r.getBoundingClientRect();+ return {+ name: r.querySelector(".name").textContent, sub: sub.textContent,+ on: r.querySelector(".segs .opt.on")?.textContent,+ // right under the words themselves+ after: r.previousElementSibling?.querySelector("input.words") != null,+ cut: sub.scrollWidth > sub.clientWidth + 1 || sub.scrollHeight > sub.clientHeight + 1,+ inside: b.left >= list.left - 1 && b.right <= list.right + 1,+ wide: document.documentElement.scrollWidth > document.documentElement.clientWidth,+ };+ });+ assert.equal(m.name, w.name);+ assert.equal(m.on, w.off, "off unless the user turned it on");+ assert(m.after, "under Masked words");+ assert(!m.cut && m.inside && !m.wide, "shown in full, inside the page");+ if (lang !== "en") assert(!m.sub.includes("A word also matches"), "its words translated");++ const before = await page.evaluate(() => [scrollX, scrollY, document.querySelector("#view-settings").scrollTop]);+ const b = await row.locator(".segs .opt", { hasText: w.on }).boundingBox();+ await page.mouse.click(b.x + b.width / 2, b.y + b.height / 2);+ await page.waitForFunction(() => document.querySelector("#redactWordsAnyCaseRow .segs .opt.on")?.textContent === t("On"));+ await new Promise((r) => setTimeout(r, 300));+ assert.equal(saved.length, 1, "one save");+ assert.equal(saved[0].redactWordsAnyCase, true);+ assert.deepEqual(saved[0].redactWords, ["Nightjar"]);+ assert.equal(saved[0].redact, true);+ assert.deepEqual(await page.evaluate(() => [scrollX, scrollY, document.querySelector("#view-settings").scrollTop]), before, "the click moved nothing");++ // another choice on the page keeps it+ const p = page.locator("#redactList .row").nth(1).locator(".segs .opt", { hasText: w.on });+ await p.click();+ await page.waitForFunction(() => document.querySelector("#redactList .row:nth-child(2) .segs .opt.on")?.textContent === t("On"));+ await new Promise((r) => setTimeout(r, 300));+ assert.equal(saved.length, 2);+ assert.equal(saved[1].redactPersonal, true);+ assert.equal(saved[1].redactWordsAnyCase, true, "a later save keeps it");+ assert.deepEqual(errors, []);+ });+ }+ }+}diff --git a/internal/masking/masking.go b/internal/masking/masking.goindex 210310399..e16af2196 100644--- a/internal/masking/masking.go+++ b/internal/masking/masking.go@@ -23,7 +23,7 @@ func Wanted(st settings.Settings) bool {func options() redact.Options {st := settings.Shared()- o := redact.Options{Secrets: st.Redact, Personal: st.RedactPersonal, Kinds: st.RedactKinds, Words: st.RedactWords, Rules: st.RedactRules,+ o := redact.Options{Secrets: st.Redact, Personal: st.RedactPersonal, Kinds: st.RedactKinds, Words: st.RedactWords, WordsAnyCase: st.RedactWordsAnyCase, Rules: st.RedactRules,Actions: st.RedactActions, Allow: st.RedactAllow}if st.RedactModel {o.Model = modeldiff --git a/internal/redact/anycase_test.go b/internal/redact/anycase_test.gonew file mode 100644index 000000000..975fe3f09--- /dev/null+++ b/internal/redact/anycase_test.go@@ -0,0 +1,48 @@+package redact++import (+ "strings"+ "testing"+)++// A masked word matches in any case only when the user asked for it+// (ZoeCats on Discord): off, the default, it is matched as written, as+// before; on, NIGHTJAR and nightjar go as placeholders too, and each comes+// back as it was written.+func TestWordsAnyCase(t *testing.T) {+ in := "Nightjar, NIGHTJAR and nightjar; МОСКВА is Москва. A nightjars' night."+ for _, c := range []struct {+ name string+ anyCase bool+ count int+ gone []string+ kept []string+ }{+ {"as written", false, 1, []string{"Nightjar,"}, []string{"NIGHTJAR", "nightjar;", "МОСКВА", "nightjars'"}},+ {"any case", true, 6, []string{"Nightjar", "NIGHTJAR", "nightjar", "МОСКВА", "Москва"}, []string{"A ", "s' night."}},+ } {+ o := Options{Words: []string{"Nightjar", " москва "}, WordsAnyCase: c.anyCase}+ out, n := Mask(in, o)+ if n != c.count {+ t.Errorf("%s: %d masked, want %d: %q", c.name, n, c.count, out)+ }+ for _, g := range c.gone {+ if strings.Contains(unmarked(out), g) {+ t.Errorf("%s: %q still in %q", c.name, g, out)+ }+ }+ for _, k := range c.kept {+ if !strings.Contains(out, k) {+ t.Errorf("%s: %q gone from %q", c.name, k, out)+ }+ }+ if back := Restore(out, false); back != in {+ t.Errorf("%s: round trip %q → %q", c.name, out, back)+ }+ // and in a request body, as the gateway masks it+ body, _ := MaskJSON([]byte(`{"messages":[{"role":"user","content":"ship NIGHTJAR"}]}`), o)+ if hid := !strings.Contains(string(body), "NIGHTJAR"); hid != c.anyCase {+ t.Errorf("%s: NIGHTJAR in a request masked=%v: %s", c.name, hid, body)+ }+ }+}diff --git a/internal/redact/redact.go b/internal/redact/redact.goindex 3e89502e4..49155b431 100644--- a/internal/redact/redact.go+++ b/internal/redact/redact.go@@ -36,7 +36,10 @@ type Options struct {Secrets bool // API keys, private keys, tokens, passwordsPersonal bool // emails, phone numbers, ID and bank card numbersWords []string // the user's own: names, codenames, hosts- Rules []Rule // the user's own rules, masked with the secrets+ // WordsAnyCase matches Words in any case: Nightjar masks NIGHTJAR and+ // nightjar too. Off, a word is matched as written.+ WordsAnyCase bool+ Rules []Rule // the user's own rules, masked with the secrets// Kinds turns each of the Categories of personal data on or off by its// id, where the user chose; one not in it is as its Category.On says.// None of them is masked while Personal is off.@@ -458,6 +461,20 @@ func Hint(kind, v string) (head string, n int) {return string(r[:k]), n}+// anyCases are the patterns that find a user's word in any case, by word.+var anyCases sync.Map++// anyCase finds w as written but in any case (Unicode's simple folding, so+// a word whose case changes its length in bytes is still found whole).+func anyCase(w string) *regexp.Regexp {+ if re, ok := anyCases.Load(w); ok {+ return re.(*regexp.Regexp)+ }+ re := regexp.MustCompile(`(?i)` + regexp.QuoteMeta(w))+ anyCases.Store(w, re)+ return re+}+// Mask swaps what o covers in s for placeholders, and says how many.func Mask(s string, o Options) (string, int) {return mask(s, withModel(o, []string{s}), placeholder)@@ -481,6 +498,12 @@ func mask(s string, o Options, put func(kind, v string) string) (string, int) {if w = strings.TrimSpace(w); len(w) < 2 {continue}+ if o.WordsAnyCase {+ for _, m := range anyCase(w).FindAllStringIndex(s, -1) {+ found = append(found, span{m[0], m[1], "TERM", ByWord})+ }+ continue+ }for i := 0; ; {j := strings.Index(s[i:], w)if j < 0 {diff --git a/internal/settings/settings.go b/internal/settings/settings.goindex 18d721cb8..9175cb5ed 100644--- a/internal/settings/settings.go+++ b/internal/settings/settings.go@@ -96,7 +96,10 @@ type Settings struct {RedactPersonal bool `json:"redactPersonal,omitempty"`RedactKinds map[string]bool `json:"redactKinds,omitempty"`RedactWords []string `json:"redactWords,omitempty"`- RedactRules []redact.Rule `json:"redactRules,omitempty"`+ // RedactWordsAnyCase matches RedactWords in any case (ZoeCats on+ // Discord); off, the default, a word is matched as written.+ RedactWordsAnyCase bool `json:"redactWordsAnyCase,omitempty"`+ RedactRules []redact.Rule `json:"redactRules,omitempty"`// RedactActions is what is done with a value of a kind (redact.Hit's// Kind: API_KEY, EMAIL, a rule's own…) other than masking it, where// the user chose: redact.Warn sends it as written and records it,