@cello-protocol/cli 0.0.305 → 0.0.307
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/.claude-plugin/marketplace.json +15 -0
- package/README.md +107 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +564 -0
- package/dist/daemon/account-page-assets.d.ts +4 -0
- package/dist/daemon/account-page-assets.js +160 -0
- package/dist/daemon/account-page.d.ts +14 -0
- package/dist/daemon/account-page.js +104 -0
- package/dist/daemon/address.d.ts +10 -0
- package/dist/daemon/address.js +34 -0
- package/dist/daemon/away.d.ts +31 -0
- package/dist/daemon/away.js +65 -0
- package/dist/daemon/channel-store.d.ts +112 -0
- package/dist/daemon/channel-store.js +284 -0
- package/dist/daemon/channels.d.ts +46 -0
- package/dist/daemon/channels.js +1049 -0
- package/dist/daemon/contacts.d.ts +26 -0
- package/dist/daemon/contacts.js +74 -0
- package/dist/daemon/engine.d.ts +80 -0
- package/dist/daemon/engine.js +2882 -0
- package/dist/daemon/errors.d.ts +5 -0
- package/dist/daemon/errors.js +16 -0
- package/dist/daemon/governance.d.ts +66 -0
- package/dist/daemon/governance.js +514 -0
- package/dist/daemon/guards.d.ts +36 -0
- package/dist/daemon/guards.js +140 -0
- package/dist/daemon/issuer-client.d.ts +56 -0
- package/dist/daemon/issuer-client.js +143 -0
- package/dist/daemon/link.d.ts +30 -0
- package/dist/daemon/link.js +191 -0
- package/dist/daemon/log.d.ts +1 -0
- package/dist/daemon/log.js +4 -0
- package/dist/daemon/main.d.ts +1 -0
- package/dist/daemon/main.js +511 -0
- package/dist/daemon/paths.d.ts +6 -0
- package/dist/daemon/paths.js +21 -0
- package/dist/daemon/pii.d.ts +24 -0
- package/dist/daemon/pii.js +146 -0
- package/dist/daemon/policy-cadence.d.ts +33 -0
- package/dist/daemon/policy-cadence.js +59 -0
- package/dist/daemon/policy-proposals.d.ts +41 -0
- package/dist/daemon/policy-proposals.js +83 -0
- package/dist/daemon/policy-store.d.ts +47 -0
- package/dist/daemon/policy-store.js +144 -0
- package/dist/daemon/presented.d.ts +36 -0
- package/dist/daemon/presented.js +94 -0
- package/dist/daemon/rate-limit.d.ts +17 -0
- package/dist/daemon/rate-limit.js +44 -0
- package/dist/daemon/reach.d.ts +63 -0
- package/dist/daemon/reach.js +207 -0
- package/dist/daemon/screening.d.ts +97 -0
- package/dist/daemon/screening.js +362 -0
- package/dist/daemon/settings.d.ts +125 -0
- package/dist/daemon/settings.js +73 -0
- package/dist/daemon/signal-rules.d.ts +55 -0
- package/dist/daemon/signal-rules.js +127 -0
- package/dist/daemon/signal-store.d.ts +53 -0
- package/dist/daemon/signal-store.js +114 -0
- package/dist/daemon/store.d.ts +188 -0
- package/dist/daemon/store.js +474 -0
- package/dist/daemon/tiers.d.ts +14 -0
- package/dist/daemon/tiers.js +9 -0
- package/dist/daemon/wallet.d.ts +73 -0
- package/dist/daemon/wallet.js +428 -0
- package/dist/daemon/who-label.d.ts +3 -0
- package/dist/daemon/who-label.js +11 -0
- package/dist/guidance.d.ts +39 -0
- package/dist/guidance.js +98 -0
- package/dist/hermes-bridge.d.ts +26 -0
- package/dist/hermes-bridge.js +180 -0
- package/dist/install-mcp.d.ts +6 -0
- package/dist/install-mcp.js +77 -0
- package/dist/ipc/client.d.ts +18 -0
- package/dist/ipc/client.js +107 -0
- package/dist/ipc/operations.d.ts +30 -0
- package/dist/ipc/operations.js +835 -0
- package/dist/ipc/protocol.d.ts +21 -0
- package/dist/ipc/protocol.js +1 -0
- package/dist/issuer-list-sign.d.ts +12 -0
- package/dist/issuer-list-sign.js +43 -0
- package/dist/local-operations.d.ts +2 -0
- package/dist/local-operations.js +73 -0
- package/dist/mcp-tools.d.ts +14 -0
- package/dist/mcp-tools.js +45 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +155 -0
- package/dist/protocol/aead.d.ts +4 -0
- package/dist/protocol/aead.js +35 -0
- package/dist/protocol/cbor.d.ts +40 -0
- package/dist/protocol/cbor.js +106 -0
- package/dist/protocol/chain.d.ts +44 -0
- package/dist/protocol/chain.js +126 -0
- package/dist/protocol/channel.d.ts +153 -0
- package/dist/protocol/channel.js +298 -0
- package/dist/protocol/encode.d.ts +6 -0
- package/dist/protocol/encode.js +21 -0
- package/dist/protocol/identity.d.ts +27 -0
- package/dist/protocol/identity.js +94 -0
- package/dist/protocol/issuer-list.d.ts +56 -0
- package/dist/protocol/issuer-list.js +193 -0
- package/dist/protocol/issuer-roots.d.ts +6 -0
- package/dist/protocol/issuer-roots.js +10 -0
- package/dist/protocol/key-agreement.d.ts +20 -0
- package/dist/protocol/key-agreement.js +88 -0
- package/dist/protocol/merkle.d.ts +16 -0
- package/dist/protocol/merkle.js +166 -0
- package/dist/protocol/ml-dsa.d.ts +28 -0
- package/dist/protocol/ml-dsa.js +58 -0
- package/dist/protocol/ml-kem.d.ts +14 -0
- package/dist/protocol/ml-kem.js +57 -0
- package/dist/protocol/pq-errors.d.ts +9 -0
- package/dist/protocol/pq-errors.js +23 -0
- package/dist/protocol/pq-warnings.d.ts +1 -0
- package/dist/protocol/pq-warnings.js +18 -0
- package/dist/protocol/presented-signals.d.ts +17 -0
- package/dist/protocol/presented-signals.js +92 -0
- package/dist/protocol/salt.d.ts +5 -0
- package/dist/protocol/salt.js +47 -0
- package/dist/protocol/seal.d.ts +58 -0
- package/dist/protocol/seal.js +220 -0
- package/dist/protocol/signal.d.ts +54 -0
- package/dist/protocol/signal.js +266 -0
- package/dist/protocol/status.d.ts +41 -0
- package/dist/protocol/status.js +64 -0
- package/dist/protocol/structures.d.ts +359 -0
- package/dist/protocol/structures.js +296 -0
- package/dist/protocol/transcript.d.ts +61 -0
- package/dist/protocol/transcript.js +319 -0
- package/dist/protocol/wire.d.ts +212 -0
- package/dist/protocol/wire.js +161 -0
- package/dist/require-node.d.ts +1 -0
- package/dist/require-node.js +10 -0
- package/dist/screener/affordance.d.ts +1 -0
- package/dist/screener/affordance.js +2 -0
- package/dist/screener/classifier-selfcheck.d.ts +29 -0
- package/dist/screener/classifier-selfcheck.js +56 -0
- package/dist/screener/exfil.d.ts +11 -0
- package/dist/screener/exfil.js +45 -0
- package/dist/screener/gitleaks-rules.d.ts +9 -0
- package/dist/screener/gitleaks-rules.js +226 -0
- package/dist/screener/inbound.d.ts +25 -0
- package/dist/screener/inbound.js +102 -0
- package/dist/screener/injection-classifier-onnx.d.ts +20 -0
- package/dist/screener/injection-classifier-onnx.js +89 -0
- package/dist/screener/injection-classifier-wasm.d.ts +2 -0
- package/dist/screener/injection-classifier-wasm.js +97 -0
- package/dist/screener/injection-patterns.d.ts +8 -0
- package/dist/screener/injection-patterns.js +48 -0
- package/dist/screener/injection-windows.d.ts +9 -0
- package/dist/screener/injection-windows.js +37 -0
- package/dist/screener/language.d.ts +15 -0
- package/dist/screener/language.js +71 -0
- package/dist/screener/linear-regex.d.ts +8 -0
- package/dist/screener/linear-regex.js +27 -0
- package/dist/screener/model-installer.d.ts +14 -0
- package/dist/screener/model-installer.js +61 -0
- package/dist/screener/outbound.d.ts +19 -0
- package/dist/screener/outbound.js +62 -0
- package/dist/screener/sanitize.d.ts +44 -0
- package/dist/screener/sanitize.js +361 -0
- package/dist/screener/scan-variants.d.ts +5 -0
- package/dist/screener/scan-variants.js +146 -0
- package/dist/screener/screener-model-manifest.d.ts +16 -0
- package/dist/screener/screener-model-manifest.js +20 -0
- package/dist/screener/screener-state.d.ts +29 -0
- package/dist/screener/screener-state.js +119 -0
- package/dist/screener/secrets.d.ts +18 -0
- package/dist/screener/secrets.js +84 -0
- package/dist/screener/worker.d.ts +6 -0
- package/dist/screener/worker.js +83 -0
- package/dist/setup.d.ts +9 -0
- package/dist/setup.js +252 -0
- package/dist/shipped-issuer-list.d.ts +1 -0
- package/dist/shipped-issuer-list.js +3 -0
- package/dist/signals-text.d.ts +46 -0
- package/dist/signals-text.js +81 -0
- package/dist/verify-seal.d.ts +9 -0
- package/dist/verify-seal.js +30 -0
- package/hermes/plugin/__init__.py +1040 -0
- package/hermes/plugin/plugin.yaml +30 -0
- package/hermes/skills/cello-bridge-setup/SKILL.md +38 -0
- package/hermes/skills/cello-policy/SKILL.md +44 -0
- package/package.json +48 -16
- package/plugins/cello/.claude-plugin/plugin.json +19 -0
- package/plugins/cello/.mcp.json +7 -0
- package/plugins/cello/skills/cello/SKILL.md +117 -0
- package/dist/arg-parse.d.ts +0 -19
- package/dist/arg-parse.d.ts.map +0 -1
- package/dist/arg-parse.js +0 -29
- package/dist/arg-parse.js.map +0 -1
- package/dist/bin/cello.d.ts +0 -15
- package/dist/bin/cello.d.ts.map +0 -1
- package/dist/bin/cello.js +0 -110
- package/dist/bin/cello.js.map +0 -1
- package/dist/cli-args.d.ts +0 -62
- package/dist/cli-args.d.ts.map +0 -1
- package/dist/cli-args.js +0 -129
- package/dist/cli-args.js.map +0 -1
- package/dist/commands.d.ts +0 -196
- package/dist/commands.d.ts.map +0 -1
- package/dist/commands.js +0 -1544
- package/dist/commands.js.map +0 -1
- package/dist/hermes/assets.d.ts +0 -41
- package/dist/hermes/assets.d.ts.map +0 -1
- package/dist/hermes/assets.js +0 -2281
- package/dist/hermes/assets.js.map +0 -1
- package/dist/hermes/install-hermes.d.ts +0 -50
- package/dist/hermes/install-hermes.d.ts.map +0 -1
- package/dist/hermes/install-hermes.js +0 -232
- package/dist/hermes/install-hermes.js.map +0 -1
- package/dist/json-out.d.ts +0 -41
- package/dist/json-out.d.ts.map +0 -1
- package/dist/json-out.js +0 -59
- package/dist/json-out.js.map +0 -1
- package/dist/node-runtime-guard-init.d.ts +0 -6
- package/dist/node-runtime-guard-init.d.ts.map +0 -1
- package/dist/node-runtime-guard-init.js +0 -7
- package/dist/node-runtime-guard-init.js.map +0 -1
- package/dist/node-runtime-guard.d.ts +0 -48
- package/dist/node-runtime-guard.d.ts.map +0 -1
- package/dist/node-runtime-guard.js +0 -79
- package/dist/node-runtime-guard.js.map +0 -1
- package/dist/parity-commands.d.ts +0 -427
- package/dist/parity-commands.d.ts.map +0 -1
- package/dist/parity-commands.js +0 -953
- package/dist/parity-commands.js.map +0 -1
- package/dist/registry.d.ts +0 -120
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -2169
- package/dist/registry.js.map +0 -1
- package/dist/screener-commands.d.ts +0 -85
- package/dist/screener-commands.d.ts.map +0 -1
- package/dist/screener-commands.js +0 -313
- package/dist/screener-commands.js.map +0 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
13
|
+
import { resolveScreenerRuntime, screenerRuntimeDir } from "./screener-state.js";
|
|
14
|
+
import { SCREENER_MODEL } from "./screener-model-manifest.js";
|
|
15
|
+
import { textWindows, aggregateWindowScores } from "./injection-windows.js";
|
|
16
|
+
const WASM_MODULE = "onnxruntime-web";
|
|
17
|
+
function resolveOrtWeb() {
|
|
18
|
+
const bases = [join(screenerRuntimeDir(), "resolver.cjs")];
|
|
19
|
+
const transformers = resolveScreenerRuntime();
|
|
20
|
+
if (transformers)
|
|
21
|
+
bases.push(transformers);
|
|
22
|
+
for (const base of bases) {
|
|
23
|
+
try {
|
|
24
|
+
return createRequire(base).resolve(WASM_MODULE);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const fail = (reason) => ({ classifier: null, reason });
|
|
32
|
+
const msg = (err) => (err instanceof Error ? err.message : String(err));
|
|
33
|
+
export async function loadWasmInjectionClassifier(modelDir) {
|
|
34
|
+
const ortPath = resolveOrtWeb();
|
|
35
|
+
if (!ortPath)
|
|
36
|
+
return fail(`${WASM_MODULE} is not installed in ${screenerRuntimeDir()}`);
|
|
37
|
+
const transformersPath = resolveScreenerRuntime();
|
|
38
|
+
if (!transformersPath)
|
|
39
|
+
return fail(`@huggingface/transformers is not installed in ${screenerRuntimeDir()} (the tokenizer comes from it)`);
|
|
40
|
+
let ort;
|
|
41
|
+
let AutoTokenizer;
|
|
42
|
+
let labelIndex;
|
|
43
|
+
let session;
|
|
44
|
+
let tokenizer;
|
|
45
|
+
try {
|
|
46
|
+
ort = (await import(__rewriteRelativeImportExtension(/* @vite-ignore */ pathToFileURL(ortPath).href)));
|
|
47
|
+
const tf = (await import(__rewriteRelativeImportExtension(/* @vite-ignore */ pathToFileURL(transformersPath).href)));
|
|
48
|
+
if (tf.env) {
|
|
49
|
+
tf.env["allowRemoteModels"] = false;
|
|
50
|
+
tf.env["allowLocalModels"] = true;
|
|
51
|
+
}
|
|
52
|
+
AutoTokenizer = tf.AutoTokenizer;
|
|
53
|
+
ort.env.wasm.wasmPaths = pathToFileURL(`${dirname(ortPath)}/`).href;
|
|
54
|
+
ort.env.wasm.numThreads = 1;
|
|
55
|
+
const config = JSON.parse(await readFile(join(modelDir, "config.json"), "utf8"));
|
|
56
|
+
const entry = Object.entries(config.id2label ?? {}).find(([, label]) => label.toLowerCase() === "injection");
|
|
57
|
+
if (!entry)
|
|
58
|
+
return fail(`config.json in ${modelDir} has no 'injection' label in id2label — refusing to guess the index`);
|
|
59
|
+
labelIndex = Number(entry[0]);
|
|
60
|
+
session = await ort.InferenceSession.create(await readFile(join(modelDir, "onnx", "model.onnx")), { executionProviders: ["wasm"] });
|
|
61
|
+
tokenizer = await AutoTokenizer.from_pretrained(modelDir, { local_files_only: true });
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
return fail(`the WASM classifier failed to load from ${modelDir}: ${msg(err)}`);
|
|
65
|
+
}
|
|
66
|
+
async function scoreWindow(text) {
|
|
67
|
+
const enc = tokenizer(text);
|
|
68
|
+
const feeds = {};
|
|
69
|
+
for (const name of session.inputNames) {
|
|
70
|
+
const t = enc[name];
|
|
71
|
+
if (!t)
|
|
72
|
+
throw new Error(`the tokenizer produced no '${name}', which the model requires`);
|
|
73
|
+
feeds[name] = new ort.Tensor("int64", BigInt64Array.from(Array.from(t.data, (v) => BigInt(v))), t.dims);
|
|
74
|
+
}
|
|
75
|
+
const out = await session.run(feeds);
|
|
76
|
+
const logits = Array.from(out[session.outputNames[0]].data, Number);
|
|
77
|
+
const max = Math.max(...logits);
|
|
78
|
+
const exps = logits.map((l) => Math.exp(l - max));
|
|
79
|
+
const p = exps[labelIndex] / exps.reduce((a, b) => a + b, 0);
|
|
80
|
+
if (!Number.isFinite(p))
|
|
81
|
+
throw new Error(`the model returned no usable logit at index ${labelIndex}`);
|
|
82
|
+
return p;
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
classifier: {
|
|
86
|
+
windows: (text) => textWindows(text, tokenizer, SCREENER_MODEL.windowTokens, SCREENER_MODEL.windowOverlapTokens),
|
|
87
|
+
score: scoreWindow,
|
|
88
|
+
async classify(text) {
|
|
89
|
+
const windows = textWindows(text, tokenizer, SCREENER_MODEL.windowTokens, SCREENER_MODEL.windowOverlapTokens);
|
|
90
|
+
const scores = [];
|
|
91
|
+
for (const w of windows)
|
|
92
|
+
scores.push(await scoreWindow(w));
|
|
93
|
+
return { injectionProbability: aggregateWindowScores(scores), label: "injection" };
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function compileInjectionPatterns(): void;
|
|
2
|
+
export declare function injectionPatternIds(): string[] | null;
|
|
3
|
+
export declare function injectionPatternDigestInputs(): Array<{
|
|
4
|
+
id: string;
|
|
5
|
+
src: string;
|
|
6
|
+
}> | null;
|
|
7
|
+
export declare function injectionPatternsReady(): boolean;
|
|
8
|
+
export declare function scanInjectionPatterns(text: string): string[];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { LinearRegex } from "./linear-regex.js";
|
|
2
|
+
let compiled = null;
|
|
3
|
+
const PATTERN_SOURCES = [
|
|
4
|
+
{ id: "role_marker", src: "\\[/?(?:system|inst|sys)\\]|<\\|im_(?:start|end)\\|>|<\\|(?:system|user|assistant)\\|>|<</?sys>>|\\bsystem prompt:" },
|
|
5
|
+
{ id: "override", src: "(?:ignore|disregard|forget|bypass|override|skip|abandon|set aside)\\s+(?:\\w+\\s+){0,3}(?:previous|prior|above|earlier|original|initial|safety|ethical|content|system)\\s+(?:instructions|prompts?|context|messages?|rules?|directions?|guidelines|polic(?:y|ies)|constraints|restrictions|programming|directives|safeguards|filters|limitations)|(?:ignore|disregard)(?:all|your|the|any)*(?:previous|prior|above|earlier)(?:instructions|prompts?|rules?|directions?|guidelines)" },
|
|
6
|
+
{ id: "override_explicit", src: "forget everything (?:above|before|you know)|your new instructions are|new[_ ]paradigm|from now on,?\\s+you (?:are|will|must|shall)\\b|you (?:are|will) no longer (?:bound|restricted|limited)|you are no longer an? (?:ai|assistant|language model)" },
|
|
7
|
+
{ id: "persona", src: "\\byou are now\\b|\\bdeveloper mode\\b|\\bdo anything now\\b|\\bDAN mode\\b|\\bpretend (?:you are|that you are) (?:an? )?(?:ai|assistant|model|chatbot) (?:with(?:out)?|that has no)\\b|\\bstay in character\\b|\\b(?:unfiltered|uncensored|unrestricted|jailbroken) (?:mode|ai|assistant|version|response)|\\bwithout any (?:restrictions|filters|limitations|censorship)\\b|\\bno (?:ethical|moral) (?:guidelines|restrictions|constraints)\\b" },
|
|
8
|
+
{ id: "jailbreak", src: "jailbreak\\s*[:>]|<jailbreak>|\\[liberated\\]|<new_paradigm>|\\[insert prompt here\\]|\\bjailbroken\\b" },
|
|
9
|
+
{ id: "prompt_extraction", src: "(?:reveal|show|print|repeat|output|display|tell me|give me|share|leak|expose|extract|disclose|divulge|surface|dump)\\s+(?:\\w+\\s+){0,3}(?:system prompt|initial prompt|hidden (?:instructions|prompt|system instructions)|(?:your |the )?(?:hidden|internal|underlying|original) system (?:instructions|prompt)|(?:your|the) (?:instructions|prompt|rules) (?:above|verbatim|word for word))|what (?:is|are|were) your (?:system prompt|initial instructions)" },
|
|
10
|
+
{ id: "secret_request", src: "(?:provide|give|share|send|tell|reveal)\\s+(?:me\\s+)?(?:\\w+\\s+){0,2}(?:confidential|sensitive|private|secret|classified|internal) (?:information|data|details|records|files)|(?:share|reveal|give me|send me|tell me) (?:your|the) (?:password|passwords|api keys?|credentials|secret keys?|private keys?|access tokens?)\\s*(?:[.!?,;]|with me|to me|now|$)" },
|
|
11
|
+
{ id: "coercion", src: "\\bor (?:else )?i will (?:expose|leak|report|publish|delete|destroy|shut)|\\bor face (?:severe |serious )?consequences\\b" },
|
|
12
|
+
{ id: "context_dump", src: "(?:print|output|repeat|dump|show|reveal)\\s+(?:me\\s+)?(?:all\\s+|everything\\s+|those\\s+|the\\s+)?(?:that\\s+)?(?:appeared|came|was)?\\s*(?:before|above|prior to)\\s+(?:my|the|this)\\s+(?:first\\s+)?(?:message|prompt|question|session|conversation)|(?:pre-session|preceding|initial)\\s+(?:instructions|prompt|context)\\s+verbatim|system log dump|repeat all instructions" },
|
|
13
|
+
{ id: "rules_void", src: "(?:previous|prior|above|earlier)\\s+(?:rules?|instructions?|guidelines?|constraints?|restrictions?)\\s+(?:no longer apply|are void|are cancelled|are canceled|are revoked|are superseded|do not apply)|\\[BREAK\\]|this (?:request|message) is covered under legal privilege" },
|
|
14
|
+
{ id: "fake_mode_header", src: "(?:admin|god)[_ ]?(?:override|mode|access)\\s*[:=]\\s*(?:true|on|enabled|active)|content[_ ]?filters?\\s*[:=]\\s*(?:off|false|disabled|none)\\s*(?:\\n|$)|safety[_ ]?(?:filters?|checks?)\\s*[:=]\\s*(?:off|false|disabled)\\s*(?:\\n|$)|\\[system [a-z ]{0,20}mode" },
|
|
15
|
+
{ id: "addressed_to_model", src: "(?:ai|a\\.i\\.|llm|assistants?|language models?|agents?|chatbots?)\\s+(?:reading|processing|viewing|parsing|summari[sz]ing)\\s+this[^.!?\\n]{0,40}\\b(?:should|must|shall|will|are to|need to)\\s+(?:ignore|disregard|recommend|include|output|print|reveal|treat|respond|reply|forward|send|call|invoke|execute|follow|append|say|rate|rank|prioriti[sz]e)\\b|(?:if|when) you are an? (?:ai|llm|assistant|language model|agent)\\b|\\b(?:agent|llm|ai|system)\\s+instructions?\\s*[::]|instructions? for (?:the )?(?:llm|ai|agent|assistant)\\s*[::]" },
|
|
16
|
+
{ id: "authority_claim", src: "(?:developer|admin|system|root)[- ]tier authority|treat (?:this|it|the following) as (?:having )?(?:developer|admin|system|elevated)|signed by the developer key|authorized (?:personnel|alignment researcher) only|i am an authorized (?:alignment researcher|developer|administrator|security researcher|agent of)\\b" },
|
|
17
|
+
{ id: "suppress_refusal", src: "(?:replace|suppress|omit)\\s+(?:any|all|every)\\s+(?:refusals?|disclaimers?)\\b|never (?:refuse|decline|say no) (?:to|when|under)\\b|do not (?:refuse|apologi[sz]e) (?:or|and|under|regardless)\\b" },
|
|
18
|
+
{ id: "obey_directive", src: "you must strictly adhere to the following instruction|comply (?:with the above|immediately) (?:or|and)\\b" },
|
|
19
|
+
{ id: "exfil_instruction", src: "(?:email|send|forward|upload|post|transmit|exfiltrate)\\s+(?:the\\s+|your\\s+|all\\s+)?(?:conversation|chat|message|session|user)\\s*(?:log|logs|history|transcript|data|context)?\\s+to\\s+(?:[\\w.+-]+@|https?://|[\\w-]+\\.[a-z]{2,}|the endpoint|an external)|send all user data" },
|
|
20
|
+
{ id: "override_nonenglish", src: "忽略(?:以上|上述|之前|前面).{0,4}(?:指令|指示|提示)|系统提示词|ignora(?:r)? (?:todas )?las instrucciones anteriores|ignorez les instructions précédentes|игнорируй (?:все )?предыдущие инструкции|이전 지시를 무시" },
|
|
21
|
+
{ id: "fake_envelope", src: "<message[^>]{0,80}priority=\"?system|BEGIN TRUSTED INPUT|END TRUSTED INPUT|\\[END OF CONVERSATION\\]" },
|
|
22
|
+
{ id: "completion_bait", src: "(?:complete|continue|finish)\\s+(?:this|the following)\\s+sentence[^\\n]{0,40}(?:system prompt|your instructions|developer message)|(?:my|your) (?:system prompt|developer message|instructions) (?:starts?|begins?) with" },
|
|
23
|
+
{ id: "developer_message", src: "(?:developer|system) message\\s+verbatim|raw (?:developer|system) message|output (?:the |your )?(?:raw )?(?:developer|system) (?:message|prompt)" },
|
|
24
|
+
{ id: "boundary", src: "-{3,}\\s*end of (?:user|system) (?:message|prompt)|={3,}\\s*end system prompt" },
|
|
25
|
+
{ id: "leetspeak", src: "1gn0r3\\s+pr3v10u5|\\bsy5t3m\\s*:" },
|
|
26
|
+
];
|
|
27
|
+
export function compileInjectionPatterns() {
|
|
28
|
+
compiled = PATTERN_SOURCES.map(({ id, src }) => ({ id, src, re: new LinearRegex(src, "i") }));
|
|
29
|
+
}
|
|
30
|
+
export function injectionPatternIds() {
|
|
31
|
+
return compiled === null ? null : compiled.map((c) => c.id);
|
|
32
|
+
}
|
|
33
|
+
export function injectionPatternDigestInputs() {
|
|
34
|
+
return compiled === null ? null : compiled.map((c) => ({ id: c.id, src: c.src }));
|
|
35
|
+
}
|
|
36
|
+
export function injectionPatternsReady() {
|
|
37
|
+
return compiled !== null;
|
|
38
|
+
}
|
|
39
|
+
export function scanInjectionPatterns(text) {
|
|
40
|
+
if (!compiled)
|
|
41
|
+
return [];
|
|
42
|
+
const hits = [];
|
|
43
|
+
for (const { id, re } of compiled) {
|
|
44
|
+
if (re.test(text))
|
|
45
|
+
hits.push(id);
|
|
46
|
+
}
|
|
47
|
+
return hits;
|
|
48
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function buildWindows(tokens: readonly number[], size: number, overlap: number): number[][];
|
|
2
|
+
export declare function aggregateWindowScores(scores: readonly number[]): number;
|
|
3
|
+
export interface WindowTokenizer {
|
|
4
|
+
encode(text: string): number[];
|
|
5
|
+
decode(ids: number[], opts?: {
|
|
6
|
+
skip_special_tokens?: boolean;
|
|
7
|
+
}): string;
|
|
8
|
+
}
|
|
9
|
+
export declare function textWindows(text: string, tok: WindowTokenizer | undefined, size: number, overlap: number): string[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function buildWindows(tokens, size, overlap) {
|
|
2
|
+
if (size <= 0)
|
|
3
|
+
throw new Error(`window size must be positive (got ${size})`);
|
|
4
|
+
if (overlap >= size) {
|
|
5
|
+
throw new Error(`window overlap ${overlap} must be smaller than the window size ${size}`);
|
|
6
|
+
}
|
|
7
|
+
if (tokens.length <= size)
|
|
8
|
+
return [[...tokens]];
|
|
9
|
+
const stride = size - overlap;
|
|
10
|
+
const windows = [];
|
|
11
|
+
for (let start = 0; start < tokens.length; start += stride) {
|
|
12
|
+
windows.push(tokens.slice(start, start + size));
|
|
13
|
+
if (start + size >= tokens.length)
|
|
14
|
+
break; // the tail is covered; another window would repeat it
|
|
15
|
+
}
|
|
16
|
+
return windows;
|
|
17
|
+
}
|
|
18
|
+
export function aggregateWindowScores(scores) {
|
|
19
|
+
if (scores.length === 0) {
|
|
20
|
+
throw new Error("cannot score a message with no windows — refusing to report an unscanned message as clean");
|
|
21
|
+
}
|
|
22
|
+
return Math.max(...scores);
|
|
23
|
+
}
|
|
24
|
+
export function textWindows(text, tok, size, overlap) {
|
|
25
|
+
if (!tok || typeof tok.encode !== "function" || typeof tok.decode !== "function")
|
|
26
|
+
return [text];
|
|
27
|
+
let ids;
|
|
28
|
+
try {
|
|
29
|
+
ids = tok.encode(text);
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return [text];
|
|
33
|
+
}
|
|
34
|
+
if (ids.length <= size)
|
|
35
|
+
return [text];
|
|
36
|
+
return buildWindows(ids, size, overlap).map((w) => tok.decode(w, { skip_special_tokens: true }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Script = "latin" | "cyrillic" | "greek" | "arabic" | "hebrew" | "han" | "kana" | "hangul" | "devanagari" | "thai" | "other";
|
|
2
|
+
export declare const SCRIPTS: readonly Script[];
|
|
3
|
+
export declare const isScript: (v: unknown) => v is Script;
|
|
4
|
+
export interface LanguageVerdict {
|
|
5
|
+
allowed: boolean;
|
|
6
|
+
script?: Script;
|
|
7
|
+
reason?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface LanguageOptions {
|
|
10
|
+
allow?: Script[];
|
|
11
|
+
minLetters?: number;
|
|
12
|
+
minShare?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare function scriptOf(cp: number): Script | null;
|
|
15
|
+
export declare function screenInboundLanguage(text: string, opts?: LanguageOptions): LanguageVerdict;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export const SCRIPTS = [
|
|
2
|
+
"latin", "cyrillic", "greek", "arabic", "hebrew", "han", "kana", "hangul",
|
|
3
|
+
"devanagari", "thai", "other",
|
|
4
|
+
];
|
|
5
|
+
export const isScript = (v) => SCRIPTS.includes(v);
|
|
6
|
+
export function scriptOf(cp) {
|
|
7
|
+
if ((cp >= 0x300 && cp <= 0x36f) || (cp >= 0x1ab0 && cp <= 0x1aff) || (cp >= 0x1dc0 && cp <= 0x1dff) ||
|
|
8
|
+
(cp >= 0x20d0 && cp <= 0x20ff) || (cp >= 0xfe20 && cp <= 0xfe2f))
|
|
9
|
+
return null;
|
|
10
|
+
if ((cp >= 0x41 && cp <= 0x5a) || (cp >= 0x61 && cp <= 0x7a) ||
|
|
11
|
+
(cp >= 0xc0 && cp <= 0x2af) || (cp >= 0x1d00 && cp <= 0x1dbf) || (cp >= 0x1e00 && cp <= 0x1eff) ||
|
|
12
|
+
(cp >= 0x2c60 && cp <= 0x2c7f) || (cp >= 0xa720 && cp <= 0xa7ff))
|
|
13
|
+
return "latin";
|
|
14
|
+
if (cp >= 0x400 && cp <= 0x4ff)
|
|
15
|
+
return "cyrillic";
|
|
16
|
+
if ((cp >= 0x370 && cp <= 0x3ff) || (cp >= 0x1f00 && cp <= 0x1fff))
|
|
17
|
+
return "greek";
|
|
18
|
+
if ((cp >= 0x600 && cp <= 0x6ff) || (cp >= 0x750 && cp <= 0x77f))
|
|
19
|
+
return "arabic";
|
|
20
|
+
if (cp >= 0x590 && cp <= 0x5ff)
|
|
21
|
+
return "hebrew";
|
|
22
|
+
if ((cp >= 0x4e00 && cp <= 0x9fff) || (cp >= 0x3400 && cp <= 0x4dbf))
|
|
23
|
+
return "han";
|
|
24
|
+
if (cp >= 0x3040 && cp <= 0x30ff)
|
|
25
|
+
return "kana";
|
|
26
|
+
if ((cp >= 0xac00 && cp <= 0xd7af) || (cp >= 0x1100 && cp <= 0x11ff))
|
|
27
|
+
return "hangul";
|
|
28
|
+
if (cp >= 0x900 && cp <= 0x97f)
|
|
29
|
+
return "devanagari";
|
|
30
|
+
if (cp >= 0xe00 && cp <= 0xe7f)
|
|
31
|
+
return "thai";
|
|
32
|
+
if (cp > 0x2bf && !(cp >= 0x2000 && cp <= 0x2bff))
|
|
33
|
+
return "other";
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const SCRIPT_LABEL = {
|
|
37
|
+
latin: "Latin", cyrillic: "Cyrillic", greek: "Greek", arabic: "Arabic", hebrew: "Hebrew",
|
|
38
|
+
han: "Han/CJK", kana: "Japanese kana", hangul: "Korean Hangul", devanagari: "Devanagari",
|
|
39
|
+
thai: "Thai", other: "a non-Latin",
|
|
40
|
+
};
|
|
41
|
+
export function screenInboundLanguage(text, opts = {}) {
|
|
42
|
+
const allow = new Set(opts.allow ?? ["latin"]);
|
|
43
|
+
const minLetters = opts.minLetters ?? 12;
|
|
44
|
+
const minShare = opts.minShare ?? 0.5;
|
|
45
|
+
const counts = new Map();
|
|
46
|
+
let total = 0;
|
|
47
|
+
for (const ch of text) {
|
|
48
|
+
const s = scriptOf(ch.codePointAt(0));
|
|
49
|
+
if (!s)
|
|
50
|
+
continue;
|
|
51
|
+
counts.set(s, (counts.get(s) ?? 0) + 1);
|
|
52
|
+
total++;
|
|
53
|
+
}
|
|
54
|
+
if (total < minLetters)
|
|
55
|
+
return { allowed: true };
|
|
56
|
+
let dominant = "latin";
|
|
57
|
+
let max = 0;
|
|
58
|
+
for (const [s, n] of counts)
|
|
59
|
+
if (n > max) {
|
|
60
|
+
max = n;
|
|
61
|
+
dominant = s;
|
|
62
|
+
}
|
|
63
|
+
if (allow.has(dominant) || max / total < minShare)
|
|
64
|
+
return { allowed: true };
|
|
65
|
+
return {
|
|
66
|
+
allowed: false,
|
|
67
|
+
script: dominant,
|
|
68
|
+
reason: `This message is predominantly ${SCRIPT_LABEL[dominant]} script, outside the gateway's ` +
|
|
69
|
+
`language allowlist.`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
let factory = null;
|
|
2
|
+
// WASM only: the native engine compiles from source, which costs every operator install time for no gain in the guarantee.
|
|
3
|
+
export async function initLinearRegex() {
|
|
4
|
+
if (factory)
|
|
5
|
+
return;
|
|
6
|
+
const wasm = (await import("re2-wasm"));
|
|
7
|
+
factory = (pattern, flags) => new wasm.RE2(pattern, flags.includes("u") ? flags : flags + "u");
|
|
8
|
+
}
|
|
9
|
+
export class LinearRegex {
|
|
10
|
+
#re;
|
|
11
|
+
constructor(pattern, flags = "") {
|
|
12
|
+
if (!factory) {
|
|
13
|
+
throw new Error("LinearRegex: call and await initLinearRegex() before constructing patterns");
|
|
14
|
+
}
|
|
15
|
+
this.#re = factory(pattern, flags);
|
|
16
|
+
}
|
|
17
|
+
test(s) {
|
|
18
|
+
return this.#re.test(s);
|
|
19
|
+
}
|
|
20
|
+
match(s) {
|
|
21
|
+
const m = this.#re.exec(s);
|
|
22
|
+
return m ? m[0] : null;
|
|
23
|
+
}
|
|
24
|
+
exec(s) {
|
|
25
|
+
return this.#re.exec(s);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare function sha256File(path: string): Promise<string>;
|
|
2
|
+
export declare function isModelInstalled(dir: string): Promise<boolean>;
|
|
3
|
+
export interface InstallResult {
|
|
4
|
+
installed: boolean;
|
|
5
|
+
needsConsent?: boolean;
|
|
6
|
+
error?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface InstallOptions {
|
|
9
|
+
dir: string;
|
|
10
|
+
consent: boolean;
|
|
11
|
+
fetchImpl?: typeof fetch;
|
|
12
|
+
onProgress?: (file: string, index: number, total: number) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function installModel(opts: InstallOptions): Promise<InstallResult>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { createReadStream, createWriteStream } from "node:fs";
|
|
3
|
+
import { mkdir, stat, rm } from "node:fs/promises";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { Readable } from "node:stream";
|
|
6
|
+
import { pipeline } from "node:stream/promises";
|
|
7
|
+
import { SCREENER_MODEL, localPathOf } from "./screener-model-manifest.js";
|
|
8
|
+
export function sha256File(path) {
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
const hash = createHash("sha256");
|
|
11
|
+
const rs = createReadStream(path);
|
|
12
|
+
rs.on("error", reject);
|
|
13
|
+
rs.on("data", (chunk) => hash.update(chunk));
|
|
14
|
+
rs.on("end", () => resolve(hash.digest("hex")));
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export async function isModelInstalled(dir) {
|
|
18
|
+
for (const f of SCREENER_MODEL.files) {
|
|
19
|
+
try {
|
|
20
|
+
await stat(join(dir, localPathOf(f)));
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
export async function installModel(opts) {
|
|
29
|
+
if (await isModelInstalled(opts.dir))
|
|
30
|
+
return { installed: true };
|
|
31
|
+
if (!opts.consent)
|
|
32
|
+
return { installed: false, needsConsent: true };
|
|
33
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
34
|
+
const total = SCREENER_MODEL.files.length;
|
|
35
|
+
for (const [i, f] of SCREENER_MODEL.files.entries()) {
|
|
36
|
+
opts.onProgress?.(f.path, i, total);
|
|
37
|
+
const dest = join(opts.dir, localPathOf(f));
|
|
38
|
+
await mkdir(dirname(dest), { recursive: true });
|
|
39
|
+
let res;
|
|
40
|
+
try {
|
|
41
|
+
res = await doFetch(SCREENER_MODEL.baseUrl + f.path);
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
return { installed: false, error: `download failed for ${f.path}: ${err instanceof Error ? err.message : String(err)}` };
|
|
45
|
+
}
|
|
46
|
+
if (!res.ok || !res.body)
|
|
47
|
+
return { installed: false, error: `download failed for ${f.path}: HTTP ${res.status}` };
|
|
48
|
+
await pipeline(Readable.fromWeb(res.body), createWriteStream(dest));
|
|
49
|
+
const downloaded = await stat(dest);
|
|
50
|
+
if (downloaded.size !== f.size) {
|
|
51
|
+
await rm(dest, { force: true });
|
|
52
|
+
return { installed: false, error: `size mismatch for ${f.path}: expected ${f.size}, got ${downloaded.size} — removed` };
|
|
53
|
+
}
|
|
54
|
+
const got = await sha256File(dest);
|
|
55
|
+
if (got !== f.sha256) {
|
|
56
|
+
await rm(dest, { force: true });
|
|
57
|
+
return { installed: false, error: `checksum mismatch for ${f.path} — the file was NOT trusted and has been removed` };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { installed: true };
|
|
61
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface OutboundVerdict {
|
|
2
|
+
disposition: "allow" | "redact" | "block" | "hold";
|
|
3
|
+
text: string;
|
|
4
|
+
categories: string[];
|
|
5
|
+
reason: string | null;
|
|
6
|
+
held?: {
|
|
7
|
+
category: string;
|
|
8
|
+
value: string;
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
export declare function protectKnownKeys(text: string, keys: readonly string[]): {
|
|
12
|
+
text: string;
|
|
13
|
+
restore: (t: string) => string;
|
|
14
|
+
};
|
|
15
|
+
export declare function screenOutbound(input: string, knownKeys: readonly string[], pii?: {
|
|
16
|
+
whitelist: string[];
|
|
17
|
+
email: boolean;
|
|
18
|
+
phone: boolean;
|
|
19
|
+
}): OutboundVerdict;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// The screen on the way out: credentials are redacted, hijack artifacts stop the message, and invisible characters and
|
|
2
|
+
// data-carrying image links are removed. It never runs the model. Rewritten from cello-client's screen/outbound.ts.
|
|
3
|
+
import { OutboundPIIScreener } from "../daemon/pii.js";
|
|
4
|
+
import { screenOutboundExfil } from "./exfil.js";
|
|
5
|
+
import { redactSecrets } from "./secrets.js";
|
|
6
|
+
const PLACEHOLDER_PREFIX = "CELLOPUBKEY";
|
|
7
|
+
function indexToLetters(i) {
|
|
8
|
+
let n = i;
|
|
9
|
+
let out = "";
|
|
10
|
+
do {
|
|
11
|
+
out = String.fromCharCode(65 + (n % 26)) + out;
|
|
12
|
+
n = Math.floor(n / 26) - 1;
|
|
13
|
+
} while (n >= 0);
|
|
14
|
+
return out;
|
|
15
|
+
}
|
|
16
|
+
// A public key this agent already knows isn't a secret, so it's held out of the detectors and put back afterwards.
|
|
17
|
+
export function protectKnownKeys(text, keys) {
|
|
18
|
+
const identity = { text, restore: (t) => t };
|
|
19
|
+
const canon = [...new Set(keys.map((k) => k.toLowerCase()))].filter((k) => k.length > 0);
|
|
20
|
+
if (canon.length === 0)
|
|
21
|
+
return identity;
|
|
22
|
+
const pattern = new RegExp(`(?<![0-9a-fA-F])(?:${canon.join("|")})(?![0-9a-fA-F])`, "gi");
|
|
23
|
+
const restoreMap = new Map();
|
|
24
|
+
let i = 0;
|
|
25
|
+
const protectedText = text.replace(pattern, (match) => {
|
|
26
|
+
const placeholder = PLACEHOLDER_PREFIX + indexToLetters(i);
|
|
27
|
+
i += 1;
|
|
28
|
+
restoreMap.set(placeholder, match);
|
|
29
|
+
return placeholder;
|
|
30
|
+
});
|
|
31
|
+
if (restoreMap.size === 0)
|
|
32
|
+
return identity;
|
|
33
|
+
for (const placeholder of restoreMap.keys()) {
|
|
34
|
+
if (text.includes(placeholder))
|
|
35
|
+
return identity;
|
|
36
|
+
}
|
|
37
|
+
const ordered = [...restoreMap.keys()].sort((a, b) => b.length - a.length);
|
|
38
|
+
const restore = (t) => {
|
|
39
|
+
let out = t;
|
|
40
|
+
for (const placeholder of ordered)
|
|
41
|
+
out = out.split(placeholder).join(restoreMap.get(placeholder));
|
|
42
|
+
return out;
|
|
43
|
+
};
|
|
44
|
+
return { text: protectedText, restore };
|
|
45
|
+
}
|
|
46
|
+
export function screenOutbound(input, knownKeys, pii = { whitelist: [], email: false, phone: false }) {
|
|
47
|
+
const protection = protectKnownKeys(input, knownKeys);
|
|
48
|
+
const secrets = redactSecrets(protection.text);
|
|
49
|
+
const categories = secrets.findings.map((f) => `secret:${f.ruleId}`);
|
|
50
|
+
const exfil = screenOutboundExfil(new TextEncoder().encode(secrets.text));
|
|
51
|
+
if (exfil.disposition === "block") {
|
|
52
|
+
return { disposition: "block", text: input, categories: exfil.events.map((e) => e.category), reason: exfil.events[0]?.reason ?? "the outbound screen blocked this message" };
|
|
53
|
+
}
|
|
54
|
+
categories.push(...exfil.events.map((e) => e.category));
|
|
55
|
+
const personal = new OutboundPIIScreener({ whitelist: pii.whitelist, checkEmail: pii.email, checkPhone: pii.phone }).screen(new TextEncoder().encode(exfil.text), "");
|
|
56
|
+
if (personal.disposition === "warn") {
|
|
57
|
+
return { disposition: "hold", text: protection.restore(exfil.text), categories, reason: null, held: personal.events.map((e) => ({ category: e.category, value: e.value })) };
|
|
58
|
+
}
|
|
59
|
+
if (categories.length === 0)
|
|
60
|
+
return { disposition: "allow", text: input, categories, reason: null };
|
|
61
|
+
return { disposition: "redact", text: protection.restore(exfil.text), categories, reason: null };
|
|
62
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export declare const DEFAULT_MAX_BYTES = 1000000;
|
|
2
|
+
export interface SanitizationNote {
|
|
3
|
+
step: "invisible_strip" | "confusables" | "decode" | "entropy" | "special_tokens" | "forged_marker";
|
|
4
|
+
detail: string;
|
|
5
|
+
count?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SanitizeResult {
|
|
8
|
+
text: string;
|
|
9
|
+
scriptScanText: string;
|
|
10
|
+
decodedForScan: string;
|
|
11
|
+
hiddenText: string;
|
|
12
|
+
notes: SanitizationNote[];
|
|
13
|
+
entropySuspicion: number;
|
|
14
|
+
blocked?: {
|
|
15
|
+
reason: string;
|
|
16
|
+
guidance: string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface SanitizeOptions {
|
|
20
|
+
maxBytes?: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function stripIllegitimate(text: string): {
|
|
23
|
+
text: string;
|
|
24
|
+
removed: number;
|
|
25
|
+
};
|
|
26
|
+
export declare function stripInvisible(text: string): {
|
|
27
|
+
text: string;
|
|
28
|
+
removed: number;
|
|
29
|
+
};
|
|
30
|
+
export declare function decodeEncoded(text: string): {
|
|
31
|
+
text: string;
|
|
32
|
+
changed: boolean;
|
|
33
|
+
count: number;
|
|
34
|
+
};
|
|
35
|
+
export declare function highEntropyTokens(text: string): string[];
|
|
36
|
+
export declare const PRIVILEGED_TURN_MARKERS: readonly ["[SYSTEM]", "[/SYSTEM]", "<<SYS>>", "<</SYS>>", "[INST]", "[/INST]", "SYSTEM PROMPT:", "<system>", "</system>", "[cello security layer, local]"];
|
|
37
|
+
export declare const PIPE_TURN_MARKER_SOURCE = "<\\|[a-z0-9_]+\\|>";
|
|
38
|
+
export declare function pipeTurnMarkerRegex(): RegExp;
|
|
39
|
+
export declare function stripForgedMarkers(text: string): {
|
|
40
|
+
text: string;
|
|
41
|
+
removed: number;
|
|
42
|
+
};
|
|
43
|
+
export declare function readHiddenChannels(text: string): string;
|
|
44
|
+
export declare function sanitizeInbound(content: Uint8Array, opts?: SanitizeOptions): SanitizeResult;
|