Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
redact: a request opens by its key again; the key goes to the GUI as a string
yetonee52a5e50ba83
diff --git a/internal/gateway/masked.go b/internal/gateway/masked.goindex d8fa16739..2d921bcc9 100644--- a/internal/gateway/masked.go+++ b/internal/gateway/masked.go@@ -21,7 +21,9 @@ type Masked struct {Warned int `json:"warned,omitempty"` // places a value went as written, the user toldKinds map[string]int `json:"kinds,omitempty"` // different values by kindBy map[string]int `json:"by,omitempty"` // different values by finder- Key int64 `json:"key,omitempty"`+ // Key is a string in JSON: nanoseconds are past what a JS number+ // holds exactly, and a rounded key finds no record+ Key int64 `json:"key,omitempty,string"`}// maskHits are what a masker swapped: each value from a gwmw.Teller, anddiff --git a/internal/gateway/masked_test.go b/internal/gateway/masked_test.goindex 013db7cf4..206f75468 100644--- a/internal/gateway/masked_test.go+++ b/internal/gateway/masked_test.go@@ -2,9 +2,11 @@ package gatewayimport ("context"+ "encoding/json""io""net/http""net/http/httptest"+ "strconv""strings""testing"@@ -78,6 +80,10 @@ func TestMaskedRequestIsRecorded(t *testing.T) {if !found {t.Fatalf("route %d not in the trace", r.Route)}+ // the GUI opens the record by this key: a JS number would round it+ if b, _ := json.Marshal(Masked{Key: r.Key}); !strings.Contains(string(b), `"key":"`+strconv.FormatInt(r.Key, 10)+`"`) {+ t.Fatalf("masked's key not a string: %s", b)+ }if c, ok := s.RouteCall(r.Route); !ok || c.Masked == nil || c.Masked.Distinct != 2 {t.Fatalf("call's masked: %+v %v", c.Masked, ok)}diff --git a/internal/gui/assets/plugins/redact/client.js b/internal/gui/assets/plugins/redact/client.jsindex e09319ea4..80422515d 100644--- a/internal/gui/assets/plugins/redact/client.js+++ b/internal/gui/assets/plugins/redact/client.js@@ -22,6 +22,6 @@ magpie.plugin("redact", (ctx) => {refresh(again) { return maskPageLoad(again); },reload() { return maskPageLoad(true); },leave() { maskTipOff(); },- focus(key) { maskOneOpen(+key); },+ focus(key) { maskOneOpen(String(key)); },});});diff --git a/internal/gui/assets/plugins/redact/page.js b/internal/gui/assets/plugins/redact/page.jsindex 1aeefeb21..7ab9e43f3 100644--- a/internal/gui/assets/plugins/redact/page.js+++ b/internal/gui/assets/plugins/redact/page.js@@ -78,7 +78,7 @@ function maskPageOpen() {// a masked call in the tray panel opens the window on its requestif (!maskKeyRead) {maskKeyRead = true;- const k = +params.get("key");+ const k = params.get("key");if (k) {const q = new URLSearchParams(location.search);q.delete("key");@@ -401,7 +401,7 @@ function maskRefresh() {const seq = maskSeq;return api(maskQuery(0)).then((r) => {if (seq !== maskSeq || !maskL.records.length) return;- const fresh = (r?.records || []).filter((x) => x.key > maskL.records[0].key);+ const fresh = (r?.records || []).filter((x) => BigInt(x.key) > BigInt(maskL.records[0].key));if (!fresh.length) return;maskL.records = [...fresh, ...maskL.records];if (!maskO) drawMaskList();diff --git a/internal/gui/masking.go b/internal/gui/masking.goindex 1d96ea4f1..fe327d045 100644--- a/internal/gui/masking.go+++ b/internal/gui/masking.go@@ -23,6 +23,8 @@ const valuesMax = 2000// only where it can.type maskedRecord struct {maskrec.Record+ // Key is a string, as gateway.Masked's: a JS number rounds it+ Key int64 `json:"key,string"`Values []maskedValue `json:"values,omitempty"`}@@ -43,7 +45,7 @@ func teller() (gwmw.Teller, bool) {}func shownRecord(r maskrec.Record, t gwmw.Teller) maskedRecord {- out := maskedRecord{Record: r}+ out := maskedRecord{Record: r, Key: r.Key}for _, v := range r.Values {mv := maskedValue{Value: v}if t != nil {diff --git a/internal/gui/masking_test.go b/internal/gui/masking_test.goindex 1b497c2a4..cadc852fa 100644--- a/internal/gui/masking_test.go+++ b/internal/gui/masking_test.go@@ -77,6 +77,15 @@ func TestMaskingRecordsAPI(t *testing.T) {if get("/api/masking/record?key="+strconv.FormatInt(rec.Key, 10), &one); one.Snips[p] != sent || !one.Values[0].Known {t.Fatalf("record %+v", one)}+ // the key goes as a string: a JS number holds a nanosecond key only+ // to 256ns, and the rounded key found no record+ for _, path := range []string{"/api/masking/record?key=" + strconv.FormatInt(rec.Key, 10), "/api/masking/records?limit=1"} {+ rw := httptest.NewRecorder()+ srv.ServeHTTP(rw, httptest.NewRequest("GET", path, nil))+ if !strings.Contains(rw.Body.String(), `"key":"`) {+ t.Fatalf("%s: key not a string: %s", path, rw.Body)+ }+ }if code := get("/api/masking/record?key=1", nil); code != http.StatusNotFound {t.Fatalf("no such record: %d", code)}diff --git a/internal/gui/tests/masking-records.test.cjs b/internal/gui/tests/masking-records.test.cjsindex 3443a1c1c..87f6764ae 100644--- a/internal/gui/tests/masking-records.test.cjs+++ b/internal/gui/tests/masking-records.test.cjs@@ -22,6 +22,9 @@ const { chromium, webkit } = require("playwright");const assets = path.resolve(__dirname, "../assets");const KEY = "{{API_KEY_aaaa1111}}", NAME = "{{PERSON_bbbb2222}}", MAIL = "{{EMAIL_cccc3333}}", PK = "{{PRIVATE_KEY_dddd4444}}";const SECRET = "sk-proj-abcdEFGH1234ijkl", ADDR = "[email protected]";+// a record's key is its time in nanoseconds, past what a JS number holds+// exactly, so the API gives it as a string+const K1 = "1792987654321000001", K2 = "1792987654321000002", K3 = "1792987654321000003", K5 = "1792987654321000005";function day(back) {const d = new Date();@@ -47,21 +50,21 @@ function summary(days) {};}const filler = "x".repeat(900);-// the body 1002 went out with: a long system prompt nothing was masked in,+// the body K2 went out with: a long system prompt nothing was masked in,// and a user message with two valuesconst SENT = JSON.stringify({ model: "claude-opus-4-1", system: "You are Claude Code. " + filler, messages: [{ role: "user", content: [{ type: "text", text: "earlier, unchanged" }] },{ role: "user", content: [{ type: "text", text: `export OPENAI_API_KEY=${KEY} # mail ${MAIL}, again ${KEY}` }] },] });const records = [- { key: 1003, t: ago(60e3), route: "messages", what: "chat", agent: "claude", provider: "anthropic", model: "claude-opus-4-1", n: 1, blocked: true,+ { key: K3, t: ago(60e3), route: "messages", what: "chat", agent: "claude", provider: "anthropic", model: "claude-opus-4-1", n: 1, blocked: true,values: [{ p: PK, k: "PRIVATE_KEY", b: "rule", h: "b3Bl", l: 400, n: 1, a: "block" }],snips: { [PK]: `-----BEGIN OPENSSH PRIVATE KEY----- ${PK}` } },- { key: 1002, t: ago(120e3), route: "messages", what: "chat", agent: "claude", provider: "anthropic", model: "claude-opus-4-1", n: 3, took: 1800, back: { [KEY]: 1 },+ { key: K2, t: ago(120e3), route: "messages", what: "chat", agent: "claude", provider: "anthropic", model: "claude-opus-4-1", n: 3, took: 1800, back: { [KEY]: 1 },values: [{ p: KEY, k: "API_KEY", b: "rule", h: "sk-p", l: 24, n: 2, known: true }, { p: MAIL, k: "EMAIL", b: "rule", h: "a", l: 15, n: 1, known: true }],snips: { [KEY]: `export OPENAI_API_KEY=${KEY} # mail ${MAIL}`, [MAIL]: `…_KEY=${KEY} # mail ${MAIL}` } },// from before a restart: no body, no values in memory- { key: 1001, t: ago(300e3), route: "search", what: "search", agent: "codex", provider: "openai", model: "gpt-5", n: 1,+ { key: K1, t: ago(300e3), route: "search", what: "search", agent: "codex", provider: "openai", model: "gpt-5", n: 1,values: [{ p: NAME, k: "PERSON", b: "model", h: "", l: 3, n: 1 }], snips: { [NAME]: `ask ${NAME} about it` } },];@@ -85,8 +88,8 @@ function serve(lang, sum, asked, opts = {}) {}if (url.pathname === "/api/providers") return json({ providers: [{ id: "anthropic", name: "Anthropic", icon: "anthropic", agents: [], models: [] }, { id: "openai", name: "OpenAI", icon: "openai", agents: [], models: [] }], presets: [], excluded: [],gateway: { running: true, window: true, mine: true, url: "http://127.0.0.1:3999", models: 0, groups: [],- calls: [{ id: 7, time: ago(120e3), agent: "claude", model: "claude-opus-4-1", from: "anthropic", to: "anthropic", status: 200, ms: 900, masked: { n: 3, distinct: 2, kinds: { API_KEY: 2, EMAIL: 1 }, by: { rule: 2 }, key: 1002 } },- { id: 8, time: ago(60e3), agent: "claude", model: "claude-opus-4-1", from: "anthropic", to: "anthropic", status: 200, ms: 700, masked: { n: 0, distinct: 0, warned: 2, key: 1003 } }] } });+ calls: [{ id: 7, time: ago(120e3), agent: "claude", model: "claude-opus-4-1", from: "anthropic", to: "anthropic", status: 200, ms: 900, masked: { n: 3, distinct: 2, kinds: { API_KEY: 2, EMAIL: 1 }, by: { rule: 2 }, key: K2 } },+ { id: 8, time: ago(60e3), agent: "claude", model: "claude-opus-4-1", from: "anthropic", to: "anthropic", status: 200, ms: 700, masked: { n: 0, distinct: 0, warned: 2, key: K3 } }] } });if (url.pathname === "/api/groups") return json({ groups: [], models: [] });if (url.pathname === "/api/plugins") return json({ plugins: [] });if (url.pathname === "/api/privacy-model") return json({ supported: true, installed: false, size: 1.6e9 });@@ -108,12 +111,12 @@ function serve(lang, sum, asked, opts = {}) {return json({ records: rs, more: false });}if (url.pathname === "/api/masking/record") {- const r = (opts.records || records).find((r) => r.key === +url.searchParams.get("key"));+ const r = (opts.records || records).find((r) => r.key === url.searchParams.get("key"));return r ? json(r) : route.fulfill({ status: 404, body: "404 page not found" });}if (url.pathname === "/api/masking/sent") {asked.push("sent " + url.searchParams.get("key"));- const body = opts.sent ? opts.sent[url.searchParams.get("key")] : url.searchParams.get("key") === "1002" && SENT;+ const body = opts.sent ? opts.sent[url.searchParams.get("key")] : url.searchParams.get("key") === K2 && SENT;return body ? json({ body }) : route.fulfill({ status: 404, body: "404 page not found" });}if (url.pathname === "/api/masking/values") {@@ -423,7 +426,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",assert.equal(await page.locator("#activity .call-item.open").count(), 0, "the click wasn't the row's");assert.match(await page.locator("#maskOne .msk-when").textContent(), /\d/);// the tray panel's badge opens the window on key=- await page.goto("http://magpie.test/?view=masking&key=1001");+ await page.goto("http://magpie.test/?view=masking&key=" + K1);await page.locator("#maskOne .msk-gone").waitFor();assert.equal(new URL(page.url()).searchParams.get("key"), null, "read once");// and Settings › Privacy links to the page@@ -439,10 +442,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",// real key against it, as it does a placeholder (#3599)const MADE = "sk_hYQWRBFmdHNIo5XVT2VnIIGh4mmMiJNm", REAL = "sk_w3axCByTQgK1PxqPhfKTrJOLBqz6sbZv";const made = {- records: [{ key: 1005, t: ago(60e3), route: "chat", what: "chat", agent: "codex", provider: "openai", model: "gpt-5", n: 2, back: { [MADE]: 1 },+ records: [{ key: K5, t: ago(60e3), route: "chat", what: "chat", agent: "codex", provider: "openai", model: "gpt-5", n: 2, back: { [MADE]: 1 },values: [{ p: MADE, k: "API_KEY", b: "rule", h: "sk_w", l: 35, n: 2, known: true }],snips: { [MADE]: `OPENAI_API_KEY=${MADE}` } }],- sent: { 1005: JSON.stringify({ model: "gpt-5", messages: [{ role: "user", content: `OPENAI_API_KEY=${MADE} sk_live_other\nonce more: ${MADE}` }] }) },+ sent: { [K5]: JSON.stringify({ model: "gpt-5", messages: [{ role: "user", content: `OPENAI_API_KEY=${MADE} sk_live_other\nonce more: ${MADE}` }] }) },known: { [MADE]: REAL },};for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {