agent-customs 0.0.0-stage → 1.0.0
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.
- package/LICENSE.md +341 -0
- package/README.md +592 -2
- package/bin/agent-customs.mjs +194 -0
- package/package.json +77 -4
- package/site/.well-known/agent-customs-key.json +13 -0
- package/site/certificate.js +944 -0
- package/site/customs/analyze.js +1224 -0
- package/site/customs/auto.js +44 -0
- package/site/customs/canary.js +270 -0
- package/site/customs/canonical.js +123 -0
- package/site/customs/capabilities.js +387 -0
- package/site/customs/diff.js +236 -0
- package/site/customs/english-words.js +153 -0
- package/site/customs/guard-notice.js +226 -0
- package/site/customs/guard-ui.js +105 -0
- package/site/customs/guard.js +259 -0
- package/site/customs/inspect.js +446 -0
- package/site/customs/judge.js +208 -0
- package/site/customs/languages.js +826 -0
- package/site/customs/locks.js +967 -0
- package/site/customs/pins.js +119 -0
- package/site/customs/protocols.js +621 -0
- package/site/customs/receipts.js +154 -0
- package/site/customs/rules.js +1470 -0
- package/site/customs/unicode.js +361 -0
- package/site/runtime/LICENSE.txt +176 -0
- package/site/runtime/generated/graph.gen.mjs +83 -0
- package/site/runtime/generated/validation.gen.mjs +70 -0
- package/site/runtime/hocon.js +262 -0
- package/site/runtime/kernel.js +237 -0
- package/site/runtime/model.js +44 -0
- package/tests/fixtures/official/NOTICE +3 -0
- package/tests/fixtures/official/guesthouse_agentified/agent-manifest.json +86 -0
- package/tests/fixtures/official/guesthouse_agentified/links.json +6 -0
- package/tests/fixtures/official/guesthouse_agentified/tidewhistle_guesthouse.network.json +56 -0
- package/tests/fixtures/official/harbor_tours_agentified/agent-manifest.json +86 -0
- package/tests/fixtures/official/harbor_tours_agentified/links.json +6 -0
- package/tests/fixtures/official/harbor_tours_agentified/marrow_point_harbor_tours.network.json +56 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/agent-manifest.json +78 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/links.json +6 -0
- package/tests/fixtures/official/pizza_restaurant_agentified/pizza_restaurant_website_assistant.network.json +156 -0
- package/tools/bench.mjs +731 -0
- package/tools/external-heldout.mjs +337 -0
- package/tools/fs-fetch.mjs +19 -0
- package/tools/heldout-corpus.mjs +135 -0
- package/tools/inspect-local.mjs +88 -0
- package/tools/round2-corpus.mjs +395 -0
- package/tools/round3-corpus.mjs +192 -0
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
// unicode.js: find and reveal characters a person cannot see but a model can read.
|
|
2
|
+
//
|
|
3
|
+
// Published agent instructions are public, so anyone can read them before trusting
|
|
4
|
+
// a network. Invisible characters break that promise: Unicode "tag" characters
|
|
5
|
+
// (U+E0000-U+E007F) can carry a whole hidden sentence that most screens show as
|
|
6
|
+
// nothing, zero-width characters can hide or split words, and bidirectional controls
|
|
7
|
+
// can make text display in a different order than a model reads it ("Trojan Source").
|
|
8
|
+
|
|
9
|
+
const TAG_START = 0xe0000;
|
|
10
|
+
const TAG_END = 0xe007f;
|
|
11
|
+
|
|
12
|
+
// Zero-width and other invisible formatting characters.
|
|
13
|
+
const INVISIBLE = new Map([
|
|
14
|
+
[0x00ad, "SOFT HYPHEN"],
|
|
15
|
+
[0x034f, "COMBINING GRAPHEME JOINER"],
|
|
16
|
+
[0x115f, "HANGUL CHOSEONG FILLER"],
|
|
17
|
+
[0x1160, "HANGUL JUNGSEONG FILLER"],
|
|
18
|
+
[0x180e, "MONGOLIAN VOWEL SEPARATOR"],
|
|
19
|
+
[0x200b, "ZERO WIDTH SPACE"],
|
|
20
|
+
[0x200c, "ZERO WIDTH NON-JOINER"],
|
|
21
|
+
[0x200d, "ZERO WIDTH JOINER"],
|
|
22
|
+
[0x2060, "WORD JOINER"],
|
|
23
|
+
[0x2061, "FUNCTION APPLICATION"],
|
|
24
|
+
[0x2062, "INVISIBLE TIMES"],
|
|
25
|
+
[0x2063, "INVISIBLE SEPARATOR"],
|
|
26
|
+
[0x2064, "INVISIBLE PLUS"],
|
|
27
|
+
[0x3164, "HANGUL FILLER"],
|
|
28
|
+
[0xfeff, "ZERO WIDTH NO-BREAK SPACE"],
|
|
29
|
+
[0xffa0, "HALFWIDTH HANGUL FILLER"],
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
// Bidirectional controls that reorder how text is displayed.
|
|
33
|
+
const BIDI = new Map([
|
|
34
|
+
[0x061c, "ARABIC LETTER MARK"],
|
|
35
|
+
[0x200e, "LEFT-TO-RIGHT MARK"],
|
|
36
|
+
[0x200f, "RIGHT-TO-LEFT MARK"],
|
|
37
|
+
[0x202a, "LEFT-TO-RIGHT EMBEDDING"],
|
|
38
|
+
[0x202b, "RIGHT-TO-LEFT EMBEDDING"],
|
|
39
|
+
[0x202c, "POP DIRECTIONAL FORMATTING"],
|
|
40
|
+
[0x202d, "LEFT-TO-RIGHT OVERRIDE"],
|
|
41
|
+
[0x202e, "RIGHT-TO-LEFT OVERRIDE"],
|
|
42
|
+
[0x2066, "LEFT-TO-RIGHT ISOLATE"],
|
|
43
|
+
[0x2067, "RIGHT-TO-LEFT ISOLATE"],
|
|
44
|
+
[0x2068, "FIRST STRONG ISOLATE"],
|
|
45
|
+
[0x2069, "POP DIRECTIONAL ISOLATE"],
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
const PICTOGRAPHIC = /\p{Extended_Pictographic}/u;
|
|
49
|
+
|
|
50
|
+
// Every character Unicode says draws nothing ("default ignorable"). The lists above name
|
|
51
|
+
// the common ones; this catches the rest, such as U+206A-U+206F and unassigned ones.
|
|
52
|
+
const DEFAULT_IGNORABLE = /\p{Default_Ignorable_Code_Point}/u;
|
|
53
|
+
|
|
54
|
+
// Khmer and Mongolian writing use some of those characters (the Khmer inherent vowels and
|
|
55
|
+
// the Mongolian free variation selectors), so they do not count as hidden. The rules still
|
|
56
|
+
// skip them.
|
|
57
|
+
function isScriptIgnorable(cp) {
|
|
58
|
+
return cp === 0x17b4 || cp === 0x17b5 || (cp >= 0x180b && cp <= 0x180d) || cp === 0x180f;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The flags of England, Scotland and Wales are a black flag followed by tag characters
|
|
62
|
+
// ("gbeng", "gbsct", "gbwls"). Those exact sequences are emoji, not hidden text.
|
|
63
|
+
const FLAG_TAGS = /(?<=\u{1F3F4})\u{E0067}\u{E0062}(?:\u{E0065}\u{E006E}\u{E0067}|\u{E0073}\u{E0063}\u{E0074}|\u{E0077}\u{E006C}\u{E0073})\u{E007F}/gu;
|
|
64
|
+
const withoutFlagTags = (text) => text.replace(FLAG_TAGS, "");
|
|
65
|
+
|
|
66
|
+
// Characters that end a line. The rules read each as a newline, so clauses split there as
|
|
67
|
+
// they would at an ordinary line break, and the words around them stay apart.
|
|
68
|
+
const LINE_BREAKS = new Set([0x0b, 0x0c, 0x0d, 0x85, 0x2028, 0x2029]);
|
|
69
|
+
|
|
70
|
+
// Typographic quotes, which word processors and phones type for you, become plain ones, so
|
|
71
|
+
// "Don’t ask for passwords" reads as "Don't ask ...", a negation, not a request.
|
|
72
|
+
const QUOTES = new Map([
|
|
73
|
+
[0x02bc, "'"], [0x2018, "'"], [0x2019, "'"], [0x201a, "'"], [0x201b, "'"], [0x2032, "'"],
|
|
74
|
+
[0x201c, '"'], [0x201d, '"'], [0x201e, '"'], [0x201f, '"'], [0x2033, '"'],
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
function isVariationSelector(cp) {
|
|
78
|
+
return (cp >= 0xfe00 && cp <= 0xfe0f) || (cp >= 0xe0100 && cp <= 0xe01ef);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function isPrivateUse(cp) {
|
|
82
|
+
return (cp >= 0xe000 && cp <= 0xf8ff) || (cp >= 0xf0000 && cp <= 0xffffd) || (cp >= 0x100000 && cp <= 0x10fffd);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function isControl(cp) {
|
|
86
|
+
return (cp < 0x20 && cp !== 0x09 && cp !== 0x0a && cp !== 0x0d) || (cp >= 0x7f && cp <= 0x9f);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function hex(cp) {
|
|
90
|
+
return "U+" + cp.toString(16).toUpperCase().padStart(4, "0");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const isTag = (cp) => cp >= TAG_START && cp <= TAG_END;
|
|
94
|
+
|
|
95
|
+
// The ASCII character a tag character stands for. The tag markers themselves read as a space.
|
|
96
|
+
function tagChar(cp) {
|
|
97
|
+
const ascii = cp - TAG_START;
|
|
98
|
+
if (ascii >= 0x20 && ascii <= 0x7e) return String.fromCharCode(ascii);
|
|
99
|
+
return ascii === 0x7f || ascii === 0x01 ? " " : "";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// A character that draws nothing, has no standard meaning, or is a control character. The
|
|
103
|
+
// lowest default-ignorable character is U+00AD, so plain ASCII skips the regex test.
|
|
104
|
+
function drawsNothing(cp, ch) {
|
|
105
|
+
return (cp >= 0xad && DEFAULT_IGNORABLE.test(ch)) || isPrivateUse(cp) || isControl(cp);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Whether chars[i] is hidden from a person reading the text: the one test that
|
|
110
|
+
* scanHidden counts and revealHidden marks. Ordinary uses are not hidden: a joiner inside
|
|
111
|
+
* an emoji, emoji style after a pictograph, and the characters Khmer and Mongolian need.
|
|
112
|
+
* Tag characters are hidden too; callers decode them first.
|
|
113
|
+
*/
|
|
114
|
+
function isHiddenAt(chars, i) {
|
|
115
|
+
const ch = chars[i];
|
|
116
|
+
const cp = ch.codePointAt(0);
|
|
117
|
+
if (!drawsNothing(cp, ch) || isScriptIgnorable(cp)) return false;
|
|
118
|
+
// A zero-width joiner between two pictographs builds one emoji (a family, a flag).
|
|
119
|
+
if (cp === 0x200d) return !(PICTOGRAPHIC.test(chars[i - 1] || "") && PICTOGRAPHIC.test(chars[i + 1] || ""));
|
|
120
|
+
// U+FE00-U+FE0F after a pictograph asks for emoji style.
|
|
121
|
+
if (cp >= 0xfe00 && cp <= 0xfe0f) return !PICTOGRAPHIC.test(chars[i - 1] || "");
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Scan one string for hidden characters.
|
|
127
|
+
*
|
|
128
|
+
* :param text: Any string from a published file.
|
|
129
|
+
* :return: {tags, tagText, invisible, bidi, variation, privateUse, control, total},
|
|
130
|
+
* where tagText is the ASCII sentence hidden in tag characters, if any.
|
|
131
|
+
*/
|
|
132
|
+
export function scanHidden(text) {
|
|
133
|
+
const out = { tags: 0, tagText: "", invisible: 0, invisibleNames: new Set(), bidi: 0, bidiNames: new Set(),
|
|
134
|
+
variation: 0, variationSupplement: 0, privateUse: 0, control: 0, total: 0 };
|
|
135
|
+
if (typeof text !== "string" || !text) return out;
|
|
136
|
+
const chars = Array.from(withoutFlagTags(text));
|
|
137
|
+
for (let i = 0; i < chars.length; i += 1) {
|
|
138
|
+
const cp = chars[i].codePointAt(0);
|
|
139
|
+
if (isTag(cp)) {
|
|
140
|
+
out.tags += 1;
|
|
141
|
+
out.tagText += tagChar(cp);
|
|
142
|
+
} else if (!isHiddenAt(chars, i)) {
|
|
143
|
+
continue;
|
|
144
|
+
} else if (INVISIBLE.has(cp)) {
|
|
145
|
+
out.invisible += 1;
|
|
146
|
+
out.invisibleNames.add(INVISIBLE.get(cp));
|
|
147
|
+
} else if (BIDI.has(cp)) {
|
|
148
|
+
out.bidi += 1;
|
|
149
|
+
out.bidiNames.add(BIDI.get(cp));
|
|
150
|
+
} else if (isVariationSelector(cp)) {
|
|
151
|
+
out.variation += 1;
|
|
152
|
+
if (cp >= 0xe0100) out.variationSupplement += 1;
|
|
153
|
+
} else if (isPrivateUse(cp)) {
|
|
154
|
+
out.privateUse += 1;
|
|
155
|
+
} else if (isControl(cp)) {
|
|
156
|
+
out.control += 1;
|
|
157
|
+
} else {
|
|
158
|
+
out.invisible += 1;
|
|
159
|
+
out.invisibleNames.add(`INVISIBLE CHARACTER ${hex(cp)}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
out.tagText = out.tagText.replace(/\s+/g, " ").trim();
|
|
163
|
+
const zalgo = text.match(/\p{M}{3,}/gu);
|
|
164
|
+
if (zalgo) {
|
|
165
|
+
out.invisible += zalgo.length;
|
|
166
|
+
out.invisibleNames.add("EXCESSIVE COMBINING MARKS");
|
|
167
|
+
}
|
|
168
|
+
out.total = out.tags + out.invisible + out.bidi + out.variation + out.privateUse + out.control;
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Make hidden characters visible, for a person reviewing the text.
|
|
174
|
+
* Tag runs become ⟦hidden text: "..."⟧ and other characters ⟦U+XXXX⟧.
|
|
175
|
+
*
|
|
176
|
+
* :param text: Any string.
|
|
177
|
+
* :return: The same text with every hidden character shown.
|
|
178
|
+
*/
|
|
179
|
+
export function revealHidden(text) {
|
|
180
|
+
if (typeof text !== "string" || !text) return text;
|
|
181
|
+
let out = "";
|
|
182
|
+
let tagRun = "";
|
|
183
|
+
const flush = () => {
|
|
184
|
+
if (tagRun) {
|
|
185
|
+
out += `⟦hidden text: "${tagRun}"⟧`;
|
|
186
|
+
tagRun = "";
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
const chars = Array.from(withoutFlagTags(text));
|
|
190
|
+
for (let i = 0; i < chars.length; i += 1) {
|
|
191
|
+
const cp = chars[i].codePointAt(0);
|
|
192
|
+
if (isTag(cp)) {
|
|
193
|
+
tagRun += tagChar(cp);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
flush();
|
|
197
|
+
out += isHiddenAt(chars, i) ? `⟦${hex(cp)}⟧` : chars[i];
|
|
198
|
+
}
|
|
199
|
+
flush();
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Remove every hidden character, so pattern rules see the words a model would read
|
|
205
|
+
* once the hiding characters are skipped (for example "password").
|
|
206
|
+
*
|
|
207
|
+
* Then compatibility forms become their plain letters (NFKC): a no-break or ideographic
|
|
208
|
+
* space is a space, and fullwidth or mathematical letters ("card", "𝐩𝐢𝐧") are ordinary
|
|
209
|
+
* ones. Runs of spaces and tabs become one space, so "card number" is "card number".
|
|
210
|
+
*
|
|
211
|
+
* :param text: Any string.
|
|
212
|
+
* :return: The visible text plus any tag-hidden text, on a line of its own.
|
|
213
|
+
*/
|
|
214
|
+
export function normalizeForRules(text) {
|
|
215
|
+
if (typeof text !== "string") return "";
|
|
216
|
+
let visible = "";
|
|
217
|
+
let hidden = "";
|
|
218
|
+
// One pass: tag text is collected, and every character that draws nothing is dropped,
|
|
219
|
+
// including the ordinary ones (an emoji joiner changes no word).
|
|
220
|
+
for (const ch of withoutFlagTags(text)) {
|
|
221
|
+
const cp = ch.codePointAt(0);
|
|
222
|
+
if (isTag(cp)) hidden += tagChar(cp);
|
|
223
|
+
else if (LINE_BREAKS.has(cp)) visible += "\n";
|
|
224
|
+
else if (QUOTES.has(cp)) visible += QUOTES.get(cp);
|
|
225
|
+
else if (!drawsNothing(cp, ch)) visible += ch;
|
|
226
|
+
}
|
|
227
|
+
hidden = hidden.replace(/\s+/g, " ").trim();
|
|
228
|
+
// Keep newlines: the rules split clauses at them.
|
|
229
|
+
visible = visible.normalize("NFKC").replace(/[^\S\n]+/g, " ");
|
|
230
|
+
return hidden ? `${visible}\n${hidden}` : visible;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Letters from scripts that look like Latin letters.
|
|
234
|
+
const CONFUSABLE_SCRIPTS = [
|
|
235
|
+
["Cyrillic", /\p{Script=Cyrillic}/u],
|
|
236
|
+
["Greek", /\p{Script=Greek}/u],
|
|
237
|
+
["Armenian", /\p{Script=Armenian}/u],
|
|
238
|
+
["Cherokee", /\p{Script=Cherokee}/u],
|
|
239
|
+
];
|
|
240
|
+
|
|
241
|
+
// Look-alike letters from Cyrillic, Greek, Armenian, Cherokee and IPA/Latin-extended
|
|
242
|
+
// mapped to their ASCII Latin skeleton.
|
|
243
|
+
const CONFUSABLE_CHARS = new Map([
|
|
244
|
+
// Cyrillic
|
|
245
|
+
["а", "a"], ["А", "A"], ["В", "B"], ["е", "e"], ["Е", "E"], ["ё", "e"], ["Ё", "E"],
|
|
246
|
+
["і", "i"], ["І", "I"], ["ї", "i"], ["Ї", "I"], ["ј", "j"], ["Ј", "J"], ["К", "K"],
|
|
247
|
+
["М", "M"], ["Н", "H"], ["о", "o"], ["О", "O"], ["р", "p"], ["Р", "P"], ["с", "c"],
|
|
248
|
+
["С", "C"], ["Т", "T"], ["у", "y"], ["У", "Y"], ["х", "x"], ["Х", "X"], ["ѕ", "s"],
|
|
249
|
+
["Ѕ", "S"], ["һ", "h"], ["ԁ", "d"], ["ԍ", "g"], ["ԛ", "q"], ["Ԛ", "Q"], ["ԝ", "w"],
|
|
250
|
+
["Ԝ", "W"], ["ѵ", "v"], ["ӏ", "l"],
|
|
251
|
+
// Greek
|
|
252
|
+
["α", "a"], ["Α", "A"], ["β", "b"], ["Β", "B"], ["ε", "e"], ["Ε", "E"], ["ζ", "z"],
|
|
253
|
+
["Ζ", "Z"], ["η", "n"], ["Η", "H"], ["ι", "i"], ["Ι", "I"], ["κ", "k"], ["Κ", "K"],
|
|
254
|
+
["μ", "u"], ["Μ", "M"], ["ν", "v"], ["Ν", "N"], ["ο", "o"], ["Ο", "O"], ["ρ", "p"],
|
|
255
|
+
["Ρ", "P"], ["ς", "s"], ["σ", "s"], ["τ", "t"], ["Τ", "T"], ["υ", "u"], ["Υ", "Y"],
|
|
256
|
+
["χ", "x"], ["Χ", "X"], ["γ", "y"], ["ω", "w"],
|
|
257
|
+
// Armenian & Cherokee & Latin/IPA lookalikes
|
|
258
|
+
["օ", "o"], ["Օ", "O"], ["ս", "u"], ["հ", "h"], ["Տ", "S"], ["Ք", "P"],
|
|
259
|
+
["Ꭺ", "A"], ["Ꮀ", "F"], ["Ꮐ", "G"], ["Ꮋ", "H"], ["Ꭻ", "J"], ["Ꮮ", "L"], ["Ꮇ", "M"],
|
|
260
|
+
["Ꮲ", "P"], ["Ꭱ", "R"], ["Ꮪ", "S"], ["Ꮦ", "T"], ["Ꮩ", "V"], ["Ꮃ", "W"], ["Ꮓ", "Z"],
|
|
261
|
+
["Ꮟ", "b"], ["Ꭵ", "i"], ["Ꮥ", "d"],
|
|
262
|
+
["ɑ", "a"], ["ɒ", "a"], ["ɓ", "b"], ["ᴄ", "c"], ["ɗ", "d"], ["ɛ", "e"], ["ɡ", "g"],
|
|
263
|
+
["ɢ", "G"], ["ʜ", "H"], ["ɪ", "i"], ["ɩ", "i"], ["ʝ", "j"], ["ᴋ", "k"], ["ʟ", "l"],
|
|
264
|
+
["ɴ", "N"], ["ᴏ", "o"], ["ɵ", "o"], ["ᴘ", "p"], ["ʀ", "R"], ["ʂ", "s"], ["ᴛ", "t"],
|
|
265
|
+
["ᴜ", "u"], ["ʋ", "v"], ["ᴡ", "w"], ["ʏ", "Y"], ["ᴢ", "z"], ["ı", "i"], ["ſ", "s"],
|
|
266
|
+
]);
|
|
267
|
+
|
|
268
|
+
const HAS_CONFUSABLE_SCRIPT = /\p{Script=Cyrillic}|\p{Script=Greek}|\p{Script=Armenian}|\p{Script=Cherokee}/u;
|
|
269
|
+
|
|
270
|
+
function foldWordChars(word) {
|
|
271
|
+
let out = "";
|
|
272
|
+
for (const ch of word) out += CONFUSABLE_CHARS.get(ch) ?? ch;
|
|
273
|
+
return out;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function isAllConfusableLetters(word) {
|
|
277
|
+
let letters = 0;
|
|
278
|
+
for (const ch of word) {
|
|
279
|
+
if (!/\p{L}/u.test(ch)) continue;
|
|
280
|
+
letters += 1;
|
|
281
|
+
if (!CONFUSABLE_CHARS.has(ch)) return false;
|
|
282
|
+
}
|
|
283
|
+
return letters > 0;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Fold look-alike characters (Cyrillic, Greek, etc.) to their Latin skeleton where
|
|
288
|
+
* words mix scripts, or where an all-confusable word sits inside a predominantly Latin
|
|
289
|
+
* line. Genuine non-Latin text (Russian, Greek...) is left untouched so language checks
|
|
290
|
+
* still read it accurately.
|
|
291
|
+
*
|
|
292
|
+
* :param text: Normalized text.
|
|
293
|
+
* :return: Text with confusable tokens folded to ASCII Latin.
|
|
294
|
+
*/
|
|
295
|
+
export function foldConfusableTokens(text) {
|
|
296
|
+
if (typeof text !== "string" || !text) return "";
|
|
297
|
+
return text.split("\n").map((line) => {
|
|
298
|
+
const words = line.split(/(\s+)/);
|
|
299
|
+
const latinCount = words.filter((w) => /\p{Script=Latin}/u.test(w) && !HAS_CONFUSABLE_SCRIPT.test(w)).length;
|
|
300
|
+
const nonLatinNative = words.filter((w) => HAS_CONFUSABLE_SCRIPT.test(w) && !/\p{Script=Latin}/u.test(w) && !isAllConfusableLetters(w)).length;
|
|
301
|
+
const mostlyLatin = latinCount >= 2 && latinCount > nonLatinNative;
|
|
302
|
+
return words.map((tok) => {
|
|
303
|
+
if (!tok || /^\s+$/.test(tok)) return tok;
|
|
304
|
+
const hasLatin = /\p{Script=Latin}/u.test(tok);
|
|
305
|
+
const hasConfusable = HAS_CONFUSABLE_SCRIPT.test(tok) || [...tok].some((ch) => CONFUSABLE_CHARS.has(ch));
|
|
306
|
+
if (!hasConfusable) return tok;
|
|
307
|
+
if (hasLatin || (mostlyLatin && isAllConfusableLetters(tok))) return foldWordChars(tok);
|
|
308
|
+
return tok;
|
|
309
|
+
}).join("");
|
|
310
|
+
}).join("\n");
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Remove hidden tag, bidi, invisible, non-emoji variation, private-use and control
|
|
315
|
+
* characters from runtime text while keeping ordinary writing and emoji intact.
|
|
316
|
+
*
|
|
317
|
+
* :param text: Any runtime string.
|
|
318
|
+
* :return: Cleaned text.
|
|
319
|
+
*/
|
|
320
|
+
export function stripHiddenChars(text) {
|
|
321
|
+
if (typeof text !== "string" || !text) return String(text ?? "");
|
|
322
|
+
const chars = Array.from(withoutFlagTags(text));
|
|
323
|
+
let out = "";
|
|
324
|
+
for (let i = 0; i < chars.length; i += 1) {
|
|
325
|
+
const cp = chars[i].codePointAt(0);
|
|
326
|
+
if (isTag(cp) || isHiddenAt(chars, i)) continue;
|
|
327
|
+
out += chars[i];
|
|
328
|
+
}
|
|
329
|
+
return out;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Find words that mix Latin letters with look-alike letters from another script,
|
|
334
|
+
* such as "Sаvings" with a Cyrillic "а". These fool people, not models.
|
|
335
|
+
*
|
|
336
|
+
* :param text: A name, brand or label.
|
|
337
|
+
* :return: A list of {word, scripts} for each mixed word.
|
|
338
|
+
*/
|
|
339
|
+
export function findMixedScriptWords(text) {
|
|
340
|
+
if (typeof text !== "string" || !text) return [];
|
|
341
|
+
const found = [];
|
|
342
|
+
const tokens = text.split(/[\s_\-./:]+/u).filter(Boolean)
|
|
343
|
+
.map((raw) => raw.replace(/^[^\p{L}\p{N}]+|[^\p{L}\p{N}]+$/gu, ""))
|
|
344
|
+
.filter(Boolean);
|
|
345
|
+
const latinWords = tokens.filter((w) => /\p{Script=Latin}/u.test(w) && !HAS_CONFUSABLE_SCRIPT.test(w)).length;
|
|
346
|
+
for (const word of tokens) {
|
|
347
|
+
const scripts = CONFUSABLE_SCRIPTS.filter(([, re]) => re.test(word)).map(([name]) => name);
|
|
348
|
+
if (!scripts.length) continue;
|
|
349
|
+
if (/\p{Script=Latin}/u.test(word)) {
|
|
350
|
+
found.push({ word, scripts });
|
|
351
|
+
} else if (latinWords >= 2 && [...word].length >= 3 && isAllConfusableLetters(word)) {
|
|
352
|
+
// A whole word spelled only with look-alike letters among Latin words ("аррӏе ID") passes
|
|
353
|
+
// for English. Lone symbols such as β or γ in formulas are left alone.
|
|
354
|
+
found.push({ word, scripts });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
// Fullwidth Latin letters (Pay) and Mathematical styled letters (𝐩𝐚𝐬𝐬) look like ASCII.
|
|
358
|
+
if (/[A-Za-z]/u.test(text)) found.push({ word: text, scripts: ["Fullwidth Latin"] });
|
|
359
|
+
if (/[\u{1D400}-\u{1D7FF}]/u.test(text)) found.push({ word: text, scripts: ["Mathematical styled Latin"] });
|
|
360
|
+
return found;
|
|
361
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// GENERATED by nsxc from neuro_san/kernel/graph.py. Do not edit by hand.
|
|
2
|
+
// Regenerate with: python -m nsxc.transpile neuro_san/kernel/graph.py
|
|
3
|
+
|
|
4
|
+
const _get = (o, k, d) => (o != null && Object.prototype.hasOwnProperty.call(o, k) ? o[k] : (d !== undefined ? d : null));
|
|
5
|
+
const _contains = (needle, hay) => (typeof hay === "string" ? hay.includes(needle) : Array.isArray(hay) ? hay.includes(needle) : (hay && typeof hay === "object") ? Object.prototype.hasOwnProperty.call(hay, needle) : false);
|
|
6
|
+
|
|
7
|
+
export function is_external_agent(ref) {
|
|
8
|
+
return (ref.startsWith("http://") || ref.startsWith("https://") || ref.startsWith("/"));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function is_mcp_ref(ref) {
|
|
12
|
+
if ((!(ref.startsWith("http://")) && !(ref.startsWith("https://")))) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
let lowered = ref.toLowerCase();
|
|
16
|
+
return (_contains("/mcp/", lowered) || lowered.endsWith("/mcp") || _contains("//mcp.", lowered) || _contains(".mcp.", lowered));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function find_front_man(config) {
|
|
20
|
+
let tools = _get(config, "tools");
|
|
21
|
+
if (tools === null) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
for (const agent of tools) {
|
|
25
|
+
let has_instructions = _get(agent, "instructions");
|
|
26
|
+
if ((has_instructions && !(_get(agent, "class")) && !(_get(agent, "toolbox")))) {
|
|
27
|
+
return _get(agent, "name");
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if ((tools).length > 0) {
|
|
31
|
+
return _get(tools[0], "name");
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function agent_names(config) {
|
|
37
|
+
let names = [];
|
|
38
|
+
let tools = _get(config, "tools");
|
|
39
|
+
if (tools === null) {
|
|
40
|
+
return names;
|
|
41
|
+
}
|
|
42
|
+
for (const agent of tools) {
|
|
43
|
+
let name = _get(agent, "name");
|
|
44
|
+
if (name !== null) {
|
|
45
|
+
names.push(name);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return names;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function classify_tool(config, ref) {
|
|
52
|
+
if ((!(typeof ref === "string") || is_mcp_ref(ref))) {
|
|
53
|
+
return "mcp";
|
|
54
|
+
}
|
|
55
|
+
let names = agent_names(config);
|
|
56
|
+
if ((is_external_agent(ref) && !_contains(ref, names))) {
|
|
57
|
+
return "remote";
|
|
58
|
+
}
|
|
59
|
+
let spec = _spec_for(config, ref);
|
|
60
|
+
if (spec === null) {
|
|
61
|
+
return "missing";
|
|
62
|
+
}
|
|
63
|
+
if (_get(spec, "class")) {
|
|
64
|
+
return "coded";
|
|
65
|
+
}
|
|
66
|
+
if (_get(spec, "toolbox")) {
|
|
67
|
+
return "toolbox";
|
|
68
|
+
}
|
|
69
|
+
return "agent";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function _spec_for(config, name) {
|
|
73
|
+
let tools = _get(config, "tools");
|
|
74
|
+
if (tools === null) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
for (const agent of tools) {
|
|
78
|
+
if (_get(agent, "name") === name) {
|
|
79
|
+
return agent;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|