From 0025a6a2d52d0acb752dfe0364bdb94b03d196c1 Mon Sep 17 00:00:00 2001 From: Steven Chong <25894545+teamchong@users.noreply.github.com> Date: Sat, 11 Jul 2026 18:18:27 -0400 Subject: [PATCH] fix(factsheet): prioritize labeled assignments --- src/core/factsheet.ts | 3 +++ tests/factsheet.test.ts | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/core/factsheet.ts b/src/core/factsheet.ts index 6b6f330..e4b4137 100644 --- a/src/core/factsheet.ts +++ b/src/core/factsheet.ts @@ -17,6 +17,7 @@ /** ReDoS-safe extraction patterns (each global). Ordered most- to least-specific so the * longest, most-identifying tokens are kept first when the substring filter runs. */ const PATTERNS: readonly RegExp[] = [ + /\b[A-Z][A-Z0-9_]{2,}=[^\s)"'<>]+/g, // semantic LABEL=value pair (preserve association) /\bhttps?:\/\/[^\s)"'<>]+/g, // URLs /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/g, // UUID /(?:[\w@~+-]+)?(?:\/[\w.@+-]+)+\.[A-Za-z]\w{0,8}\b/g, // path with a file extension (multi-dot ok: .test.ts) @@ -62,10 +63,12 @@ const SHAPE_FLAG = /^--?[A-Za-z][\w-]+$/; // CLI flag const SHAPE_NUM = /^\d[\d,_]*$|^\d+\.\d+$/; // port / large or separated number / decimal const SHAPE_URL = /^https?:\/\//; const SHAPE_CAMEL = /^(?:[a-z]+|[A-Z][a-z0-9]+)(?:[A-Z][a-z0-9]*)+$/; // tokenLedgerShard / getUserById +const SHAPE_ASSIGNMENT = /^[A-Z][A-Z0-9_]{2,}=\S+$/; // ACTIVE_MANIFEST=/path /** Lower tier = higher keep-priority. Pure function of the token → deterministic. */ function priorityTier(tok: string): 0 | 1 | 2 { if ( + SHAPE_ASSIGNMENT.test(tok) || SHAPE_HEX.test(tok) || SHAPE_UUID.test(tok) || SHAPE_CONST.test(tok) || diff --git a/tests/factsheet.test.ts b/tests/factsheet.test.ts index 7583012..3b542ad 100644 --- a/tests/factsheet.test.ts +++ b/tests/factsheet.test.ts @@ -50,6 +50,27 @@ describe('factsheet extraction', () => { expect(extractFactSheetTokens(many).length).toBeLessThanOrEqual(96); }); + it('prioritizes uppercase-labeled assignment values over anonymous hex log noise', () => { + const noise = Array.from({ length: 180 }, (_, i) => + `trace8=${(0x10000000 + i * 7919).toString(16)} queue=${10000 + i}`, + ); + const targetPath = '/srv/sol-pilot/releases/alpha-07/config/runtime-map.json'; + const text = [ + ...noise.slice(0, 60), + 'DEPLOYMENT_FINGERPRINT=c7a1e90b4d2f', + 'RUNTIME_FIELD=retryBudgetSeconds', + `ACTIVE_MANIFEST=${targetPath}`, + 'CONTROL_PORT=47831', + ...noise.slice(60), + ].join('\n'); + const toks = extractFactSheetTokens(text); + expect(toks).toContain('DEPLOYMENT_FINGERPRINT=c7a1e90b4d2f'); + expect(toks).toContain('RUNTIME_FIELD=retryBudgetSeconds'); + expect(toks).toContain(`ACTIVE_MANIFEST=${targetPath}`); + expect(toks).toContain('CONTROL_PORT=47831'); + expect(toks.length).toBeLessThanOrEqual(96); + }); + it('protects short high-consequence tokens from eviction by long URLs', () => { // 80 long doc-URLs (well over the 96-token budget) plus a short commit SHA and a port — // the exact shape that silently dropped the SHA a coding agent needed off the image.