@foldrun/core 18.3.0 → 18.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@
22
22
  // exchanges text and JSON only, and a URL in a reply is not an invitation.
23
23
  //
24
24
  // No vault, no MCP: values in, values out. a2a-tools.ts is the agent's side.
25
+ import { spellingJoiners } from "./joiners.js";
25
26
  import crypto from "node:crypto";
26
27
  import { viaEgress } from "./egress.js";
27
28
  import { capBody, ResponseTooLarge } from "./untrusted-fetch.js";
@@ -101,7 +102,12 @@ const HIDDEN = /[​-‏‪-‮⁠-⁤⁦-⁩\u0000-\u0008\u000B\u000C\u000E-
101
102
  /** `text` with hidden characters removed, and how many there were. */
102
103
  export function stripHidden(text) {
103
104
  let removed = 0;
104
- const out = text.replace(HIDDEN, () => {
105
+ // A joiner that is spelling (a Persian half-space, an Indic or emoji
106
+ // joiner — joiners.ts) stays: removing it misspells the word.
107
+ const spelling = spellingJoiners(text);
108
+ const out = text.replace(HIDDEN, (m, at) => {
109
+ if (spelling.has(at))
110
+ return m;
105
111
  removed++;
106
112
  return "";
107
113
  });
@@ -0,0 +1,5 @@
1
+ /** The indices (UTF-16) of every invisible in `text` that is spelling, not
2
+ * hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
3
+ * LINE with right-to-left letters, not splitting a Latin word (Codex review:
4
+ * judged per line, per whole run, by letters alone). */
5
+ export declare function spellingJoiners(text: string): Set<number>;
@@ -0,0 +1,74 @@
1
+ // ZWNJ (U+200C) and ZWJ (U+200D) are invisible, and they are also spelling.
2
+ //
3
+ // In Persian the half-space is how a word is written: «کانال‌ها», «می‌شود».
4
+ // Arabic-script, Syriac, Thaana and N'Ko, and the Indic and other Brahmic
5
+ // scripts, use both joiners inside words. An emoji sequence (👨‍💻, 🏳️‍🌈) is
6
+ // glued with ZWJ. Flagging those as hidden text (scan.ts
7
+ // content/hidden-unicode) buried real findings under hundreds of false ones
8
+ // on a Persian workspace (cloudhost, 11 Nov 2026), and stripping them from an
9
+ // outside agent's reply (a2a-client.ts) misspelled every such word.
10
+ //
11
+ // So a joiner is spelling when it sits INSIDE a word of a script that uses
12
+ // joiners — a letter or mark of one on BOTH sides — or between two emoji.
13
+ // Anywhere else (between Latin letters, at a word's edge, alone) it is still
14
+ // hidden text. Every other invisible character (zero-width space, bidi
15
+ // overrides and isolates, word joiner, BOM, Unicode tags) is never spelling.
16
+ const JOINER_SCRIPTS = [
17
+ "Arabic", "Syriac", "Thaana", "Nko",
18
+ "Devanagari", "Bengali", "Gurmukhi", "Gujarati", "Oriya", "Tamil", "Telugu", "Kannada", "Malayalam", "Sinhala",
19
+ "Tibetan", "Myanmar", "Khmer", "Mongolian",
20
+ ];
21
+ const LETTER = `(?:${JOINER_SCRIPTS.map((s) => `[\\p{scx=${s}}&&[\\p{L}\\p{M}]]`).join("|")})`;
22
+ /** A ZWNJ or ZWJ with a letter or mark of a joining script on one side and
23
+ * a letter or mark on the other — inside a word, or where a Persian suffix
24
+ * follows a Latin word («channel‌ها», «webhooks‌اند»; cloudhost, 11 Nov). */
25
+ const ANY_LETTER = "[\\p{L}\\p{M}]";
26
+ const IN_WORD = new RegExp(`(?<=${LETTER})[\\u200C\\u200D](?=${ANY_LETTER})|(?<=${ANY_LETTER})[\\u200C\\u200D](?=${LETTER})`, "gv");
27
+ /** A ZWJ between two emoji (a skin tone or VS16 may follow the first). */
28
+ const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)\u200D(?=\p{Extended_Pictographic})/gu;
29
+ /** A right-to-left LETTER (Arabic-script, Hebrew, Syriac, Thaana, N'Ko) —
30
+ * letters only, so a mark (ALM is Arabic-script) is never its own evidence. */
31
+ const RTL_LETTER = new RegExp("[[\\p{scx=Arabic}\\p{scx=Hebrew}\\p{scx=Syriac}\\p{scx=Thaana}\\p{scx=Nko}]&&\\p{L}]", "v");
32
+ /** A run of bidi MARKS — LRM, RLM, ALM. Unlike overrides and isolates they
33
+ * move nothing: they settle where a neutral (a backtick, a dot) sits, which
34
+ * is how a Latin file name stays in order inside Persian text. */
35
+ const MARKS = /[\u200E\u200F\u061C]+/gu;
36
+ const LATIN = /\p{scx=Latin}/u;
37
+ const MARKS_ANY = /[\u200E\u200F\u061C]/u;
38
+ /** The indices (UTF-16) of every invisible in `text` that is spelling, not
39
+ * hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
40
+ * LINE with right-to-left letters, not splitting a Latin word (Codex review:
41
+ * judged per line, per whole run, by letters alone). */
42
+ export function spellingJoiners(text) {
43
+ const at = new Set();
44
+ if (/[\u200C\u200D]/.test(text))
45
+ for (const re of [IN_WORD, IN_EMOJI])
46
+ for (const m of text.matchAll(re))
47
+ at.add(m.index);
48
+ if (/[\u200E\u200F\u061C]/.test(text)) {
49
+ // Line by line, each line classified once (Codex review: rescanning the
50
+ // line for every run of marks was quadratic on hostile input).
51
+ let lineStart = 0;
52
+ while (lineStart <= text.length) {
53
+ const nl = text.indexOf("\n", lineStart);
54
+ const lineEnd = nl === -1 ? text.length : nl;
55
+ const line = text.slice(lineStart, lineEnd);
56
+ if (MARKS_ANY.test(line) && RTL_LETTER.test(line)) {
57
+ for (const m of line.matchAll(MARKS)) {
58
+ const start = lineStart + m.index;
59
+ const end = start + m[0].length;
60
+ // "ig\u200E\u200Enore": marks between two Latin letters split a
61
+ // word; they order nothing there, so they are still hidden text.
62
+ if (LATIN.test(text[start - 1] ?? "") && LATIN.test(text[end] ?? ""))
63
+ continue;
64
+ for (let k = start; k < end; k++)
65
+ at.add(k);
66
+ }
67
+ }
68
+ if (nl === -1)
69
+ break;
70
+ lineStart = nl + 1;
71
+ }
72
+ }
73
+ return at;
74
+ }
package/dist/src/scan.js CHANGED
@@ -25,6 +25,7 @@
25
25
  // or `foldrun-ignore-file <rule>: <reason>` anywhere in a file for all of it.
26
26
  // The reason is required: an ignore without one ignores nothing and is itself
27
27
  // reported, because "why is this allowed?" is the question a reviewer asks.
28
+ import { spellingJoiners } from "./joiners.js";
28
29
  import crypto from "node:crypto";
29
30
  import matter, { frontmatterErrorLine, frontmatterErrorText, parseLenient, configMatter } from "./matter.js";
30
31
  import { refNames } from "./refs.js";
@@ -566,10 +567,14 @@ function scanContent(file, lines, push, untrusted = false) {
566
567
  const line = i === 0 ? lines[i].replace(/^/, "") : lines[i];
567
568
  if (!untrusted && /^\s*(?:```|~~~)/.test(line))
568
569
  fenced = !fenced;
569
- HIDDEN.lastIndex = 0;
570
- if (HIDDEN.test(line)) {
571
- const kind = HIDDEN_NAMES.find(([re]) => re.test(line))?.[1] ?? "invisible characters";
572
- const n = line.match(HIDDEN)?.length ?? 0;
570
+ // A half-space inside a Persian word, a joiner in an Indic word or an
571
+ // emoji sequence is spelling, not hiding (joiners.ts): not counted.
572
+ const spelling = spellingJoiners(line);
573
+ const hits = [...line.matchAll(HIDDEN)].filter((m) => !spelling.has(m.index));
574
+ if (hits.length) {
575
+ const found = hits.map((m) => m[0]).join("");
576
+ const kind = HIDDEN_NAMES.find(([re]) => re.test(found))?.[1] ?? "invisible characters";
577
+ const n = hits.length;
573
578
  const tagged = /\uDB40[\uDC00-\uDC7F]/.test(line) ? ` that read as: "${decodeTags(line).slice(0, 80)}"` : "";
574
579
  push("content/hidden-unicode", file.path, i + 1, line, `${n} ${kind}${redactText(tagged)} — invisible to a reviewer, read by the model`);
575
580
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldrun/core",
3
- "version": "18.3.0",
3
+ "version": "18.3.2",
4
4
  "description": "Agents are just folders. The format, the runner, the checks.",
5
5
  "license": "FSL-1.1-ALv2",
6
6
  "type": "module",
package/src/a2a-client.ts CHANGED
@@ -23,6 +23,7 @@
23
23
  //
24
24
  // No vault, no MCP: values in, values out. a2a-tools.ts is the agent's side.
25
25
 
26
+ import { spellingJoiners } from "./joiners.ts";
26
27
  import crypto from "node:crypto";
27
28
  import { viaEgress } from "./egress.ts";
28
29
  import { capBody, ResponseTooLarge } from "./untrusted-fetch.ts";
@@ -168,7 +169,11 @@ const HIDDEN = /[​-‏‪-‮⁠-⁤⁦-⁩\u0000-\u0008\u000B\u000C\u000E-
168
169
  /** `text` with hidden characters removed, and how many there were. */
169
170
  export function stripHidden(text: string): { text: string; removed: number } {
170
171
  let removed = 0;
171
- const out = text.replace(HIDDEN, () => {
172
+ // A joiner that is spelling (a Persian half-space, an Indic or emoji
173
+ // joiner — joiners.ts) stays: removing it misspells the word.
174
+ const spelling = spellingJoiners(text);
175
+ const out = text.replace(HIDDEN, (m: string, at: number) => {
176
+ if (spelling.has(at)) return m;
172
177
  removed++;
173
178
  return "";
174
179
  });
package/src/joiners.ts ADDED
@@ -0,0 +1,72 @@
1
+ // ZWNJ (U+200C) and ZWJ (U+200D) are invisible, and they are also spelling.
2
+ //
3
+ // In Persian the half-space is how a word is written: «کانال‌ها», «می‌شود».
4
+ // Arabic-script, Syriac, Thaana and N'Ko, and the Indic and other Brahmic
5
+ // scripts, use both joiners inside words. An emoji sequence (👨‍💻, 🏳️‍🌈) is
6
+ // glued with ZWJ. Flagging those as hidden text (scan.ts
7
+ // content/hidden-unicode) buried real findings under hundreds of false ones
8
+ // on a Persian workspace (cloudhost, 11 Nov 2026), and stripping them from an
9
+ // outside agent's reply (a2a-client.ts) misspelled every such word.
10
+ //
11
+ // So a joiner is spelling when it sits INSIDE a word of a script that uses
12
+ // joiners — a letter or mark of one on BOTH sides — or between two emoji.
13
+ // Anywhere else (between Latin letters, at a word's edge, alone) it is still
14
+ // hidden text. Every other invisible character (zero-width space, bidi
15
+ // overrides and isolates, word joiner, BOM, Unicode tags) is never spelling.
16
+
17
+ const JOINER_SCRIPTS = [
18
+ "Arabic", "Syriac", "Thaana", "Nko",
19
+ "Devanagari", "Bengali", "Gurmukhi", "Gujarati", "Oriya", "Tamil", "Telugu", "Kannada", "Malayalam", "Sinhala",
20
+ "Tibetan", "Myanmar", "Khmer", "Mongolian",
21
+ ];
22
+ const LETTER = `(?:${JOINER_SCRIPTS.map((s) => `[\\p{scx=${s}}&&[\\p{L}\\p{M}]]`).join("|")})`;
23
+
24
+ /** A ZWNJ or ZWJ with a letter or mark of a joining script on one side and
25
+ * a letter or mark on the other — inside a word, or where a Persian suffix
26
+ * follows a Latin word («channel‌ها», «webhooks‌اند»; cloudhost, 11 Nov). */
27
+ const ANY_LETTER = "[\\p{L}\\p{M}]";
28
+ const IN_WORD = new RegExp(`(?<=${LETTER})[\\u200C\\u200D](?=${ANY_LETTER})|(?<=${ANY_LETTER})[\\u200C\\u200D](?=${LETTER})`, "gv");
29
+ /** A ZWJ between two emoji (a skin tone or VS16 may follow the first). */
30
+ const IN_EMOJI = /(?<=\p{Extended_Pictographic}\u{FE0F}?[\u{1F3FB}-\u{1F3FF}]?)\u200D(?=\p{Extended_Pictographic})/gu;
31
+
32
+ /** A right-to-left LETTER (Arabic-script, Hebrew, Syriac, Thaana, N'Ko) —
33
+ * letters only, so a mark (ALM is Arabic-script) is never its own evidence. */
34
+ const RTL_LETTER = new RegExp("[[\\p{scx=Arabic}\\p{scx=Hebrew}\\p{scx=Syriac}\\p{scx=Thaana}\\p{scx=Nko}]&&\\p{L}]", "v");
35
+ /** A run of bidi MARKS — LRM, RLM, ALM. Unlike overrides and isolates they
36
+ * move nothing: they settle where a neutral (a backtick, a dot) sits, which
37
+ * is how a Latin file name stays in order inside Persian text. */
38
+ const MARKS = /[\u200E\u200F\u061C]+/gu;
39
+ const LATIN = /\p{scx=Latin}/u;
40
+ const MARKS_ANY = /[\u200E\u200F\u061C]/u;
41
+
42
+ /** The indices (UTF-16) of every invisible in `text` that is spelling, not
43
+ * hiding: a joiner of a joining script or emoji; and a run of bidi marks on a
44
+ * LINE with right-to-left letters, not splitting a Latin word (Codex review:
45
+ * judged per line, per whole run, by letters alone). */
46
+ export function spellingJoiners(text: string): Set<number> {
47
+ const at = new Set<number>();
48
+ if (/[\u200C\u200D]/.test(text)) for (const re of [IN_WORD, IN_EMOJI]) for (const m of text.matchAll(re)) at.add(m.index!);
49
+ if (/[\u200E\u200F\u061C]/.test(text)) {
50
+ // Line by line, each line classified once (Codex review: rescanning the
51
+ // line for every run of marks was quadratic on hostile input).
52
+ let lineStart = 0;
53
+ while (lineStart <= text.length) {
54
+ const nl = text.indexOf("\n", lineStart);
55
+ const lineEnd = nl === -1 ? text.length : nl;
56
+ const line = text.slice(lineStart, lineEnd);
57
+ if (MARKS_ANY.test(line) && RTL_LETTER.test(line)) {
58
+ for (const m of line.matchAll(MARKS)) {
59
+ const start = lineStart + m.index!;
60
+ const end = start + m[0].length;
61
+ // "ig\u200E\u200Enore": marks between two Latin letters split a
62
+ // word; they order nothing there, so they are still hidden text.
63
+ if (LATIN.test(text[start - 1] ?? "") && LATIN.test(text[end] ?? "")) continue;
64
+ for (let k = start; k < end; k++) at.add(k);
65
+ }
66
+ }
67
+ if (nl === -1) break;
68
+ lineStart = nl + 1;
69
+ }
70
+ }
71
+ return at;
72
+ }
package/src/scan.ts CHANGED
@@ -26,6 +26,7 @@
26
26
  // The reason is required: an ignore without one ignores nothing and is itself
27
27
  // reported, because "why is this allowed?" is the question a reviewer asks.
28
28
 
29
+ import { spellingJoiners } from "./joiners.ts";
29
30
  import crypto from "node:crypto";
30
31
  import matter, { frontmatterErrorLine, frontmatterErrorText, parseLenient, configMatter } from "./matter.ts";
31
32
  import { refNames } from "./refs.ts";
@@ -647,10 +648,14 @@ function scanContent(file: ScanFile, lines: string[], push: Push, untrusted = fa
647
648
  for (let i = 0; i < lines.length; i++) {
648
649
  const line = i === 0 ? lines[i]!.replace(/^/, "") : lines[i]!;
649
650
  if (!untrusted && /^\s*(?:```|~~~)/.test(line)) fenced = !fenced;
650
- HIDDEN.lastIndex = 0;
651
- if (HIDDEN.test(line)) {
652
- const kind = HIDDEN_NAMES.find(([re]) => re.test(line))?.[1] ?? "invisible characters";
653
- const n = line.match(HIDDEN)?.length ?? 0;
651
+ // A half-space inside a Persian word, a joiner in an Indic word or an
652
+ // emoji sequence is spelling, not hiding (joiners.ts): not counted.
653
+ const spelling = spellingJoiners(line);
654
+ const hits = [...line.matchAll(HIDDEN)].filter((m) => !spelling.has(m.index!));
655
+ if (hits.length) {
656
+ const found = hits.map((m) => m[0]).join("");
657
+ const kind = HIDDEN_NAMES.find(([re]) => re.test(found))?.[1] ?? "invisible characters";
658
+ const n = hits.length;
654
659
  const tagged = /\uDB40[\uDC00-\uDC7F]/.test(line) ? ` that read as: "${decodeTags(line).slice(0, 80)}"` : "";
655
660
  push("content/hidden-unicode", file.path, i + 1, line, `${n} ${kind}${redactText(tagged)} — invisible to a reviewer, read by the model`);
656
661
  }