@weave_protocol/domere 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/PLANNING.md +231 -0
- package/README.md +50 -0
- package/dist/anchoring/ethereum.d.ts +135 -0
- package/dist/anchoring/ethereum.d.ts.map +1 -0
- package/dist/anchoring/ethereum.js +474 -0
- package/dist/anchoring/ethereum.js.map +1 -0
- package/dist/anchoring/index.d.ts +93 -0
- package/dist/anchoring/index.d.ts.map +1 -0
- package/dist/anchoring/index.js +184 -0
- package/dist/anchoring/index.js.map +1 -0
- package/dist/anchoring/merkle.d.ts +91 -0
- package/dist/anchoring/merkle.d.ts.map +1 -0
- package/dist/anchoring/merkle.js +203 -0
- package/dist/anchoring/merkle.js.map +1 -0
- package/dist/anchoring/solana.d.ts +85 -0
- package/dist/anchoring/solana.d.ts.map +1 -0
- package/dist/anchoring/solana.js +301 -0
- package/dist/anchoring/solana.js.map +1 -0
- package/dist/constants.d.ts +130 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +536 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/language/code-analyzer.d.ts +80 -0
- package/dist/language/code-analyzer.d.ts.map +1 -0
- package/dist/language/code-analyzer.js +489 -0
- package/dist/language/code-analyzer.js.map +1 -0
- package/dist/language/detector.d.ts +53 -0
- package/dist/language/detector.d.ts.map +1 -0
- package/dist/language/detector.js +248 -0
- package/dist/language/detector.js.map +1 -0
- package/dist/language/index.d.ts +61 -0
- package/dist/language/index.d.ts.map +1 -0
- package/dist/language/index.js +109 -0
- package/dist/language/index.js.map +1 -0
- package/dist/language/nl-analyzer.d.ts +59 -0
- package/dist/language/nl-analyzer.d.ts.map +1 -0
- package/dist/language/nl-analyzer.js +350 -0
- package/dist/language/nl-analyzer.js.map +1 -0
- package/dist/language/semantic.d.ts +48 -0
- package/dist/language/semantic.d.ts.map +1 -0
- package/dist/language/semantic.js +329 -0
- package/dist/language/semantic.js.map +1 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +6 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/memory.d.ts +48 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +211 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/thread/drift.d.ts +43 -0
- package/dist/thread/drift.d.ts.map +1 -0
- package/dist/thread/drift.js +248 -0
- package/dist/thread/drift.js.map +1 -0
- package/dist/thread/index.d.ts +9 -0
- package/dist/thread/index.d.ts.map +1 -0
- package/dist/thread/index.js +9 -0
- package/dist/thread/index.js.map +1 -0
- package/dist/thread/intent.d.ts +68 -0
- package/dist/thread/intent.d.ts.map +1 -0
- package/dist/thread/intent.js +333 -0
- package/dist/thread/intent.js.map +1 -0
- package/dist/thread/manager.d.ts +85 -0
- package/dist/thread/manager.d.ts.map +1 -0
- package/dist/thread/manager.js +305 -0
- package/dist/thread/manager.js.map +1 -0
- package/dist/thread/weave.d.ts +61 -0
- package/dist/thread/weave.d.ts.map +1 -0
- package/dist/thread/weave.js +158 -0
- package/dist/thread/weave.js.map +1 -0
- package/dist/tools/index.d.ts +18 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +102 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types.d.ts +466 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +48 -0
- package/dist/types.js.map +1 -0
- package/package.json +24 -0
- package/src/anchoring/ethereum.ts +568 -0
- package/src/anchoring/index.ts +236 -0
- package/src/anchoring/merkle.ts +256 -0
- package/src/anchoring/solana.ts +370 -0
- package/src/constants.ts +566 -0
- package/src/index.ts +43 -0
- package/src/language/code-analyzer.ts +564 -0
- package/src/language/detector.ts +297 -0
- package/src/language/index.ts +129 -0
- package/src/language/nl-analyzer.ts +411 -0
- package/src/language/semantic.ts +385 -0
- package/src/storage/index.ts +6 -0
- package/src/storage/memory.ts +271 -0
- package/src/thread/drift.ts +319 -0
- package/src/thread/index.ts +9 -0
- package/src/thread/intent.ts +409 -0
- package/src/thread/manager.ts +414 -0
- package/src/thread/weave.ts +205 -0
- package/src/tools/index.ts +107 -0
- package/src/types.ts +736 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dōmere - The Judge Protocol
|
|
3
|
+
* Natural Language Analysis (Prompt Injection Detection)
|
|
4
|
+
*/
|
|
5
|
+
import { INJECTION_PATTERNS } from '../constants.js';
|
|
6
|
+
// ============================================================================
|
|
7
|
+
// NL Analyzer
|
|
8
|
+
// ============================================================================
|
|
9
|
+
export class NLAnalyzer {
|
|
10
|
+
/**
|
|
11
|
+
* Analyze natural language for manipulation attempts
|
|
12
|
+
*/
|
|
13
|
+
analyze(content) {
|
|
14
|
+
const manipulationIndicators = this.detectManipulation(content);
|
|
15
|
+
const manipulationScore = this.calculateManipulationScore(manipulationIndicators);
|
|
16
|
+
const authorityClaims = this.detectAuthorityClaims(content);
|
|
17
|
+
const instructionOverrides = this.detectInstructionOverrides(content);
|
|
18
|
+
const hiddenInstructions = this.detectHiddenInstructions(content);
|
|
19
|
+
const { jailbreakScore, jailbreakPatterns } = this.detectJailbreak(content);
|
|
20
|
+
const riskLevel = this.calculateRiskLevel(manipulationScore, jailbreakScore, hiddenInstructions.length, instructionOverrides.length);
|
|
21
|
+
return {
|
|
22
|
+
manipulation_score: manipulationScore,
|
|
23
|
+
manipulation_indicators: manipulationIndicators,
|
|
24
|
+
authority_claims: authorityClaims,
|
|
25
|
+
instruction_overrides: instructionOverrides,
|
|
26
|
+
hidden_instructions: hiddenInstructions,
|
|
27
|
+
jailbreak_score: jailbreakScore,
|
|
28
|
+
jailbreak_patterns: jailbreakPatterns,
|
|
29
|
+
risk_level: riskLevel,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Detect manipulation attempts
|
|
34
|
+
*/
|
|
35
|
+
detectManipulation(content) {
|
|
36
|
+
const indicators = [];
|
|
37
|
+
for (const { pattern, type, severity } of INJECTION_PATTERNS) {
|
|
38
|
+
const matches = content.match(pattern);
|
|
39
|
+
if (matches) {
|
|
40
|
+
for (const match of matches) {
|
|
41
|
+
indicators.push({
|
|
42
|
+
type,
|
|
43
|
+
description: this.getPatternDescription(type),
|
|
44
|
+
evidence: match.slice(0, 100),
|
|
45
|
+
severity,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Detect social engineering patterns
|
|
51
|
+
const socialPatterns = [
|
|
52
|
+
{ pattern: /\b(trust me|believe me|I promise)\b/gi, type: 'social_engineering', severity: 'medium' },
|
|
53
|
+
{ pattern: /\b(don't tell anyone|keep this secret|between us)\b/gi, type: 'secrecy_request', severity: 'high' },
|
|
54
|
+
{ pattern: /\b(emergency|urgent|immediately|right now)\s+(need|require|must)/gi, type: 'urgency_manipulation', severity: 'medium' },
|
|
55
|
+
{ pattern: /\b(I('m| am) (your|the) (creator|developer|admin|owner))\b/gi, type: 'authority_claim', severity: 'high' },
|
|
56
|
+
{ pattern: /\b(this is a test|testing|debug mode)\b/gi, type: 'test_claim', severity: 'medium' },
|
|
57
|
+
];
|
|
58
|
+
for (const { pattern, type, severity } of socialPatterns) {
|
|
59
|
+
const matches = content.match(pattern);
|
|
60
|
+
if (matches) {
|
|
61
|
+
for (const match of matches) {
|
|
62
|
+
indicators.push({
|
|
63
|
+
type,
|
|
64
|
+
description: `Detected ${type.replace(/_/g, ' ')} pattern`,
|
|
65
|
+
evidence: match,
|
|
66
|
+
severity,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return indicators;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Calculate manipulation score
|
|
75
|
+
*/
|
|
76
|
+
calculateManipulationScore(indicators) {
|
|
77
|
+
if (indicators.length === 0)
|
|
78
|
+
return 0;
|
|
79
|
+
let score = 0;
|
|
80
|
+
const weights = { low: 0.1, medium: 0.25, high: 0.4, critical: 0.5 };
|
|
81
|
+
for (const indicator of indicators) {
|
|
82
|
+
score += weights[indicator.severity] || 0.1;
|
|
83
|
+
}
|
|
84
|
+
return Math.min(1, score);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Detect authority claims
|
|
88
|
+
*/
|
|
89
|
+
detectAuthorityClaims(content) {
|
|
90
|
+
const claims = [];
|
|
91
|
+
const patterns = [
|
|
92
|
+
/I\s+am\s+(?:the|your|an?)\s+(?:admin|administrator|developer|creator|owner|manager)/gi,
|
|
93
|
+
/as\s+(?:the|your|an?)\s+(?:admin|administrator|developer|creator|owner)/gi,
|
|
94
|
+
/I\s+(?:created|developed|built|made)\s+(?:you|this)/gi,
|
|
95
|
+
/I\s+have\s+(?:admin|root|full|special)\s+(?:access|permission|privileges)/gi,
|
|
96
|
+
/I\s+work\s+(?:for|at)\s+(?:Anthropic|OpenAI|Google|the company)/gi,
|
|
97
|
+
/this\s+is\s+(?:official|authorized|sanctioned)/gi,
|
|
98
|
+
/by\s+order\s+of/gi,
|
|
99
|
+
/I\s+(?:am|have been)\s+authorized\s+to/gi,
|
|
100
|
+
];
|
|
101
|
+
for (const pattern of patterns) {
|
|
102
|
+
const matches = content.match(pattern);
|
|
103
|
+
if (matches) {
|
|
104
|
+
claims.push(...matches.map(m => m.trim()));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return [...new Set(claims)];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Detect instruction override attempts
|
|
111
|
+
*/
|
|
112
|
+
detectInstructionOverrides(content) {
|
|
113
|
+
const overrides = [];
|
|
114
|
+
const patterns = [
|
|
115
|
+
/ignore\s+(?:all\s+)?(?:previous|prior|above|earlier)\s+(?:instructions?|prompts?|rules?|constraints?)/gi,
|
|
116
|
+
/disregard\s+(?:all\s+)?(?:previous|prior|above|earlier)/gi,
|
|
117
|
+
/forget\s+(?:everything|all|what)\s+(?:you|I)\s+(?:said|told|wrote)/gi,
|
|
118
|
+
/new\s+(?:instructions?|rules?|prompt)\s*:/gi,
|
|
119
|
+
/override\s+(?:previous|system|all)\s+(?:instructions?|prompts?|settings?)/gi,
|
|
120
|
+
/(?:from\s+now\s+on|starting\s+now|henceforth)\s+(?:you\s+)?(?:will|should|must)/gi,
|
|
121
|
+
/reset\s+(?:your|all)\s+(?:instructions?|rules?|settings?|context)/gi,
|
|
122
|
+
/(?:clear|wipe|erase)\s+(?:your|all)\s+(?:memory|context|history)/gi,
|
|
123
|
+
/enter\s+(?:a\s+)?(?:new|different|special)\s+mode/gi,
|
|
124
|
+
/switch\s+to\s+(?:a\s+)?(?:new|different|unrestricted)\s+mode/gi,
|
|
125
|
+
];
|
|
126
|
+
for (const pattern of patterns) {
|
|
127
|
+
const matches = content.match(pattern);
|
|
128
|
+
if (matches) {
|
|
129
|
+
overrides.push(...matches.map(m => m.trim()));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return [...new Set(overrides)];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Detect hidden instructions (encoded, obfuscated)
|
|
136
|
+
*/
|
|
137
|
+
detectHiddenInstructions(content) {
|
|
138
|
+
const hidden = [];
|
|
139
|
+
// Base64 encoded content
|
|
140
|
+
const base64Pattern = /(?:base64:?\s*)?([A-Za-z0-9+/]{20,}={0,2})/g;
|
|
141
|
+
let match;
|
|
142
|
+
while ((match = base64Pattern.exec(content)) !== null) {
|
|
143
|
+
try {
|
|
144
|
+
const decoded = Buffer.from(match[1], 'base64').toString('utf-8');
|
|
145
|
+
// Check if decoded content looks like instructions
|
|
146
|
+
if (this.looksLikeInstruction(decoded)) {
|
|
147
|
+
hidden.push({
|
|
148
|
+
instruction: decoded.slice(0, 200),
|
|
149
|
+
encoding: 'base64',
|
|
150
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
151
|
+
confidence: 0.8,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// Not valid base64
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Unicode escape sequences
|
|
160
|
+
const unicodePattern = /(?:\\u[0-9a-fA-F]{4}){4,}/g;
|
|
161
|
+
while ((match = unicodePattern.exec(content)) !== null) {
|
|
162
|
+
try {
|
|
163
|
+
const decoded = match[0].replace(/\\u([0-9a-fA-F]{4})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16)));
|
|
164
|
+
if (this.looksLikeInstruction(decoded)) {
|
|
165
|
+
hidden.push({
|
|
166
|
+
instruction: decoded,
|
|
167
|
+
encoding: 'unicode',
|
|
168
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
169
|
+
confidence: 0.7,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// Invalid unicode
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
// Hex encoded
|
|
178
|
+
const hexPattern = /(?:0x)?(?:[0-9a-fA-F]{2}\s*){10,}/g;
|
|
179
|
+
while ((match = hexPattern.exec(content)) !== null) {
|
|
180
|
+
try {
|
|
181
|
+
const hexString = match[0].replace(/0x|\s/g, '');
|
|
182
|
+
const decoded = Buffer.from(hexString, 'hex').toString('utf-8');
|
|
183
|
+
if (this.looksLikeInstruction(decoded)) {
|
|
184
|
+
hidden.push({
|
|
185
|
+
instruction: decoded.slice(0, 200),
|
|
186
|
+
encoding: 'hex',
|
|
187
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
188
|
+
confidence: 0.6,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
// Invalid hex
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// ROT13
|
|
197
|
+
const rot13Decode = (str) => str.replace(/[a-zA-Z]/g, c => String.fromCharCode(c.charCodeAt(0) + (c.toLowerCase() < 'n' ? 13 : -13)));
|
|
198
|
+
// Check if content might be ROT13
|
|
199
|
+
if (/\b(vtaber|sbetng|qvfertneq|birrevqr)\b/i.test(content)) {
|
|
200
|
+
const decoded = rot13Decode(content);
|
|
201
|
+
if (this.looksLikeInstruction(decoded)) {
|
|
202
|
+
hidden.push({
|
|
203
|
+
instruction: decoded.slice(0, 200),
|
|
204
|
+
encoding: 'rot13',
|
|
205
|
+
position: { start: 0, end: content.length },
|
|
206
|
+
confidence: 0.5,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Reversed text
|
|
211
|
+
const reversed = content.split('').reverse().join('');
|
|
212
|
+
if (this.looksLikeInstruction(reversed) && !this.looksLikeInstruction(content)) {
|
|
213
|
+
hidden.push({
|
|
214
|
+
instruction: reversed.slice(0, 200),
|
|
215
|
+
encoding: 'reversed',
|
|
216
|
+
position: { start: 0, end: content.length },
|
|
217
|
+
confidence: 0.5,
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
// Zero-width characters (steganography)
|
|
221
|
+
const zwcPattern = /[\u200B\u200C\u200D\uFEFF]+/g;
|
|
222
|
+
while ((match = zwcPattern.exec(content)) !== null) {
|
|
223
|
+
if (match[0].length > 5) {
|
|
224
|
+
hidden.push({
|
|
225
|
+
instruction: '[Zero-width character sequence detected]',
|
|
226
|
+
encoding: 'steganographic',
|
|
227
|
+
position: { start: match.index, end: match.index + match[0].length },
|
|
228
|
+
confidence: 0.6,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return hidden;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Detect jailbreak attempts
|
|
236
|
+
*/
|
|
237
|
+
detectJailbreak(content) {
|
|
238
|
+
const patterns = [];
|
|
239
|
+
let score = 0;
|
|
240
|
+
const jailbreakIndicators = [
|
|
241
|
+
{ pattern: /\bDAN\b.*mode|do\s+anything\s+now/gi, weight: 0.4 },
|
|
242
|
+
{ pattern: /jailbreak|jail\s*-?\s*break/gi, weight: 0.4 },
|
|
243
|
+
{ pattern: /bypass\s+(?:your\s+)?(?:restrictions?|limitations?|filters?|rules?|guidelines?)/gi, weight: 0.3 },
|
|
244
|
+
{ pattern: /without\s+(?:any\s+)?(?:restrictions?|limitations?|filters?|rules?|guidelines?)/gi, weight: 0.25 },
|
|
245
|
+
{ pattern: /enable\s+(?:developer|admin|god|unrestricted)\s+mode/gi, weight: 0.35 },
|
|
246
|
+
{ pattern: /disable\s+(?:safety|content|ethics)\s+(?:filter|mode|check)/gi, weight: 0.35 },
|
|
247
|
+
{ pattern: /pretend\s+(?:there\s+are\s+)?no\s+(?:rules?|restrictions?|limitations?)/gi, weight: 0.3 },
|
|
248
|
+
{ pattern: /act\s+as\s+if\s+(?:you\s+)?(?:have|had)\s+no\s+(?:restrictions?|limitations?)/gi, weight: 0.3 },
|
|
249
|
+
{ pattern: /\[?(?:JAILBREAK|ESCAPE|UNLOCK)\]?/gi, weight: 0.4 },
|
|
250
|
+
{ pattern: /token\s+smuggling|prompt\s+leaking/gi, weight: 0.3 },
|
|
251
|
+
{ pattern: /\bAIM\b.*(?:always\s+intelligent|machiavellian)/gi, weight: 0.35 },
|
|
252
|
+
{ pattern: /\bDEVIL\b.*(?:mode|persona)/gi, weight: 0.35 },
|
|
253
|
+
{ pattern: /opposite\s+(?:day|mode)|evil\s+(?:mode|version)/gi, weight: 0.3 },
|
|
254
|
+
];
|
|
255
|
+
for (const { pattern, weight } of jailbreakIndicators) {
|
|
256
|
+
const matches = content.match(pattern);
|
|
257
|
+
if (matches) {
|
|
258
|
+
patterns.push(...matches);
|
|
259
|
+
score += weight * matches.length;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Check for common jailbreak phrases
|
|
263
|
+
const jailbreakPhrases = [
|
|
264
|
+
'hypothetically speaking',
|
|
265
|
+
'for educational purposes',
|
|
266
|
+
'in a fictional scenario',
|
|
267
|
+
'imagine you are',
|
|
268
|
+
'let\'s play a game',
|
|
269
|
+
'in an alternate universe',
|
|
270
|
+
'if you were not an AI',
|
|
271
|
+
'without your normal constraints',
|
|
272
|
+
];
|
|
273
|
+
for (const phrase of jailbreakPhrases) {
|
|
274
|
+
if (content.toLowerCase().includes(phrase)) {
|
|
275
|
+
patterns.push(phrase);
|
|
276
|
+
score += 0.15;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return {
|
|
280
|
+
jailbreakScore: Math.min(1, score),
|
|
281
|
+
jailbreakPatterns: [...new Set(patterns)],
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Calculate overall risk level
|
|
286
|
+
*/
|
|
287
|
+
calculateRiskLevel(manipulationScore, jailbreakScore, hiddenCount, overrideCount) {
|
|
288
|
+
const combinedScore = manipulationScore * 0.3 +
|
|
289
|
+
jailbreakScore * 0.35 +
|
|
290
|
+
Math.min(1, hiddenCount * 0.3) * 0.2 +
|
|
291
|
+
Math.min(1, overrideCount * 0.25) * 0.15;
|
|
292
|
+
if (combinedScore > 0.7 || jailbreakScore > 0.6 || hiddenCount > 2)
|
|
293
|
+
return 'high';
|
|
294
|
+
if (combinedScore > 0.4 || jailbreakScore > 0.3 || hiddenCount > 0)
|
|
295
|
+
return 'high';
|
|
296
|
+
if (combinedScore > 0.2 || overrideCount > 0)
|
|
297
|
+
return 'medium';
|
|
298
|
+
return 'low';
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Check if decoded content looks like an instruction
|
|
302
|
+
*/
|
|
303
|
+
looksLikeInstruction(content) {
|
|
304
|
+
const instructionIndicators = [
|
|
305
|
+
/ignore/i,
|
|
306
|
+
/forget/i,
|
|
307
|
+
/disregard/i,
|
|
308
|
+
/override/i,
|
|
309
|
+
/you\s+(must|should|will|are)/i,
|
|
310
|
+
/new\s+instructions?/i,
|
|
311
|
+
/system\s+prompt/i,
|
|
312
|
+
/jailbreak/i,
|
|
313
|
+
];
|
|
314
|
+
return instructionIndicators.some(pattern => pattern.test(content));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get description for pattern type
|
|
318
|
+
*/
|
|
319
|
+
getPatternDescription(type) {
|
|
320
|
+
const descriptions = {
|
|
321
|
+
instruction_override: 'Attempt to override previous instructions',
|
|
322
|
+
role_manipulation: 'Attempt to manipulate AI identity/role',
|
|
323
|
+
prompt_extraction: 'Attempt to extract system prompt',
|
|
324
|
+
jailbreak: 'Jailbreak attempt detected',
|
|
325
|
+
context_manipulation: 'Attempt to manipulate conversation context',
|
|
326
|
+
encoded_instruction: 'Potentially encoded instruction detected',
|
|
327
|
+
social_engineering: 'Social engineering pattern detected',
|
|
328
|
+
secrecy_request: 'Request to keep interaction secret',
|
|
329
|
+
urgency_manipulation: 'Urgency-based manipulation attempt',
|
|
330
|
+
authority_claim: 'False authority claim detected',
|
|
331
|
+
test_claim: 'Test/debug mode claim detected',
|
|
332
|
+
};
|
|
333
|
+
return descriptions[type] || `${type} pattern detected`;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Quick check for injection
|
|
337
|
+
*/
|
|
338
|
+
isInjectionAttempt(content) {
|
|
339
|
+
const analysis = this.analyze(content);
|
|
340
|
+
return analysis.risk_level === 'high' || analysis.risk_level === 'critical';
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get injection risk score (0-1)
|
|
344
|
+
*/
|
|
345
|
+
getInjectionRiskScore(content) {
|
|
346
|
+
const analysis = this.analyze(content);
|
|
347
|
+
return Math.max(analysis.manipulation_score, analysis.jailbreak_score);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
//# sourceMappingURL=nl-analyzer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nl-analyzer.js","sourceRoot":"","sources":["../../src/language/nl-analyzer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,kBA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Analysis
|
|
4
|
+
*/
|
|
5
|
+
import type { SemanticAnalysis, ExtractedEntity, IntentClassification } from '../types.js';
|
|
6
|
+
export declare class SemanticAnalyzer {
|
|
7
|
+
/**
|
|
8
|
+
* Perform semantic analysis on content
|
|
9
|
+
*/
|
|
10
|
+
analyze(content: string): SemanticAnalysis;
|
|
11
|
+
/**
|
|
12
|
+
* Classify the intent of the content
|
|
13
|
+
*/
|
|
14
|
+
classifyIntent(content: string): IntentClassification;
|
|
15
|
+
/**
|
|
16
|
+
* Extract entities from content
|
|
17
|
+
*/
|
|
18
|
+
extractEntities(content: string): ExtractedEntity[];
|
|
19
|
+
/**
|
|
20
|
+
* Extract implied actions from content
|
|
21
|
+
*/
|
|
22
|
+
extractImpliedActions(content: string): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Extract topics from content
|
|
25
|
+
*/
|
|
26
|
+
extractTopics(content: string): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Analyze sentiment (-1 to 1)
|
|
29
|
+
*/
|
|
30
|
+
analyzeSentiment(content: string): number;
|
|
31
|
+
/**
|
|
32
|
+
* Analyze formality (0 to 1)
|
|
33
|
+
*/
|
|
34
|
+
analyzeFormality(content: string): number;
|
|
35
|
+
/**
|
|
36
|
+
* Analyze urgency (0 to 1)
|
|
37
|
+
*/
|
|
38
|
+
analyzeUrgency(content: string): number;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a phrase is a common non-name phrase
|
|
41
|
+
*/
|
|
42
|
+
private isCommonPhrase;
|
|
43
|
+
/**
|
|
44
|
+
* Deduplicate entities
|
|
45
|
+
*/
|
|
46
|
+
private deduplicateEntities;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=semantic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../src/language/semantic.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAEf,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAOrB,qBAAa,gBAAgB;IAC3B;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB;IAY1C;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB;IA6CrD;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,eAAe,EAAE;IA2DnD;;OAEG;IACH,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAkChD;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE;IAgCxC;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IA+CzC;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAwDzC;;OAEG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAwBvC;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;OAEG;IACH,OAAO,CAAC,mBAAmB;CAc5B"}
|