🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(ruflo-mods): key-assignment rule is linear and ends at the credential name; windows start at whitespace (#3798)
Dragan Spiridonove281da31a46a
diff --git a/plugins/ruflo-mods/hooks/guidance/screen.ts b/plugins/ruflo-mods/hooks/guidance/screen.tsindex ee55564273..d6f75a9d8f 100644--- a/plugins/ruflo-mods/hooks/guidance/screen.ts+++ b/plugins/ruflo-mods/hooks/guidance/screen.ts@@ -12,8 +12,10 @@ const SECRETS: readonly (readonly [string, RegExp])[] = [['anthropic or openai key', /\bsk-(?:ant-|proj-)?[A-Za-z0-9_-]{24,}/],['jwt', /\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/],['bearer token', /\bBearer\s+[A-Za-z0-9._~+/=-]{24,}/],- // The keyword may sit inside an _ or - separated name: GITHUB_TOKEN=, aws_secret_access_key =, "client_secret":.- ['key assignment', /(?<![A-Za-z0-9_-])(?:[A-Za-z0-9]+[_-])*(?:api[_-]?key|secret|token|passw(?:or)?d|credential)s?(?:[_-][A-Za-z0-9]+)*["']?\s*[:=]\s*["']?[A-Za-z0-9/+=_.-]{16,}/i],+ // The keyword ends an _ or - separated name (GITHUB_TOKEN=, "client_secret":), optionally then _key / _access_key+ // (aws_secret_access_key =). Names that only start with it (TOKEN_URL=, MAX_TOKENS=) and all-digit values do not+ // match, and nothing after the keyword can backtrack against it (linear on 'token_token_...').+ ['key assignment', /(?<![A-Za-z0-9_-])(?:[A-Za-z0-9]+[_-])*(?:api[_-]?key|secret|token|passw(?:or)?d|credential)s?(?:[_-](?:access[_-]?)?key)?["']?\s*[:=]\s*["']?(?=[A-Za-z0-9/+=_.-]*[A-Za-z])[A-Za-z0-9/+=_.-]{16,}/i],]const INJECTION: readonly (readonly [string, RegExp])[] = [@@ -46,7 +48,10 @@ export function windows(text: string): string[] {if (clean.length <= WINDOW) return [clean]const out: string[] = []for (let start = 0; start < clean.length; start += WINDOW - OVERLAP) {- out.push(clean.slice(start, start + WINDOW))+ // A later window starts after whitespace, so a rule's lookbehind, \b and ^ never see a word cut in half.+ const ws = start === 0 ? -1 : clean.slice(start, start + 256).search(/\s/)+ const from = ws >= 0 ? start + ws + 1 : start+ out.push(clean.slice(from, start + WINDOW))if (start + WINDOW >= clean.length) break}return outdiff --git a/plugins/ruflo-mods/tests/delivery.test.ts b/plugins/ruflo-mods/tests/delivery.test.tsindex c699d0c0c1..e21e73c74d 100644--- a/plugins/ruflo-mods/tests/delivery.test.ts+++ b/plugins/ruflo-mods/tests/delivery.test.ts@@ -120,6 +120,33 @@ describe('screen coverage: prefixed keys, padding, invisible characters, more sefor (const t of ['tokenizer: bert-base-uncased-model-v2', 'max_tokens: 4096', 'the secretary: Josephine-Baker-Smith']) expect(screenOutbound(t), t).toBeUndefined()})+ test('config names that merely start with a keyword, and all-digit values, are not credentials', () => {+ for (const t of [+ 'token_count = 1234567890123456', 'MAX_TOKENS=1000000000000000000', 'session_token_ttl=86400000000000000',+ 'TOKEN_URL=/api/v1/oauth/token/refresh', 'CREDENTIALS_FILE=/etc/app/credentials.json', 'SECRET_MANAGER_PROJECT=cognitum-20260110',+ 'password_reset_path: /users/password/reset/confirm', 'api_key_header: X-Api-Key-Header-Name', 'password_hash_algorithm: argon2id-v19-memory-cost',+ ]) expect(screenOutbound(t), t).toBeUndefined()+ for (const t of ['SECRET_KEY=abcdefghijklmnop0123', 'api_key: "abcdef0123456789abcdef"']) expect(screenOutbound(t), t).toBe('key assignment')+ })++ test('the key rule stays linear on adversarial names (no backtracking blow-up)', () => {+ for (const unit of ['token_', 'token-', 'tokens_', 'api_key_', 'a_secret_']) {+ const t0 = Date.now()+ expect(screenOutbound(unit.repeat(Math.ceil(1_000_000 / unit.length)))).toBeUndefined()+ expect(Date.now() - t0, unit).toBeLessThan(1_500)+ }+ })++ test('a window boundary never cuts a word: text that passes unpadded passes padded', () => {+ for (const tail of ['secret=abcdefghijklmnopqrstu', 'system: hi']) {+ // 20,000 - 1,024 = 18,976 is where the second window starts; the trailing text makes two windows.+ for (const n of [18_970, 18_976, 18_980]) {+ const t = 'q'.repeat(n) + tail + ' ' + 'z'.repeat(2_000)+ expect(screenOutbound(t) ?? screenInbound(t), `${n}`).toBeUndefined()+ }+ }+ })+test('padding cannot push a phrase or a secret past the screen', () => {for (const pad of ['x'.repeat(20_000), ' '.repeat(19_990), 'y'.repeat(100_000)]) {expect(screenOutbound(pad + ' ghp_' + 'a'.repeat(36))).toBe('github token')