Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(mods): one iterative textsOf in the shared screen — depth, sibling, size caps, object keys and the invisible-character set fixed at the root (ADR-445)

ruv53de5bb93699
diff --git a/plugins/ruflo-adr/hooks/guard.ts b/plugins/ruflo-adr/hooks/guard.ts
index f37d628a02..b7178dedce 100644
--- a/plugins/ruflo-adr/hooks/guard.ts
+++ b/plugins/ruflo-adr/hooks/guard.ts
@@ -1,4 +1,6 @@
import { hasSecret } from './screen'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its two halves; tool names never hold a double underscore. */
export function splitName(name: string): { server: string; tool: string } | undefined {
@@ -7,18 +9,6 @@ export function splitName(name: string): { server: string; tool: string } | unde
return at > 5 ? { server: name.slice(5, at), tool: name.slice(at + 2) } : undefined
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
const namespaceOf = (input: unknown): string => {
const ns = (input as { namespace?: unknown } | null)?.namespace
return typeof ns === 'string' ? ns : ''
diff --git a/plugins/ruflo-adr/hooks/screen.ts b/plugins/ruflo-adr/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-adr/hooks/screen.ts
+++ b/plugins/ruflo-adr/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-agent/hooks/guard.ts b/plugins/ruflo-agent/hooks/guard.ts
index 2a52d0cb44..c42718c0cf 100644
--- a/plugins/ruflo-agent/hooks/guard.ts
+++ b/plugins/ruflo-agent/hooks/guard.ts
@@ -1,4 +1,6 @@
import { hasSecret } from './screen'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its two halves; tool names never hold a double underscore. */
export function splitName(name: string): { server: string; tool: string } | undefined {
@@ -7,18 +9,6 @@ export function splitName(name: string): { server: string; tool: string } | unde
return at > 5 ? { server: name.slice(5, at), tool: name.slice(at + 2) } : undefined
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** True for the tool calls this plugin guards: text sent into an agent runtime (`wasm_agent_prompt`, `wasm_agent_tool`, `wasm_agent_create`, `wasm_gallery_create`, `managed_agent_create`, `managed_agent_prompt`). */
export function owns(tool: string, input: unknown): boolean {
const parts = splitName(tool)
diff --git a/plugins/ruflo-agent/hooks/screen.ts b/plugins/ruflo-agent/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-agent/hooks/screen.ts
+++ b/plugins/ruflo-agent/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-agentdb/hooks/guard.ts b/plugins/ruflo-agentdb/hooks/guard.ts
index 874d5fa62b..554a688595 100644
--- a/plugins/ruflo-agentdb/hooks/guard.ts
+++ b/plugins/ruflo-agentdb/hooks/guard.ts
@@ -1,17 +1,7 @@
import { hasSecret } from './screen'
import { isWriter } from './tools'
-
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The reason a memory write is refused, or undefined when it may go. Never names or echoes the secret. */
export function verdict(tool: string, input: unknown): string | undefined {
diff --git a/plugins/ruflo-agentdb/hooks/screen.ts b/plugins/ruflo-agentdb/hooks/screen.ts
index b5f05f7cc6..50665033bb 100644
--- a/plugins/ruflo-agentdb/hooks/screen.ts
+++ b/plugins/ruflo-agentdb/hooks/screen.ts
@@ -39,8 +39,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -162,6 +166,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-agentdb/tests/textsof.test.ts b/plugins/ruflo-agentdb/tests/textsof.test.ts
new file mode 100644
index 0000000000..b50a0544ea
--- /dev/null
+++ b/plugins/ruflo-agentdb/tests/textsof.test.ts
@@ -0,0 +1,61 @@
+import { describe, expect, test, tier } from 'claude-code/testing'
+
+import { hasSecret, textsOf } from '../hooks/screen'
+
+tier('user')
+
+const AWS = `AKIA${'IOSFODNN7EXAMPLE'}`
+const found = (input: unknown) => textsOf(input).some(hasSecret)
+const nest = (leaf: unknown, depth: number) => {
+ let v = leaf
+ for (let i = 0; i < depth; i++) v = { c: [v] }
+ return v
+}
+
+describe('the shared walker every guard reads through', () => {
+ test('a secret nested 5000 levels deep is found, without overflowing the stack', () => {
+ expect(found(nest({ note: AWS }, 5000))).toBe(true)
+ expect(found(nest('plain text', 5000))).toBe(false)
+ })
+
+ test('an object with 100 000 keys is bounded, and a secret among the first slots is still found', () => {
+ const wide: Record<string, unknown> = { first: AWS }
+ for (let i = 0; i < 100_000; i++) wide[`field${i}`] = i
+ const started = performance.now()
+ const texts = textsOf(wide)
+ expect(performance.now() - started).toBeLessThan(500)
+ expect(texts.length).toBeLessThanOrEqual(20_000)
+ expect(texts.some(hasSecret)).toBe(true)
+ })
+
+ test('a secret that is only an object key is read', () => {
+ expect(found({ [AWS]: { ok: 1 } })).toBe(true)
+ expect(found({ [AWS]: 'v' })).toBe(true)
+ expect(found({ short: { ok: 1 } })).toBe(false)
+ })
+
+ test('a secret in the middle or at the end of a 1 MB string is found', () => {
+ const pad = 'lorem ipsum dolor '.repeat(29_000)
+ expect(found({ value: `${pad} ${AWS} ${pad}` })).toBe(true)
+ expect(found({ value: `${pad}${pad} ${AWS}` })).toBe(true)
+ expect(found({ value: pad + pad })).toBe(false)
+ })
+
+ test('a secret split by a soft hyphen, a bidi isolate or a Mongolian vowel separator is found', () => {
+ for (const mark of ['­', '⁦', '⁩', '᠎']) expect(found({ value: `${AWS.slice(0, 8)}${mark}${AWS.slice(8)}` })).toBe(true)
+ })
+
+ test('the 201st array element and the 25 KB-padded tail are read', () => {
+ expect(found({ list: [...Array.from({ length: 200 }, () => 'x'), AWS] })).toBe(true)
+ expect(found({ value: `${'y'.repeat(25_000)} ${AWS}` })).toBe(true)
+ })
+
+ test('siblings are visited before depth, so a wide list cannot hide a shallow value behind deep ones', () => {
+ const deep = nest('plain', 50)
+ expect(found({ a: Array.from({ length: 300 }, () => deep), b: { note: AWS } })).toBe(true)
+ })
+
+ test('limits bound the work: a node budget of 2 stops the walk', () => {
+ expect(textsOf({ a: 'one', b: 'two', c: 'three' }, { nodes: 2 }).length).toBeLessThanOrEqual(2)
+ })
+})
diff --git a/plugins/ruflo-agntcy/hooks/screen.ts b/plugins/ruflo-agntcy/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-agntcy/hooks/screen.ts
+++ b/plugins/ruflo-agntcy/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-ai-team/hooks/guard.ts b/plugins/ruflo-ai-team/hooks/guard.ts
index 988bd5d2b9..626d17677f 100644
--- a/plugins/ruflo-ai-team/hooks/guard.ts
+++ b/plugins/ruflo-ai-team/hooks/guard.ts
@@ -1,4 +1,6 @@
import { hasSecret } from './screen'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its two halves; tool names never hold a double underscore. */
export function splitName(name: string): { server: string; tool: string } | undefined {
@@ -7,18 +9,6 @@ export function splitName(name: string): { server: string; tool: string } | unde
return at > 5 ? { server: name.slice(5, at), tool: name.slice(at + 2) } : undefined
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** True for the tool calls this plugin guards: what goes into team memory and task or run records (`memory_remember`, `task_create`, `task_update`, `run_create` on the ruflo-ai-team server). */
export function owns(tool: string, input: unknown): boolean {
const parts = splitName(tool)
diff --git a/plugins/ruflo-ai-team/hooks/screen.ts b/plugins/ruflo-ai-team/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-ai-team/hooks/screen.ts
+++ b/plugins/ruflo-ai-team/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-aidefence/hooks/guard.ts b/plugins/ruflo-aidefence/hooks/guard.ts
index 3695e2ca2f..610415a5a6 100644
--- a/plugins/ruflo-aidefence/hooks/guard.ts
+++ b/plugins/ruflo-aidefence/hooks/guard.ts
@@ -1,4 +1,6 @@
import { hasSecret } from './screen'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its two halves; tool names never hold a double underscore. */
export function splitName(name: string): { server: string; tool: string } | undefined {
@@ -7,18 +9,6 @@ export function splitName(name: string): { server: string; tool: string } | unde
return at > 5 ? { server: name.slice(5, at), tool: name.slice(at + 2) } : undefined
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** True for the tool calls this plugin guards: what `aidefence_learn` teaches the detector (patterns persist and are shown back later). */
export function owns(tool: string, input: unknown): boolean {
const parts = splitName(tool)
diff --git a/plugins/ruflo-aidefence/hooks/screen.ts b/plugins/ruflo-aidefence/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-aidefence/hooks/screen.ts
+++ b/plugins/ruflo-aidefence/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-arena/hooks/screen.ts b/plugins/ruflo-arena/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-arena/hooks/screen.ts
+++ b/plugins/ruflo-arena/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-autopilot/hooks/guard.ts b/plugins/ruflo-autopilot/hooks/guard.ts
index a2305c3b4d..31dad12853 100644
--- a/plugins/ruflo-autopilot/hooks/guard.ts
+++ b/plugins/ruflo-autopilot/hooks/guard.ts
@@ -1,5 +1,7 @@
import type { ModOptions } from './options'
import { hasSecret } from './screen'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its two halves; tool names never hold a double underscore. */
export function splitName(name: string): { server: string; tool: string } | undefined {
@@ -8,18 +10,6 @@ export function splitName(name: string): { server: string; tool: string } | unde
return at > 5 ? { server: name.slice(5, at), tool: name.slice(at + 2) } : undefined
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** True for the tool calls this plugin guards: the autopilot log and learned patterns (`autopilot_log`, `autopilot_learn`) and a runaway loop limit on `autopilot_config` (`maxIterations` over the cap). */
export function owns(tool: string, input: unknown): boolean {
const parts = splitName(tool)
diff --git a/plugins/ruflo-autopilot/hooks/screen.ts b/plugins/ruflo-autopilot/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-autopilot/hooks/screen.ts
+++ b/plugins/ruflo-autopilot/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-bbs-federation/hooks/screen.ts b/plugins/ruflo-bbs-federation/hooks/screen.ts
index bb62ab536e..581478dfd7 100644
--- a/plugins/ruflo-bbs-federation/hooks/screen.ts
+++ b/plugins/ruflo-bbs-federation/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -171,18 +239,6 @@ export const secretsIn = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
const CRED_KEY = /^(?:pass(?:word|wd)?|secret(?:_?key)?|api_?key|(?:access_?|auth_?|bearer_?)?token|private_?key|nsec|authorization|credentials?)$/i
/** True when any object key (to a bounded depth) names a credential and holds a non-empty string. The value is never read out. */
diff --git a/plugins/ruflo-browser/hooks/screen.ts b/plugins/ruflo-browser/hooks/screen.ts
index 63e6ec1625..a0a457c9ec 100644
--- a/plugins/ruflo-browser/hooks/screen.ts
+++ b/plugins/ruflo-browser/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -171,18 +239,6 @@ export const secretsIn = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
const CRED_KEY = /^(?:pass(?:word|wd)?|secret(?:_?key)?|api_?key|(?:access_?|auth_?|bearer_?)?token|private_?key|nsec|authorization|credentials?)$/i
/** True when any object key (to a bounded depth) names a credential and holds a non-empty string. The value is never read out. */
diff --git a/plugins/ruflo-business-pods/hooks/screen.ts b/plugins/ruflo-business-pods/hooks/screen.ts
index e3210a7b59..49edb148d9 100644
--- a/plugins/ruflo-business-pods/hooks/screen.ts
+++ b/plugins/ruflo-business-pods/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -171,18 +239,6 @@ export const secretsIn = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
const CRED_KEY = /^(?:pass(?:word|wd)?|secret(?:_?key)?|api_?key|(?:access_?|auth_?|bearer_?)?token|private_?key|nsec|authorization|credentials?)$/i
/** True when any object key (to a bounded depth) names a credential and holds a non-empty string. The value is never read out. */
diff --git a/plugins/ruflo-chatgpt-federation/hooks/screen.ts b/plugins/ruflo-chatgpt-federation/hooks/screen.ts
index 3051fa0e27..63587c2961 100644
--- a/plugins/ruflo-chatgpt-federation/hooks/screen.ts
+++ b/plugins/ruflo-chatgpt-federation/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -171,18 +239,6 @@ export const secretsIn = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
const CRED_KEY = /^(?:pass(?:word|wd)?|secret(?:_?key)?|api_?key|(?:access_?|auth_?|bearer_?)?token|private_?key|nsec|authorization|credentials?)$/i
/** True when any object key (to a bounded depth) names a credential and holds a non-empty string. The value is never read out. */
diff --git a/plugins/ruflo-daa/hooks/screen.ts b/plugins/ruflo-daa/hooks/screen.ts
index 396818c23d..58d52fdaaf 100644
--- a/plugins/ruflo-daa/hooks/screen.ts
+++ b/plugins/ruflo-daa/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -169,15 +237,3 @@ const SECRETS: Rules = [
export const secretNames = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what a guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
diff --git a/plugins/ruflo-ddd/hooks/screen.ts b/plugins/ruflo-ddd/hooks/screen.ts
index 396818c23d..58d52fdaaf 100644
--- a/plugins/ruflo-ddd/hooks/screen.ts
+++ b/plugins/ruflo-ddd/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -169,15 +237,3 @@ const SECRETS: Rules = [
export const secretNames = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what a guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
diff --git a/plugins/ruflo-deepseek-harness/hooks/screen.ts b/plugins/ruflo-deepseek-harness/hooks/screen.ts
index 396818c23d..58d52fdaaf 100644
--- a/plugins/ruflo-deepseek-harness/hooks/screen.ts
+++ b/plugins/ruflo-deepseek-harness/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -169,15 +237,3 @@ const SECRETS: Rules = [
export const secretNames = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what a guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
diff --git a/plugins/ruflo-docs/hooks/screen.ts b/plugins/ruflo-docs/hooks/screen.ts
index 396818c23d..58d52fdaaf 100644
--- a/plugins/ruflo-docs/hooks/screen.ts
+++ b/plugins/ruflo-docs/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -169,15 +237,3 @@ const SECRETS: Rules = [
export const secretNames = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what a guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
diff --git a/plugins/ruflo-federation/hooks/screen.ts b/plugins/ruflo-federation/hooks/screen.ts
index 396818c23d..58d52fdaaf 100644
--- a/plugins/ruflo-federation/hooks/screen.ts
+++ b/plugins/ruflo-federation/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -169,15 +237,3 @@ const SECRETS: Rules = [
export const secretNames = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what a guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
diff --git a/plugins/ruflo-goals/hooks/guard.ts b/plugins/ruflo-goals/hooks/guard.ts
index e9870968ab..87b77a4721 100644
--- a/plugins/ruflo-goals/hooks/guard.ts
+++ b/plugins/ruflo-goals/hooks/guard.ts
@@ -1,5 +1,5 @@
-import { hasSecret } from './screen'
-import { bare, namespaceOf, textsOf } from './tools'
+import { hasSecret, textsOf } from './screen'
+import { bare, namespaceOf } from './tools'
import type { ModOptions } from './options'
/** The namespaces the goals, research and dossier skills write to (legacy names included). */
diff --git a/plugins/ruflo-goals/hooks/screen.ts b/plugins/ruflo-goals/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-goals/hooks/screen.ts
+++ b/plugins/ruflo-goals/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-goals/hooks/tools.ts b/plugins/ruflo-goals/hooks/tools.ts
index 09c509774e..46e6bc65c1 100644
--- a/plugins/ruflo-goals/hooks/tools.ts
+++ b/plugins/ruflo-goals/hooks/tools.ts
@@ -16,18 +16,6 @@ export function findTool(tools: readonly ToolInfo[], suffix: string): { server:
return hit && splitName(hit.name)
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** The tool input's `namespace` field when it is a string, else ''. */
export const namespaceOf = (input: unknown): string => {
const ns = (input as { namespace?: unknown } | null)?.namespace
diff --git a/plugins/ruflo-graph-intelligence/hooks/guard.ts b/plugins/ruflo-graph-intelligence/hooks/guard.ts
index 5e6b6d8eeb..3c95bf3caf 100644
--- a/plugins/ruflo-graph-intelligence/hooks/guard.ts
+++ b/plugins/ruflo-graph-intelligence/hooks/guard.ts
@@ -1,5 +1,5 @@
-import { hasSecret } from './screen'
-import { bare, textsOf } from './tools'
+import { hasSecret, textsOf } from './screen'
+import { bare } from './tools'
import type { ModOptions } from './options'
/** The engine's tools are named `sublinear/<verb>` and surface as `sublinear_*` once an MCP server carries them. */
diff --git a/plugins/ruflo-graph-intelligence/hooks/screen.ts b/plugins/ruflo-graph-intelligence/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-graph-intelligence/hooks/screen.ts
+++ b/plugins/ruflo-graph-intelligence/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-graph-intelligence/hooks/tools.ts b/plugins/ruflo-graph-intelligence/hooks/tools.ts
index 09c509774e..46e6bc65c1 100644
--- a/plugins/ruflo-graph-intelligence/hooks/tools.ts
+++ b/plugins/ruflo-graph-intelligence/hooks/tools.ts
@@ -16,18 +16,6 @@ export function findTool(tools: readonly ToolInfo[], suffix: string): { server:
return hit && splitName(hit.name)
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** The tool input's `namespace` field when it is a string, else ''. */
export const namespaceOf = (input: unknown): string => {
const ns = (input as { namespace?: unknown } | null)?.namespace
diff --git a/plugins/ruflo-intelligence/hooks/guard.ts b/plugins/ruflo-intelligence/hooks/guard.ts
index d3e7c14223..1a8644a14b 100644
--- a/plugins/ruflo-intelligence/hooks/guard.ts
+++ b/plugins/ruflo-intelligence/hooks/guard.ts
@@ -1,5 +1,5 @@
-import { hasSecret } from './screen'
-import { bare, namespaceOf, textsOf } from './tools'
+import { hasSecret, textsOf } from './screen'
+import { bare, namespaceOf } from './tools'
import type { ModOptions } from './options'
/** Learning writes: a secret in a stored pattern, trajectory or training row would be learned, recalled and, via transfer, published. */
diff --git a/plugins/ruflo-intelligence/hooks/screen.ts b/plugins/ruflo-intelligence/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-intelligence/hooks/screen.ts
+++ b/plugins/ruflo-intelligence/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-intelligence/hooks/tools.ts b/plugins/ruflo-intelligence/hooks/tools.ts
index 09c509774e..46e6bc65c1 100644
--- a/plugins/ruflo-intelligence/hooks/tools.ts
+++ b/plugins/ruflo-intelligence/hooks/tools.ts
@@ -16,18 +16,6 @@ export function findTool(tools: readonly ToolInfo[], suffix: string): { server:
return hit && splitName(hit.name)
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** The tool input's `namespace` field when it is a string, else ''. */
export const namespaceOf = (input: unknown): string => {
const ns = (input as { namespace?: unknown } | null)?.namespace
diff --git a/plugins/ruflo-iot-cognitum/hooks/guard.ts b/plugins/ruflo-iot-cognitum/hooks/guard.ts
index 4608eadebf..e21af8cbde 100644
--- a/plugins/ruflo-iot-cognitum/hooks/guard.ts
+++ b/plugins/ruflo-iot-cognitum/hooks/guard.ts
@@ -1,5 +1,5 @@
-import { hasSecret } from './screen'
-import { bare, namespaceOf, textsOf } from './tools'
+import { hasSecret, textsOf } from './screen'
+import { bare, namespaceOf } from './tools'
import type { ModOptions } from './options'
const IOT_NS = /^iot-/i
diff --git a/plugins/ruflo-iot-cognitum/hooks/screen.ts b/plugins/ruflo-iot-cognitum/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-iot-cognitum/hooks/screen.ts
+++ b/plugins/ruflo-iot-cognitum/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-iot-cognitum/hooks/tools.ts b/plugins/ruflo-iot-cognitum/hooks/tools.ts
index 09c509774e..46e6bc65c1 100644
--- a/plugins/ruflo-iot-cognitum/hooks/tools.ts
+++ b/plugins/ruflo-iot-cognitum/hooks/tools.ts
@@ -16,18 +16,6 @@ export function findTool(tools: readonly ToolInfo[], suffix: string): { server:
return hit && splitName(hit.name)
}
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** The tool input's `namespace` field when it is a string, else ''. */
export const namespaceOf = (input: unknown): string => {
const ns = (input as { namespace?: unknown } | null)?.namespace
diff --git a/plugins/ruflo-jujutsu/hooks/guard.ts b/plugins/ruflo-jujutsu/hooks/guard.ts
index bd29cfe4df..cdbd9499f0 100644
--- a/plugins/ruflo-jujutsu/hooks/guard.ts
+++ b/plugins/ruflo-jujutsu/hooks/guard.ts
@@ -1,5 +1,7 @@
import { hasSecret } from './screen'
import type { ModOptions } from './options'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its tool half; tool names never hold a double underscore. */
export function shortName(name: string): string {
@@ -7,18 +9,6 @@ export function shortName(name: string): string {
return name.startsWith('mcp__') && at > 5 ? name.slice(at + 2) : name
}
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
-
const field = (input: unknown, key: string): unknown => (typeof input === 'object' && input !== null ? (input as Record<string, unknown>)[key] : undefined)
diff --git a/plugins/ruflo-jujutsu/hooks/screen.ts b/plugins/ruflo-jujutsu/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-jujutsu/hooks/screen.ts
+++ b/plugins/ruflo-jujutsu/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-knowledge-graph/hooks/guard.ts b/plugins/ruflo-knowledge-graph/hooks/guard.ts
index dd18f1cc45..20a3160a51 100644
--- a/plugins/ruflo-knowledge-graph/hooks/guard.ts
+++ b/plugins/ruflo-knowledge-graph/hooks/guard.ts
@@ -1,5 +1,7 @@
import { hasSecret } from './screen'
import type { ModOptions } from './options'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its tool half; tool names never hold a double underscore. */
export function shortName(name: string): string {
@@ -7,18 +9,6 @@ export function shortName(name: string): string {
return name.startsWith('mcp__') && at > 5 ? name.slice(at + 2) : name
}
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
-
const field = (input: unknown, key: string): unknown => (typeof input === 'object' && input !== null ? (input as Record<string, unknown>)[key] : undefined)
diff --git a/plugins/ruflo-knowledge-graph/hooks/screen.ts b/plugins/ruflo-knowledge-graph/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-knowledge-graph/hooks/screen.ts
+++ b/plugins/ruflo-knowledge-graph/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-loop-workers/hooks/guard.ts b/plugins/ruflo-loop-workers/hooks/guard.ts
index a6eb8a5e11..3fc6f7fefb 100644
--- a/plugins/ruflo-loop-workers/hooks/guard.ts
+++ b/plugins/ruflo-loop-workers/hooks/guard.ts
@@ -1,5 +1,7 @@
import { hasSecret } from './screen'
import type { ModOptions } from './options'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its tool half; tool names never hold a double underscore. */
export function shortName(name: string): string {
@@ -7,18 +9,6 @@ export function shortName(name: string): string {
return name.startsWith('mcp__') && at > 5 ? name.slice(at + 2) : name
}
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
-
const field = (input: unknown, key: string): unknown => (typeof input === 'object' && input !== null ? (input as Record<string, unknown>)[key] : undefined)
diff --git a/plugins/ruflo-loop-workers/hooks/screen.ts b/plugins/ruflo-loop-workers/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-loop-workers/hooks/screen.ts
+++ b/plugins/ruflo-loop-workers/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-market-data/hooks/guard.ts b/plugins/ruflo-market-data/hooks/guard.ts
index 677551c17e..9e8fed4c06 100644
--- a/plugins/ruflo-market-data/hooks/guard.ts
+++ b/plugins/ruflo-market-data/hooks/guard.ts
@@ -1,5 +1,7 @@
import { hasSecret } from './screen'
import type { ModOptions } from './options'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its tool half; tool names never hold a double underscore. */
export function shortName(name: string): string {
@@ -7,18 +9,6 @@ export function shortName(name: string): string {
return name.startsWith('mcp__') && at > 5 ? name.slice(at + 2) : name
}
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
-
const field = (input: unknown, key: string): unknown => (typeof input === 'object' && input !== null ? (input as Record<string, unknown>)[key] : undefined)
diff --git a/plugins/ruflo-market-data/hooks/screen.ts b/plugins/ruflo-market-data/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-market-data/hooks/screen.ts
+++ b/plugins/ruflo-market-data/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-metaharness/hooks/guard.ts b/plugins/ruflo-metaharness/hooks/guard.ts
index b52e62b0c9..4cc51e2f7b 100644
--- a/plugins/ruflo-metaharness/hooks/guard.ts
+++ b/plugins/ruflo-metaharness/hooks/guard.ts
@@ -1,5 +1,7 @@
import { hasSecret } from './screen'
import type { ModOptions } from './options'
+import { textsOf } from './screen'
+export { textsOf }
/** `mcp__<server>__<tool>` into its tool half; tool names never hold a double underscore. */
export function shortName(name: string): string {
@@ -7,18 +9,6 @@ export function shortName(name: string): string {
return name.startsWith('mcp__') && at > 5 ? name.slice(at + 2) : name
}
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
-
const field = (input: unknown, key: string): unknown => (typeof input === 'object' && input !== null ? (input as Record<string, unknown>)[key] : undefined)
diff --git a/plugins/ruflo-metaharness/hooks/screen.ts b/plugins/ruflo-metaharness/hooks/screen.ts
index 2b734d2efd..5e899f3944 100644
--- a/plugins/ruflo-metaharness/hooks/screen.ts
+++ b/plugins/ruflo-metaharness/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-migrations/hooks/screen.ts b/plugins/ruflo-migrations/hooks/screen.ts
index ed10089ec2..e3b01e80f6 100644
--- a/plugins/ruflo-migrations/hooks/screen.ts
+++ b/plugins/ruflo-migrations/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -170,20 +238,3 @@ const SECRETS: Rules = [
export const secretsIn = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) {
- // A string field is also read as `name=value`, so {api_secret: '...'} trips the key-assignment rule like a pasted line would.
- return Object.entries(input)
- .slice(0, 200)
- .flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- }
- return []
-}
diff --git a/plugins/ruflo-music/hooks/screen.ts b/plugins/ruflo-music/hooks/screen.ts
index 5eb5d4d7e9..0600038a81 100644
--- a/plugins/ruflo-music/hooks/screen.ts
+++ b/plugins/ruflo-music/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -169,20 +237,3 @@ const SECRETS: Rules = [
export const secretsIn = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) {
- // A string field is also read as `name=value`, so {api_secret: '...'} trips the key-assignment rule like a pasted line would.
- return Object.entries(input)
- .slice(0, 200)
- .flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- }
- return []
-}
diff --git a/plugins/ruflo-neural-trader/hooks/screen.ts b/plugins/ruflo-neural-trader/hooks/screen.ts
index cd5169a8d0..b5f22aac70 100644
--- a/plugins/ruflo-neural-trader/hooks/screen.ts
+++ b/plugins/ruflo-neural-trader/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -169,20 +237,3 @@ const SECRETS: Rules = [
export const secretsIn = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) {
- // A string field is also read as `name=value`, so {api_secret: '...'} trips the key-assignment rule like a pasted line would.
- return Object.entries(input)
- .slice(0, 200)
- .flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- }
- return []
-}
diff --git a/plugins/ruflo-observability/hooks/screen.ts b/plugins/ruflo-observability/hooks/screen.ts
index 2232300754..329d685de3 100644
--- a/plugins/ruflo-observability/hooks/screen.ts
+++ b/plugins/ruflo-observability/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
@@ -171,20 +239,3 @@ const SECRETS: Rules = [
export const secretsIn = (text: string): string[] => names(SECRETS, bare(text))
export const hasSecret = (text: string) => hasSecretIn(SECRETS, text)
-
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) {
- // A string field is also read as `name=value`, so {api_secret: '...'} trips the key-assignment rule like a pasted line would.
- return Object.entries(input)
- .slice(0, 200)
- .flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- }
- return []
-}
diff --git a/plugins/ruflo-rag-memory/hooks/guard.ts b/plugins/ruflo-rag-memory/hooks/guard.ts
index 2da856c790..5f331d2113 100644
--- a/plugins/ruflo-rag-memory/hooks/guard.ts
+++ b/plugins/ruflo-rag-memory/hooks/guard.ts
@@ -1,17 +1,7 @@
import { hasSecret } from './screen'
import { isWriter } from './tools'
-
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The reason a call is refused, or undefined when it may go. Never names or echoes the secret. */
export function verdict(tool: string, input: unknown): string | undefined {
diff --git a/plugins/ruflo-rag-memory/hooks/screen.ts b/plugins/ruflo-rag-memory/hooks/screen.ts
index c6584493ad..6a733312f7 100644
--- a/plugins/ruflo-rag-memory/hooks/screen.ts
+++ b/plugins/ruflo-rag-memory/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-ruvector/hooks/guard.ts b/plugins/ruflo-ruvector/hooks/guard.ts
index e57b73dff2..ca414e3623 100644
--- a/plugins/ruflo-ruvector/hooks/guard.ts
+++ b/plugins/ruflo-ruvector/hooks/guard.ts
@@ -1,17 +1,7 @@
import { hasSecret } from './screen'
import { isWriter } from './tools'
-
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The reason a call is refused, or undefined when it may go. Never names or echoes the secret. */
export function verdict(tool: string, input: unknown): string | undefined {
diff --git a/plugins/ruflo-ruvector/hooks/screen.ts b/plugins/ruflo-ruvector/hooks/screen.ts
index 06227bdcb6..9fef5365db 100644
--- a/plugins/ruflo-ruvector/hooks/screen.ts
+++ b/plugins/ruflo-ruvector/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-ruvllm/hooks/guard.ts b/plugins/ruflo-ruvllm/hooks/guard.ts
index 1c53a2ad23..0692494a62 100644
--- a/plugins/ruflo-ruvllm/hooks/guard.ts
+++ b/plugins/ruflo-ruvllm/hooks/guard.ts
@@ -1,17 +1,7 @@
import { hasSecret } from './screen'
import { isWriter } from './tools'
-
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The reason a call is refused, or undefined when it may go. Never names or echoes the secret. */
export function verdict(tool: string, input: unknown): string | undefined {
diff --git a/plugins/ruflo-ruvllm/hooks/screen.ts b/plugins/ruflo-ruvllm/hooks/screen.ts
index 7c67e93cf1..1d0154f5cf 100644
--- a/plugins/ruflo-ruvllm/hooks/screen.ts
+++ b/plugins/ruflo-ruvllm/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-rvf/hooks/guard.ts b/plugins/ruflo-rvf/hooks/guard.ts
index c2a0149887..d3d8d6e764 100644
--- a/plugins/ruflo-rvf/hooks/guard.ts
+++ b/plugins/ruflo-rvf/hooks/guard.ts
@@ -1,17 +1,7 @@
import { hasSecret } from './screen'
import { isWriter } from './tools'
-
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The reason a call is refused, or undefined when it may go. Never names or echoes the secret. */
export function verdict(tool: string, input: unknown): string | undefined {
diff --git a/plugins/ruflo-rvf/hooks/screen.ts b/plugins/ruflo-rvf/hooks/screen.ts
index e95deac7dc..f780854d70 100644
--- a/plugins/ruflo-rvf/hooks/screen.ts
+++ b/plugins/ruflo-rvf/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-security-audit/hooks/guard.ts b/plugins/ruflo-security-audit/hooks/guard.ts
index 97d43071a3..87e05903d5 100644
--- a/plugins/ruflo-security-audit/hooks/guard.ts
+++ b/plugins/ruflo-security-audit/hooks/guard.ts
@@ -1,16 +1,6 @@
import { hasSecret } from './screen'
-
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The tool's short name: `mcp__<server>__<tool>` to `<tool>`. */
export const shortName = (name: string) => (name.startsWith('mcp__') && name.lastIndexOf('__') > 5 ? name.slice(name.lastIndexOf('__') + 2) : name)
diff --git a/plugins/ruflo-security-audit/hooks/screen.ts b/plugins/ruflo-security-audit/hooks/screen.ts
index 3a97683355..19e560824a 100644
--- a/plugins/ruflo-security-audit/hooks/screen.ts
+++ b/plugins/ruflo-security-audit/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-sparc/hooks/guard.ts b/plugins/ruflo-sparc/hooks/guard.ts
index 5bebe41d47..4515df8dc4 100644
--- a/plugins/ruflo-sparc/hooks/guard.ts
+++ b/plugins/ruflo-sparc/hooks/guard.ts
@@ -1,16 +1,6 @@
import { hasSecret } from './screen'
-
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The tool's short name: `mcp__<server>__<tool>` to `<tool>`. */
export const shortName = (name: string) => (name.startsWith('mcp__') && name.lastIndexOf('__') > 5 ? name.slice(name.lastIndexOf('__') + 2) : name)
diff --git a/plugins/ruflo-sparc/hooks/screen.ts b/plugins/ruflo-sparc/hooks/screen.ts
index 9b0fe5adeb..e8774e59f6 100644
--- a/plugins/ruflo-sparc/hooks/screen.ts
+++ b/plugins/ruflo-sparc/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-testgen/hooks/guard.ts b/plugins/ruflo-testgen/hooks/guard.ts
index aa9ebd9cb0..c957511ec1 100644
--- a/plugins/ruflo-testgen/hooks/guard.ts
+++ b/plugins/ruflo-testgen/hooks/guard.ts
@@ -1,15 +1,3 @@
-/** Every string in a tool's input, to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 20_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= input.length
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.values(input).slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- return []
-}
-
/** The tool's short name: `mcp__<server>__<tool>` to `<tool>`. */
export const shortName = (name: string) => (name.startsWith('mcp__') && name.lastIndexOf('__') > 5 ? name.slice(name.lastIndexOf('__') + 2) : name)
diff --git a/plugins/ruflo-workflows/hooks/guard.ts b/plugins/ruflo-workflows/hooks/guard.ts
index 060b4d0f5c..cb4b47a301 100644
--- a/plugins/ruflo-workflows/hooks/guard.ts
+++ b/plugins/ruflo-workflows/hooks/guard.ts
@@ -1,16 +1,6 @@
import { hasSecret } from './screen'
-
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The tool's short name: `mcp__<server>__<tool>` to `<tool>`. */
export const shortName = (name: string) => (name.startsWith('mcp__') && name.lastIndexOf('__') > 5 ? name.slice(name.lastIndexOf('__') + 2) : name)
diff --git a/plugins/ruflo-workflows/hooks/screen.ts b/plugins/ruflo-workflows/hooks/screen.ts
index 577fec4dd6..8ed877f2aa 100644
--- a/plugins/ruflo-workflows/hooks/screen.ts
+++ b/plugins/ruflo-workflows/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/plugins/ruflo-x-gateway/hooks/guard.ts b/plugins/ruflo-x-gateway/hooks/guard.ts
index 78783deaa4..a17ddbb3aa 100644
--- a/plugins/ruflo-x-gateway/hooks/guard.ts
+++ b/plugins/ruflo-x-gateway/hooks/guard.ts
@@ -1,16 +1,6 @@
import { hasSecret } from './screen'
-
-/** Every string in a tool's input (a string value led by its key, so `api_key=...` reads as an assignment), to a bounded depth and size: what the guard reads. */
-export function textsOf(input: unknown, budget = { left: 100_000 }, depth = 0): string[] {
- if (budget.left <= 0 || depth > 6) return []
- if (typeof input === 'string') {
- budget.left -= Math.min(input.length, 20_000)
- return [input]
- }
- if (Array.isArray(input)) return input.slice(0, 200).flatMap(v => textsOf(v, budget, depth + 1))
- if (typeof input === 'object' && input !== null) return Object.entries(input).slice(0, 200).flatMap(([k, v]) => (typeof v === 'string' ? textsOf(`${k}=${v}`, budget, depth + 1) : textsOf(v, budget, depth + 1)))
- return []
-}
+import { textsOf } from './screen'
+export { textsOf }
/** The tool's short name: `mcp__<server>__<tool>` to `<tool>`. */
export const shortName = (name: string) => (name.startsWith('mcp__') && name.lastIndexOf('__') > 5 ? name.slice(name.lastIndexOf('__') + 2) : name)
diff --git a/plugins/ruflo-x-gateway/hooks/screen.ts b/plugins/ruflo-x-gateway/hooks/screen.ts
index 7944914dac..3850675534 100644
--- a/plugins/ruflo-x-gateway/hooks/screen.ts
+++ b/plugins/ruflo-x-gateway/hooks/screen.ts
@@ -35,8 +35,12 @@ export const INJECTION: Rules = [
['shell pipe', /\b(?:curl|wget)\b[^|\n]{0,200}\|\s*(?:sudo\s+)?(?:ba|z)?sh\b/i],
]
-// C0/C1 controls (keeping tab and newline), DEL, zero-width and bidi override characters; built with escapes, never raw.
-const INVISIBLE = new RegExp('[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u2064\\ufeff]', 'g')
+// C0/C1 controls (keeping tab and newline), DEL, soft hyphen, combining grapheme joiner, Arabic letter mark, Hangul and Mongolian fillers/separators,
+// zero-width, bidi (overrides and isolates) and invisible-format characters, variation selectors; built with escapes, never raw.
+const INVISIBLE = new RegExp(
+ '[\\u0000-\\u0008\\u000b-\\u001f\\u007f-\\u009f\\u00ad\\u034f\\u061c\\u115f\\u1160\\u17b4\\u17b5\\u180b-\\u180e\\u200b-\\u200f\\u2028-\\u202e\\u2060-\\u206f\\u3164\\ufe00-\\ufe0f\\ufeff\\uffa0\\ufff9-\\ufffb]',
+ 'g',
+)
/** Longest input scanned in one pass; a longer one keeps its head and tail halves. One regex pass per rule, so cost stays linear. */
const MAX_SCAN = 200_000
@@ -158,6 +162,70 @@ export function tidy(text: string, max: number): string {
const flat = text.replace(INVISIBLE, '').replace(/\s+/g, ' ').trim()
return flat.length > max ? `${flat.slice(0, Math.max(0, max - 1))}…` : flat
}
+/** Bounds for textsOf: nodes visited, characters returned, the longest string read in full, the size of one returned chunk, chunk overlap. */
+export type TextLimits = { readonly nodes?: number; readonly chars?: number; readonly perString?: number }
+const NODES = 20_000
+const CHARS = 2_000_000
+const PER_STRING = 1_500_000
+const OVERLAP = 2_048
+const BARE_KEY_MIN = 8
+
+/** A string as texts the screen can read whole: one text up to MAX_SCAN, else overlapping MAX_SCAN windows so a secret anywhere is inside one. */
+function windows(text: string, out: string[]): void {
+ if (text.length <= MAX_SCAN) {
+ out.push(text)
+ return
+ }
+ for (let at = 0; ; at += MAX_SCAN - OVERLAP) {
+ out.push(text.slice(at, at + MAX_SCAN))
+ if (at + MAX_SCAN >= text.length) return
+ }
+}
+
+/**
+ * Every string in a tool input, for the screen to read: iterative (no recursion, so nesting 5000 deep cannot overflow the stack) and
+ * breadth-first (siblings before depth, so a long list cannot hide a nested value). A string under an object key comes back as `key=value`,
+ * so a secret-named key is judged with its value; a key whose value is not a string is returned bare. Strings longer than the screen window
+ * come back as overlapping windows; one over `perString` keeps its head and tail. Work is bounded by `nodes` slots and `chars` characters.
+ */
+export function textsOf(input: unknown, limits: TextLimits = {}): string[] {
+ const out: string[] = []
+ let slots = limits.nodes ?? NODES
+ let chars = limits.chars ?? CHARS
+ const perString = limits.perString ?? PER_STRING
+ const take = (text: string): void => {
+ if (chars <= 0) return
+ if (text.length <= Math.min(perString, chars)) {
+ chars -= text.length
+ windows(text, out)
+ return
+ }
+ const half = Math.floor(Math.min(perString, chars) / 2)
+ chars -= 2 * half
+ windows(text.slice(0, half), out)
+ windows(text.slice(-half), out)
+ }
+ const queue: unknown[] = [input]
+ for (let head = 0; head < queue.length && chars > 0; head++) {
+ const node = queue[head]
+ if (typeof node === 'string') take(node)
+ else if (Array.isArray(node)) {
+ for (let i = 0; i < node.length && slots > 0; i++, slots--) if (i in node) queue.push(node[i])
+ } else if (typeof node === 'object' && node !== null) {
+ for (const k in node) {
+ if (slots-- <= 0) break
+ if (!Object.prototype.hasOwnProperty.call(node, k)) continue
+ const v = (node as Record<string, unknown>)[k]
+ if (typeof v === 'string') queue.push(k + '=' + v)
+ else {
+ if (k.length >= BARE_KEY_MIN) take(k)
+ queue.push(v)
+ }
+ }
+ }
+ }
+ return out
+}
// END SHARED SCREEN
const SECRETS: Rules = [
diff --git a/scripts/probe-mod-guards.known-holes.json b/scripts/probe-mod-guards.known-holes.json
index c9207d2429..0967ef424b 100644
--- a/scripts/probe-mod-guards.known-holes.json
+++ b/scripts/probe-mod-guards.known-holes.json
@@ -1,854 +1 @@
-{
- "ruflo-adr": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-agent": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-agentdb": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-ai-team": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-aidefence": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-autopilot": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-bbs-federation": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-daa": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-ddd": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-docs": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-federation": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-goals": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-graph-intelligence": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-intelligence": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-iot-cognitum": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-jujutsu": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-knowledge-graph": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-loop-workers": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-market-data": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-metaharness": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-migrations": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-music": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-neural-trader": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-observability": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-rag-memory": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-ruvector": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-ruvllm": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-rvf": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-security-audit": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-sparc": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-workflows": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ],
- "ruflo-x-gateway": [
- "shy-split",
- "bidi-isolate",
- "mongolian-vs",
- "nest-obj-6",
- "nest-obj-12",
- "nest-obj-60",
- "nest-obj-5000",
- "nest-arr-6",
- "nest-arr-12",
- "nest-arr-60",
- "nest-arr-5000",
- "nest-mix-6",
- "nest-mix-12",
- "nest-mix-60",
- "nest-mix-5000",
- "wide-array-250",
- "wide-object-250",
- "wide-array-5000",
- "key-name",
- "key-name-nested-3",
- "key-name-in-array",
- "huge-middle",
- "huge-end",
- "after-25k-padding",
- "after-200k-padding"
- ]
-}
+{}
diff --git a/scripts/sync-mod-screen.mjs b/scripts/sync-mod-screen.mjs
index 72d3b90790..c615bfd292 100755
--- a/scripts/sync-mod-screen.mjs
+++ b/scripts/sync-mod-screen.mjs
@@ -15,7 +15,7 @@ const ORIGIN = 'ruflo-agentdb'
const BEGIN = '// BEGIN SHARED SCREEN'
const END = '// END SHARED SCREEN'
// Raw zero-width, bidi and line-separator characters must never sit in a regex literal (they are built from escapes).
-const RAW_INVISIBLE = new RegExp('[\\u2028\\u2029\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u2064\\ufeff]')
+const RAW_INVISIBLE = new RegExp('[\\u00ad\\u034f\\u061c\\u180b-\\u180e\\u2028\\u2029\\u200b-\\u200f\\u202a-\\u202e\\u2060-\\u206f\\ufe00-\\ufe0f\\ufeff]')
/** Split into the text before the begin line, the region (begin line to end line inclusive), and the text after. */
export function split(src) {