Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
keep each redaction consumer's output vocabulary when sharing the pattern list (#7474)
[._.]/ Adam Eivy45715b86e40a
diff --git a/server/lib/piiRedactionPatterns.js b/server/lib/piiRedactionPatterns.jsindex 6736be27f3..38c1d8bc76 100644--- a/server/lib/piiRedactionPatterns.js+++ b/server/lib/piiRedactionPatterns.js@@ -57,17 +57,57 @@ export const PII_PATTERNS = Object.freeze([Object.freeze({ code: 'gps-coordinate', pattern: /\b(latitude|longitude|lat|lon|lng)\s*[:=]\s*-?\d{1,3}(?:\.\d+)?/i, replacement: '$1=[REDACTED]' }),]);+/**+ * Replacement vocabularies, keyed by pattern `code`.+ *+ * The two redaction consumers converge on the PATTERNS above — that is the+ * drift #7474 exists to kill — but they deliberately keep DIFFERENT output+ * text, because each one is an observable contract something already depends+ * on. `agentContextMcp` emits bracketed `[REDACTED X]` markers that the+ * critical `search-redacts-and-omits-fields` case in+ * `test/fixtures/agent-context-eval.json` pins by value, and it collapses a+ * home path to `~` rather than naming the OS convention. `agentErrorAnalysis`+ * emits terse `<x>` placeholders that read well inside a one-line log+ * snippet. Folding those onto one vocabulary silently rewrote every marker the+ * MCP tool emits — a behaviour change well outside "share the pattern list",+ * and one a critical privacy eval is there to catch.+ *+ * A code omitted from a vocabulary falls back to the table's own+ * `replacement`, so adding a pattern never silently un-redacts a consumer.+ */+export const PII_REPLACEMENTS = Object.freeze({+ // `agentContextMcp.js#redactAgentContextText` — MCP search/summary payloads.+ bracketed: Object.freeze({+ 'home-path': '~',+ 'windows-path': '~',+ 'ip-literal': '[REDACTED IP]',+ 'network-host': '[REDACTED HOST]',+ 'mac-address': '[REDACTED MAC]',+ 'email-address': '[REDACTED EMAIL]',+ 'phone-number': '[REDACTED PHONE]',+ }),+ // `agentErrorAnalysis.js#redactFailureSnippet` — one-line failure snippets.+ // Every code takes the table default, so this is deliberately empty rather+ // than a second copy of the defaults that could drift from them.+ terse: Object.freeze({}),+});+/** A global-flagged copy of `pattern`, safe for a `.replace()` caller to reuse. */export function globalPattern(pattern) {return new RegExp(pattern.source, pattern.flags.includes('g') ? pattern.flags : `${pattern.flags}g`);}/**- * Apply every `{ pattern, replacement }` entry in `PII_PATTERNS` to `text`, in- * table order. Shared by both redaction consumers so a correction to the- * table (or the order patterns apply in) reaches both without a second copy- * of this loop.+ * Apply every entry in `PII_PATTERNS` to `text`, in table order. Shared by+ * both redaction consumers so a correction to the table (or the order+ * patterns apply in) reaches both without a second copy of this loop.+ *+ * `vocabulary` picks the output text (see `PII_REPLACEMENTS`); a code it does+ * not name falls back to that entry's own `replacement`.*/-export function redactPii(text) {- return PII_PATTERNS.reduce((out, { pattern, replacement }) => out.replace(globalPattern(pattern), replacement), text);+export function redactPii(text, vocabulary = PII_REPLACEMENTS.terse) {+ return PII_PATTERNS.reduce(+ (out, { code, pattern, replacement }) => out.replace(globalPattern(pattern), vocabulary[code] ?? replacement),+ text,+ );}diff --git a/server/lib/piiRedactionPatterns.test.js b/server/lib/piiRedactionPatterns.test.jsindex 35924c006c..9bf601c821 100644--- a/server/lib/piiRedactionPatterns.test.js+++ b/server/lib/piiRedactionPatterns.test.js@@ -9,7 +9,7 @@* `.test()` calls without a stateful `lastIndex` bug.*/import { describe, expect, it } from 'vitest';-import { PII_PATTERNS, globalPattern, redactPii } from './piiRedactionPatterns.js';+import { PII_PATTERNS, PII_REPLACEMENTS, globalPattern, redactPii } from './piiRedactionPatterns.js';// One sample per CODE the table declares (not per pattern — `ip-literal`// covers both an IPv4 and an IPv6 entry, exercised separately below). If a@@ -66,6 +66,44 @@ describe('PII_PATTERNS / redactPii', () => {expect(emailPattern.test('[email protected]')).toBe(true);});+ it('keeps each consumer output vocabulary intact while sharing one pattern list', () => {+ // The first cut of #7474 shared the patterns AND the replacement text,+ // which silently rewrote every marker agentContextMcp emits — caught only+ // by the critical `search-redacts-and-omits-fields` eval case. Sharing+ // patterns is the goal; sharing output text is a behaviour change.+ const sample = 'mail [email protected] from /Users/alice/notes on 192.0.2.10 via node.tailnet.ts.net';++ const bracketed = redactPii(sample, PII_REPLACEMENTS.bracketed);+ expect(bracketed).toContain('[REDACTED EMAIL]');+ expect(bracketed).toContain('[REDACTED IP]');+ expect(bracketed).toContain('[REDACTED HOST]');+ expect(bracketed).toContain('~');+ expect(bracketed).not.toContain('<email>');++ const terse = redactPii(sample);+ expect(terse).toContain('<email>');+ expect(terse).toContain('<ip>');+ expect(terse).toContain('<host>');+ expect(terse).not.toContain('[REDACTED EMAIL]');++ // Whichever vocabulary is in play, nothing sensitive survives either one.+ for (const out of [bracketed, terse]) {+ expect(out).not.toContain('[email protected]');+ expect(out).not.toContain('/Users/alice');+ expect(out).not.toContain('192.0.2.10');+ expect(out).not.toContain('node.tailnet.ts.net');+ }+ });++ it('falls back to the table replacement for a code a vocabulary does not name, so a new pattern is never silently un-redacted', () => {+ // The bypass probe for the fallback: a vocabulary that names nothing must+ // still redact every shape, or adding a pattern to the table would leave+ // a consumer emitting the raw value.+ const out = redactPii('reach [email protected] at 192.0.2.10', {});+ expect(out).not.toContain('[email protected]');+ expect(out).not.toContain('192.0.2.10');+ });+it('globalPattern derives a replace-safe copy without mutating the shared regex object', () => {const homePathPattern = PII_PATTERNS.find((entry) => entry.code === 'home-path').pattern;const asGlobal = globalPattern(homePathPattern);diff --git a/server/services/agentContextMcp.js b/server/services/agentContextMcp.jsindex 4a92307be9..367efa2498 100644--- a/server/services/agentContextMcp.js+++ b/server/services/agentContextMcp.js@@ -4,7 +4,7 @@ import { BRAIN_SEARCH_TYPES, getBrainProjections } from './brainSearchIndex.js';import { listContexts } from './workspaceContext.js';import { previewLegacyExport, redactSecrets } from './legacyExport.js';import { NAV_COMMANDS, resolveNavCommand } from '../lib/navManifest.js';-import { redactPii } from '../lib/piiRedactionPatterns.js';+import { PII_REPLACEMENTS, redactPii } from '../lib/piiRedactionPatterns.js';import {AGENT_CONTEXT_DEFAULT_SCOPES,AGENT_CONTEXT_DEFAULT_ACTIONS,@@ -37,7 +37,10 @@ const normalizedText = (value) => String(value ?? '').replace(/\s+/g, ' ').trim(const searchableText = (value) => normalizedText(value).slice(0, 2_000);export function redactAgentContextText(value) {- return cap(redactPii(redactSecrets(normalizedText(value))), AGENT_CONTEXT_LIMITS.maxSummaryChars);+ return cap(+ redactPii(redactSecrets(normalizedText(value)), PII_REPLACEMENTS.bracketed),+ AGENT_CONTEXT_LIMITS.maxSummaryChars,+ );}export function resolveAgentContextConfig(settings = {}) {diff --git a/server/services/agentContextMcp.test.js b/server/services/agentContextMcp.test.jsindex b034367a6c..e3a21a18f4 100644--- a/server/services/agentContextMcp.test.js+++ b/server/services/agentContextMcp.test.js@@ -167,11 +167,12 @@ describe('agentContextMcp service', () => {}]);const result = await callAgentContextTool('list_context', { scope: 'brain' });const serialized = JSON.stringify(result);- // Canonical redaction tokens moved to the shared table's placeholders- // (#7474) — the strings themselves are no longer this service's own,- // but the leak-proofing the assertions below check is unchanged.- expect(serialized).toContain('<email>');- expect(serialized).toContain('<ip>');+ // The bracketed vocabulary is this tool's OWN observable contract, not an+ // incidental spelling: the critical `search-redacts-and-omits-fields` case+ // in test/fixtures/agent-context-eval.json pins these exact markers. #7474+ // shares the PATTERNS with agentErrorAnalysis, never the output text.+ expect(serialized).toContain('[REDACTED EMAIL]');+ expect(serialized).toContain('[REDACTED IP]');expect(serialized).not.toContain('[email protected]');expect(serialized).not.toContain('/Users/alice');expect(serialized).not.toContain('sk-12345678901234567890');