Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.
redact: the masking eval scores each local model (#3578)
yetone89a9ded2cc41
diff --git a/internal/redact/eval_cases_test.go b/internal/redact/eval_cases_test.goindex 01153e0c3..88a67bf8a 100644--- a/internal/redact/eval_cases_test.go+++ b/internal/redact/eval_cases_test.go@@ -10,8 +10,9 @@ type evalCase struct {// evalValue is a value in a case's text. Kind is what it is, or for one// to keep what it was or could be taken for. Known, where set, is the-// issue of a value that comes out wrong with the rules and the model.-type evalValue struct{ V, Kind, Known string }+// issue of a value that comes out wrong with the rules and Privacy+// Filter; GuardKnown, with the rules and AstrLink Guard.+type evalValue struct{ V, Kind, Known, GuardKnown string }// The keys are made up, in the vendors' shapes; the people, places and// numbers are made up or the ones vendors and standards give as examples.@@ -89,7 +90,7 @@ var evalCases = []evalCase{{ID: "token-count", From: "611b9e173",Text: "<system-reminder><total_tokens>14902266 tokens left</total_tokens></system-reminder>",- Keep: []evalValue{{V: "14902266", Kind: "ACCOUNT"}},+ Keep: []evalValue{{V: "14902266", Kind: "ACCOUNT", GuardKnown: "#3775"}},},{ID: "assistant-names", From: "611b9e173",@@ -391,7 +392,7 @@ var evalCases = []evalCase{{ID: "tool-result-mixed", From: "true",Text: "$ cat contacts.csv\nname,email,phone\nRina Kobayashi,[email protected],+81 90-1234-5678\nOmar Haddad,[email protected],+44 7700 900123",- Mask: []evalValue{{V: "Rina Kobayashi", Kind: "PERSON"}, {V: "[email protected]", Kind: "EMAIL"}, {V: "90-1234-5678", Kind: "PHONE"}, {V: "Omar Haddad", Kind: "PERSON"}, {V: "[email protected]", Kind: "EMAIL"}, {V: "7700 900123", Kind: "PHONE"}},+ Mask: []evalValue{{V: "Rina Kobayashi", Kind: "PERSON"}, {V: "[email protected]", Kind: "EMAIL"}, {V: "90-1234-5678", Kind: "PHONE", GuardKnown: "#3776"}, {V: "Omar Haddad", Kind: "PERSON"}, {V: "[email protected]", Kind: "EMAIL"}, {V: "7700 900123", Kind: "PHONE"}},Keep: []evalValue{{V: "contacts.csv", Kind: "EMAIL"}},},}diff --git a/internal/redact/eval_test.go b/internal/redact/eval_test.goindex 66e833339..5937529ff 100644--- a/internal/redact/eval_test.go+++ b/internal/redact/eval_test.go@@ -1,6 +1,7 @@package redact_testimport (+ "context""crypto/sha256""encoding/hex""encoding/json"@@ -28,25 +29,53 @@ import (// - both: the rules and the model with magpie's checks on what it found,// as a user with the model on gets.//-// What the model said is recorded in testdata/eval-model.json, so the-// test runs the whole of "both" without the model or the network, and-// fails when a value that came out right comes out wrong. A value known-// to come out wrong says so (evalValue.Known, an issue), and fails once-// it comes out right, to have its Known taken off.+// Each local model (pii.Models) is scored on its own. What it said is+// recorded in testdata (evalModels), so the test runs the whole of+// "both" without the model or the network, and fails when a value that+// came out right comes out wrong. A value known to come out wrong with a+// model says so (evalValue.Known for Privacy Filter, GuardKnown for+// AstrLink Guard, an issue), and fails once it comes out right, to have+// it taken off.//-// To ask the real model again, after a case is added or a new model,-// point MAGPIE_EVAL_CACHE at the cache folder it was downloaded into-// (the folder that holds magpie/privacy-filter):+// To ask the real models again, after a case is added or a new model,+// point MAGPIE_EVAL_CACHE at the cache folder they were downloaded into+// (the folder that holds magpie/privacy-filter, magpie/astrlink-guard);+// each one there is asked://// MAGPIE_EVAL_CACHE=$HOME/.cache go test -run TestMaskEval -v ./internal/redact//// which writes the recording again and logs the table.func TestMaskEval(t *testing.T) {- rec := readRecording(t)- if dir := os.Getenv("MAGPIE_EVAL_CACHE"); dir != "" {- rec = askModel(t, dir)- writeRecording(t, rec)+ asked := 0+ for _, em := range evalModels {+ t.Run(em.id, func(t *testing.T) {+ rec := readRecording(t, em.path)+ if dir := os.Getenv("MAGPIE_EVAL_CACHE"); dir != "" {+ if r, ok := askModel(t, dir, pii.Of(em.id)); ok {+ rec = r+ writeRecording(t, em.path, rec)+ asked+++ }+ }+ evalModel(t, rec, em.known)+ })+ }+ if os.Getenv("MAGPIE_EVAL_CACHE") != "" && asked == 0 {+ t.Fatal("no model is in MAGPIE_EVAL_CACHE")}+}++// evalModels are the local models, each with its recording and the+// values known to come out wrong with it.+var evalModels = []struct {+ id, path string+ known func(evalValue) string+}{+ {pii.PrivacyFilter, "testdata/eval-model.json", func(v evalValue) string { return v.Known }},+ {pii.AstrLinkGuard, "testdata/eval-astrlink.json", func(v evalValue) string { return v.GuardKnown }},+}++func evalModel(t *testing.T, rec map[string]recorded, known func(evalValue) string) {var stale []stringfor _, c := range evalCases {if r, ok := rec[c.ID]; !ok || r.Text != textHash(c.Text) {@@ -74,10 +103,10 @@ func TestMaskEval(t *testing.T) {rules := redact.Preview(c.Text, redact.Options{Secrets: true, Personal: true})both := redact.Preview(c.Text, redact.Options{Secrets: true, Personal: true, Model: replay})for _, v := range c.Mask {- checkValue(t, c, v, true, &tally, gone(rules, v.V), modelFound(c.Text, v.V, rec[c.ID].Found), gone(both, v.V))+ checkValue(t, c, v, known(v), true, &tally, gone(rules, v.V), modelFound(c.Text, v.V, rec[c.ID].Found), gone(both, v.V))}for _, v := range c.Keep {- checkValue(t, c, v, false, &tally, gone(rules, v.V), modelFound(c.Text, v.V, rec[c.ID].Found), gone(both, v.V))+ checkValue(t, c, v, known(v), false, &tally, gone(rules, v.V), modelFound(c.Text, v.V, rec[c.ID].Found), gone(both, v.V))}}t.Log("\n" + tally.table())@@ -85,16 +114,16 @@ func TestMaskEval(t *testing.T) {// checkValue counts one value in each way, and holds "both" to what the// case says of it.-func checkValue(t *testing.T, c evalCase, v evalValue, mask bool, tally *evalTally, rules, model, both bool) {+func checkValue(t *testing.T, c evalCase, v evalValue, known string, mask bool, tally *evalTally, rules, model, both bool) {t.Helper()tally.add(v.Kind, mask, rules, model, both)if rules != mask || model != mask || both != mask {tally.wrong = append(tally.wrong, fmt.Sprintf("%-18s %-6s %-7s %-5s %-5s %-5s %q",c.ID, map[bool]string{true: "mask", false: "keep"}[mask], v.Kind, mark(rules == mask), mark(model == mask), mark(both == mask), v.V))}- if v.Known != "" {+ if known != "" {if both == mask {- t.Errorf("%s: %q now comes out right; take its Known (%s) off", c.ID, v.V, v.Known)+ t.Errorf("%s: %q now comes out right; take its known issue (%s) off", c.ID, v.V, known)}return}@@ -221,8 +250,6 @@ func frac(n, of int) string {// ---- the recording -----------------------------------------------------------const recordingPath = "testdata/eval-model.json"-// recorded is what the model found in one case's text, and the text's// hash, to tell a recording made of another text.type recorded struct {@@ -235,7 +262,7 @@ func textHash(s string) string {return hex.EncodeToString(h[:8])}-func readRecording(t *testing.T) map[string]recorded {+func readRecording(t *testing.T, recordingPath string) map[string]recorded {rec := map[string]recorded{}b, err := os.ReadFile(recordingPath)if os.IsNotExist(err) {@@ -250,7 +277,7 @@ func readRecording(t *testing.T) map[string]recorded {return rec}-func writeRecording(t *testing.T, rec map[string]recorded) {+func writeRecording(t *testing.T, recordingPath string, rec map[string]recorded) {b, err := json.MarshalIndent(rec, "", "\t")if err != nil {t.Fatal(err)@@ -264,18 +291,19 @@ func writeRecording(t *testing.T, rec map[string]recorded) {}}-// askModel runs every case's text through the real model, downloaded+// askModel runs every case's text through the real model m, downloaded// into the cache folder dir, one text at a time, as a request's text-// that has the model to itself is.-func askModel(t *testing.T, dir string) map[string]recorded {+// that has the model to itself is; false if m isn't there.+func askModel(t *testing.T, dir string, m pii.Model) (map[string]recorded, bool) {t.Setenv("XDG_CACHE_HOME", dir)- if !pii.Installed() {- t.Fatalf("the model isn't in %s", filepath.Join(dir, "magpie", "privacy-filter"))+ if !m.Installed() {+ t.Logf("%s isn't in %s; its recording is kept", m.ID(), filepath.Join(dir, "magpie"))+ return nil, false}- defer pii.Stop()+ defer m.Stop()rec := map[string]recorded{}for _, c := range evalCases {- got, err := pii.Find([]string{c.Text})+ got, err := m.Find(context.Background(), []string{c.Text})if err != nil {t.Fatalf("%s: %v", c.ID, err)}@@ -285,5 +313,5 @@ func askModel(t *testing.T, dir string) map[string]recorded {}rec[c.ID] = recorded{Text: textHash(c.Text), Found: fs}}- return rec+ return rec, true}diff --git a/internal/redact/testdata/eval-astrlink.json b/internal/redact/testdata/eval-astrlink.jsonnew file mode 100644index 000000000..856159dde--- /dev/null+++ b/internal/redact/testdata/eval-astrlink.json@@ -0,0 +1,593 @@+{+ "asset-files": {+ "text": "8b019ca5e2af716b",+ "found": []+ },+ "assistant-names": {+ "text": "6f312259162fb240",+ "found": []+ },+ "assistant-prose": {+ "text": "2f09c57d2bcd4a33",+ "found": [+ {+ "Start": 57,+ "End": 64,+ "Label": "private_person"+ }+ ]+ },+ "background-tasks": {+ "text": "1a8c290d9137f372",+ "found": []+ },+ "base64-image": {+ "text": "88418a5daf6d9b9a",+ "found": []+ },+ "bearer": {+ "text": "708d72f298141a4c",+ "found": [+ {+ "Start": 31,+ "End": 148,+ "Label": "secret"+ },+ {+ "Start": 150,+ "End": 180,+ "Label": "private_url"+ }+ ]+ },+ "card": {+ "text": "7387f43ca5ce5824",+ "found": [+ {+ "Start": 30,+ "End": 49,+ "Label": "account_number"+ },+ {+ "Start": 58,+ "End": 63,+ "Label": "private_date"+ }+ ]+ },+ "ci-table": {+ "text": "059b37d552df2314",+ "found": []+ },+ "code-keys": {+ "text": "d5f835bbf0a332b8",+ "found": [+ {+ "Start": 67,+ "End": 108,+ "Label": "secret"+ },+ {+ "Start": 135,+ "End": 175,+ "Label": "secret"+ }+ ]+ },+ "code-locations": {+ "text": "ebbde1d7b5199206",+ "found": []+ },+ "codex-meta": {+ "text": "4978726969792675",+ "found": [+ {+ "Start": 155,+ "End": 169,+ "Label": "private_person"+ },+ {+ "Start": 240,+ "End": 253,+ "Label": "secret"+ }+ ]+ },+ "colors-ports": {+ "text": "252b9ce2e8df3e82",+ "found": [+ {+ "Start": 45,+ "End": 54,+ "Label": "ip_address"+ }+ ]+ },+ "commit-login": {+ "text": "43e1522fcf559a62",+ "found": [+ {+ "Start": 56,+ "End": 62,+ "Label": "account_number"+ },+ {+ "Start": 64,+ "End": 95,+ "Label": "private_email"+ }+ ]+ },+ "digests": {+ "text": "3b3e688a54f12e96",+ "found": []+ },+ "env-file": {+ "text": "c1f1a7ab84f78373",+ "found": [+ {+ "Start": 15,+ "End": 63,+ "Label": "secret"+ },+ {+ "Start": 76,+ "End": 90,+ "Label": "secret"+ }+ ]+ },+ "event-times": {+ "text": "c1fe2fbd2701c75c",+ "found": [+ {+ "Start": 112,+ "End": 127,+ "Label": "private_phone"+ }+ ]+ },+ "example-mail": {+ "text": "a1867625846dc315",+ "found": [+ {+ "Start": 14,+ "End": 30,+ "Label": "private_email"+ }+ ]+ },+ "gateway-ids": {+ "text": "e911ab18a1116ef5",+ "found": []+ },+ "git-author": {+ "text": "94a966005e2adee1",+ "found": [+ {+ "Start": 23,+ "End": 33,+ "Label": "private_person"+ },+ {+ "Start": 35,+ "End": 55,+ "Label": "private_email"+ }+ ]+ },+ "git-log": {+ "text": "8fc8f17e8817539a",+ "found": []+ },+ "git-user-url": {+ "text": "b92e10fa6b923a00",+ "found": [+ {+ "Start": 10,+ "End": 55,+ "Label": "private_url"+ }+ ]+ },+ "go-caches": {+ "text": "e855cf322da328a9",+ "found": []+ },+ "grep-alts": {+ "text": "dab9d9ae2f7b6d01",+ "found": []+ },+ "grep-pattern": {+ "text": "0d38dbff0a086bdf",+ "found": []+ },+ "hex-lines": {+ "text": "b378b2965f1a80de",+ "found": []+ },+ "home-path": {+ "text": "4f79a2f3631db506",+ "found": []+ },+ "iban": {+ "text": "cf32ccaec3a1dfc1",+ "found": [+ {+ "Start": 24,+ "End": 51,+ "Label": "account_number"+ }+ ]+ },+ "json-contact": {+ "text": "8b8300472a287a74",+ "found": [+ {+ "Start": 21,+ "End": 30,+ "Label": "private_person"+ },+ {+ "Start": 41,+ "End": 62,+ "Label": "private_email"+ },+ {+ "Start": 73,+ "End": 90,+ "Label": "private_phone"+ }+ ]+ },+ "json-settings": {+ "text": "17b49a014daba2fc",+ "found": []+ },+ "log-user": {+ "text": "cda01fa1bd419b1d",+ "found": [+ {+ "Start": 40,+ "End": 52,+ "Label": "private_email"+ },+ {+ "Start": 68,+ "End": 76,+ "Label": "ip_address"+ }+ ]+ },+ "ls-files": {+ "text": "df52e0f6fb986b33",+ "found": []+ },+ "metric-decimals": {+ "text": "36c335311d2812ab",+ "found": []+ },+ "model-names": {+ "text": "1ddc9e9ff3476549",+ "found": []+ },+ "noreply": {+ "text": "271c7650b6474a19",+ "found": []+ },+ "one-letter": {+ "text": "0ff1555b12fd8004",+ "found": []+ },+ "phone-intl": {+ "text": "28bf596367da1b2b",+ "found": [+ {+ "Start": 36,+ "End": 39,+ "Label": "private_person"+ },+ {+ "Start": 43,+ "End": 58,+ "Label": "private_phone"+ }+ ]+ },+ "pixels": {+ "text": "96d207f1a0461a94",+ "found": []+ },+ "pr-checks": {+ "text": "e95e64e5f1c74ae9",+ "found": [+ {+ "Start": 67,+ "End": 103,+ "Label": "private_url"+ }+ ]+ },+ "prose-password": {+ "text": "b45e2539ee55a672",+ "found": [+ {+ "Start": 27,+ "End": 38,+ "Label": "secret"+ }+ ]+ },+ "prose-person": {+ "text": "7090b229a3288b42",+ "found": [+ {+ "Start": 13,+ "End": 27,+ "Label": "private_person"+ }+ ]+ },+ "retina-file": {+ "text": "6210ece83f6b71ab",+ "found": []+ },+ "run-ids": {+ "text": "eb2807913ed4300b",+ "found": [+ {+ "Start": 46,+ "End": 98,+ "Label": "private_url"+ }+ ]+ },+ "rust-toolchain": {+ "text": "5e982c7d912ab858",+ "found": []+ },+ "session-tokens": {+ "text": "6170ea7af28ec9e2",+ "found": [+ {+ "Start": 51,+ "End": 83,+ "Label": "secret"+ }+ ]+ },+ "session-uuid": {+ "text": "45ff8afdbe77e369",+ "found": []+ },+ "settings-model": {+ "text": "24b9db62bf272ec3",+ "found": [+ {+ "Start": 26,+ "End": 31,+ "Label": "secret"+ },+ {+ "Start": 85,+ "End": 110,+ "Label": "private_url"+ }+ ]+ },+ "short-values": {+ "text": "0133fede621b7801",+ "found": []+ },+ "sizes-versions": {+ "text": "e08a850f552a995b",+ "found": []+ },+ "skill-list": {+ "text": "535fc5de908c39dd",+ "found": []+ },+ "snake-arg": {+ "text": "7ade5b7b89a61dd4",+ "found": []+ },+ "snake-words": {+ "text": "89fcc6da0d4cc9fb",+ "found": []+ },+ "task-ids": {+ "text": "faff967171e2421d",+ "found": []+ },+ "team-notes": {+ "text": "6141f843b721d582",+ "found": [+ {+ "Start": 41,+ "End": 55,+ "Label": "private_person"+ },+ {+ "Start": 118,+ "End": 123,+ "Label": "private_person"+ }+ ]+ },+ "token-count": {+ "text": "359c740b1ce9a3c5",+ "found": [+ {+ "Start": 31,+ "End": 39,+ "Label": "secret"+ }+ ]+ },+ "tool-ids": {+ "text": "50c8c97e610d704c",+ "found": []+ },+ "tool-result-mixed": {+ "text": "f5a49344e0e7f392",+ "found": [+ {+ "Start": 36,+ "End": 50,+ "Label": "private_person"+ },+ {+ "Start": 51,+ "End": 70,+ "Label": "private_email"+ },+ {+ "Start": 88,+ "End": 99,+ "Label": "private_person"+ },+ {+ "Start": 100,+ "End": 121,+ "Label": "private_email"+ },+ {+ "Start": 122,+ "End": 137,+ "Label": "private_phone"+ }+ ]+ },+ "tool-servers": {+ "text": "6b9515c4bf396f51",+ "found": []+ },+ "tool-use-ids": {+ "text": "c83ab5e49cce4b75",+ "found": []+ },+ "transcript-path": {+ "text": "28861a2d1fee2589",+ "found": []+ },+ "unix-time": {+ "text": "3e3d22cf38729962",+ "found": []+ },+ "unix-time-ms": {+ "text": "7e29836c6aa4f105",+ "found": []+ },+ "url-login": {+ "text": "d6f5b2b60e384bb9",+ "found": [+ {+ "Start": 10,+ "End": 58,+ "Label": "private_url"+ }+ ]+ },+ "url-userinfo": {+ "text": "a74a01c8225d54da",+ "found": [+ {+ "Start": 13,+ "End": 67,+ "Label": "private_url"+ }+ ]+ },+ "us-address": {+ "text": "d73e7386a905373e",+ "found": [+ {+ "Start": 24,+ "End": 68,+ "Label": "private_address"+ },+ {+ "Start": 78,+ "End": 92,+ "Label": "private_phone"+ }+ ]+ },+ "user-path": {+ "text": "007eeda2f5ba95d3",+ "found": []+ },+ "zh-contact": {+ "text": "5d654b2bbdd23aa1",+ "found": [+ {+ "Start": 12,+ "End": 18,+ "Label": "private_person"+ },+ {+ "Start": 28,+ "End": 39,+ "Label": "private_phone"+ },+ {+ "Start": 51,+ "End": 93,+ "Label": "private_address"+ }+ ]+ },+ "zh-id": {+ "text": "f058f91bb1800cbe",+ "found": []+ },+ "zh-names-edge": {+ "text": "709d9aa01117e001",+ "found": [+ {+ "Start": 18,+ "End": 27,+ "Label": "private_person"+ },+ {+ "Start": 51,+ "End": 57,+ "Label": "private_person"+ }+ ]+ },+ "zh-password": {+ "text": "ca3835176b202e40",+ "found": [+ {+ "Start": 19,+ "End": 29,+ "Label": "secret"+ }+ ]+ },+ "zh-prose": {+ "text": "c75e8925f3dddfc7",+ "found": [+ {+ "Start": 0,+ "End": 6,+ "Label": "private_person"+ },+ {+ "Start": 6,+ "End": 15,+ "Label": "private_date"+ },+ {+ "Start": 66,+ "End": 72,+ "Label": "private_person"+ }+ ]+ },+ "zh-words": {+ "text": "dfccf70c683fe55b",+ "found": []+ }+}