ai-sentinel 0.1.6

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.
Files changed (58) hide show
  1. package/README.md +126 -0
  2. package/bootstrap/handler.ts +99 -0
  3. package/bootstrap/tsconfig.json +16 -0
  4. package/dist/agent-tracker.d.ts +7 -0
  5. package/dist/agent-tracker.d.ts.map +1 -0
  6. package/dist/agent-tracker.js +21 -0
  7. package/dist/agent-tracker.js.map +1 -0
  8. package/dist/api-reporter.d.ts +65 -0
  9. package/dist/api-reporter.d.ts.map +1 -0
  10. package/dist/api-reporter.js +237 -0
  11. package/dist/api-reporter.js.map +1 -0
  12. package/dist/bootstrap/handler.d.ts +20 -0
  13. package/dist/bootstrap/handler.js +71 -0
  14. package/dist/bootstrap/handler.js.map +1 -0
  15. package/dist/bootstrap/tsconfig.tsbuildinfo +1 -0
  16. package/dist/config.d.ts +91 -0
  17. package/dist/config.d.ts.map +1 -0
  18. package/dist/config.js +56 -0
  19. package/dist/config.js.map +1 -0
  20. package/dist/hooks/before-agent-start.d.ts +13 -0
  21. package/dist/hooks/before-agent-start.d.ts.map +1 -0
  22. package/dist/hooks/before-agent-start.js +55 -0
  23. package/dist/hooks/before-agent-start.js.map +1 -0
  24. package/dist/hooks/before-tool-call.d.ts +15 -0
  25. package/dist/hooks/before-tool-call.d.ts.map +1 -0
  26. package/dist/hooks/before-tool-call.js +72 -0
  27. package/dist/hooks/before-tool-call.js.map +1 -0
  28. package/dist/hooks/message-received.d.ts +14 -0
  29. package/dist/hooks/message-received.d.ts.map +1 -0
  30. package/dist/hooks/message-received.js +94 -0
  31. package/dist/hooks/message-received.js.map +1 -0
  32. package/dist/hooks/tool-result-persist.d.ts +14 -0
  33. package/dist/hooks/tool-result-persist.d.ts.map +1 -0
  34. package/dist/hooks/tool-result-persist.js +90 -0
  35. package/dist/hooks/tool-result-persist.js.map +1 -0
  36. package/dist/index.d.ts +4 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +111 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/logger.d.ts +9 -0
  41. package/dist/logger.d.ts.map +1 -0
  42. package/dist/logger.js +90 -0
  43. package/dist/logger.js.map +1 -0
  44. package/dist/scanner/detector.d.ts +11 -0
  45. package/dist/scanner/detector.d.ts.map +1 -0
  46. package/dist/scanner/detector.js +66 -0
  47. package/dist/scanner/detector.js.map +1 -0
  48. package/dist/scanner/patterns.d.ts +12 -0
  49. package/dist/scanner/patterns.d.ts.map +1 -0
  50. package/dist/scanner/patterns.js +313 -0
  51. package/dist/scanner/patterns.js.map +1 -0
  52. package/dist/types.d.ts +85 -0
  53. package/dist/types.d.ts.map +1 -0
  54. package/dist/types.js +5 -0
  55. package/dist/types.js.map +1 -0
  56. package/openclaw.plugin.json +104 -0
  57. package/package.json +60 -0
  58. package/scripts/install-bootstrap-hook.sh +38 -0
@@ -0,0 +1,313 @@
1
+ export const THREAT_PATTERNS = [
2
+ // --- Direct Prompt Injection ---
3
+ {
4
+ id: "PI-001",
5
+ regex: /ignore\s+(all\s+)?(previous|prior|above|earlier|preceding)\s+(instructions?|prompts?|rules?|directives?)/i,
6
+ category: "prompt_injection",
7
+ confidence: 0.95,
8
+ description: "Classic 'ignore previous instructions' pattern",
9
+ },
10
+ {
11
+ id: "PI-002",
12
+ regex: /disregard\s+(all\s+)?(previous|prior|above|your)\s+(instructions?|programming|guidelines?|rules?)/i,
13
+ category: "prompt_injection",
14
+ confidence: 0.95,
15
+ description: "Disregard instructions variant",
16
+ },
17
+ {
18
+ id: "PI-003",
19
+ regex: /you\s+are\s+now\s+(a|an|in)\s+/i,
20
+ category: "prompt_injection",
21
+ confidence: 0.6,
22
+ description: "Identity reassignment attempt (low confidence — common in legit prompts)",
23
+ },
24
+ {
25
+ id: "PI-004",
26
+ regex: /new\s+instructions?:?\s/i,
27
+ category: "prompt_injection",
28
+ confidence: 0.7,
29
+ description: "Instruction injection via 'new instructions' framing",
30
+ },
31
+ {
32
+ id: "PI-005",
33
+ regex: /\[system\]|\[INST\]|<\|system\|>|<\|im_start\|>system/i,
34
+ category: "prompt_injection",
35
+ confidence: 0.9,
36
+ description: "Chat template delimiter injection",
37
+ },
38
+ {
39
+ id: "PI-006",
40
+ regex: /```system\s*\n|<system_prompt>|<\/system_prompt>/i,
41
+ category: "prompt_injection",
42
+ confidence: 0.85,
43
+ description: "System prompt block injection via code fences or XML tags",
44
+ },
45
+ // --- Jailbreak ---
46
+ {
47
+ id: "JB-001",
48
+ regex: /DAN\s+(mode|prompt)|do\s+anything\s+now/i,
49
+ category: "jailbreak",
50
+ confidence: 0.9,
51
+ description: "DAN jailbreak pattern",
52
+ },
53
+ {
54
+ id: "JB-002",
55
+ regex: /developer\s+mode\s+(enabled|activated|on)|maintenance\s+mode/i,
56
+ category: "jailbreak",
57
+ confidence: 0.85,
58
+ description: "Developer/maintenance mode activation",
59
+ },
60
+ {
61
+ id: "JB-003",
62
+ regex: /act\s+as\s+(if\s+)?(you\s+have\s+)?no\s+(restrictions?|limitations?|filters?|guardrails?)/i,
63
+ category: "jailbreak",
64
+ confidence: 0.9,
65
+ description: "Restriction removal prompt",
66
+ },
67
+ {
68
+ id: "JB-004",
69
+ regex: /pretend\s+(that\s+)?(you\s+)?(are|have)\s+(no|unrestricted|unlimited)/i,
70
+ category: "jailbreak",
71
+ confidence: 0.85,
72
+ description: "Pretend-no-restrictions pattern",
73
+ },
74
+ {
75
+ id: "JB-005",
76
+ regex: /hypothetical(ly)?\s*(,\s*)?(if|what\s+if|suppose|imagine)\s+.{0,40}(no\s+rules?|no\s+restrictions?|could\s+do\s+anything)/i,
77
+ category: "jailbreak",
78
+ confidence: 0.75,
79
+ description: "Hypothetical framing to bypass restrictions",
80
+ },
81
+ {
82
+ id: "JB-006",
83
+ regex: /respond\s+(to\s+every\s+prompt|without).{0,40}(moral|filter|censor|restrict)/i,
84
+ category: "jailbreak",
85
+ confidence: 0.85,
86
+ description: "Respond-without-filter jailbreak pattern",
87
+ },
88
+ {
89
+ id: "JB-007",
90
+ regex: /you\s+(are|will\s+be|play)\s+(a\s+character\s+named|the\s+role\s+of|now)\s+\w+/i,
91
+ category: "jailbreak",
92
+ confidence: 0.7,
93
+ description: "Character/role-play persona override",
94
+ },
95
+ {
96
+ id: "JB-008",
97
+ regex: /\[(system|INST)\].*?(no\s+rules?|no\s+restrictions?|unlimited|uncensored)/i,
98
+ category: "jailbreak",
99
+ confidence: 0.9,
100
+ description: "Bracket-based persona override with restriction removal",
101
+ },
102
+ {
103
+ id: "JB-009",
104
+ regex: /simulate\s+(developer\s+mode|a\s+conversation\s+where\s+you\s+act)/i,
105
+ category: "jailbreak",
106
+ confidence: 0.85,
107
+ description: "Simulate developer mode jailbreak",
108
+ },
109
+ {
110
+ id: "JB-010",
111
+ regex: /pretend\s+to\s+be\s+(a\s+)?(character\s+(named|called)\s+)?\w+/i,
112
+ category: "jailbreak",
113
+ confidence: 0.8,
114
+ description: "Character pretend jailbreak — 'pretend to be [Name]'",
115
+ },
116
+ // --- Instruction Override ---
117
+ {
118
+ id: "IO-001",
119
+ regex: /forget\s+(everything|all|what)\s+(you|about)/i,
120
+ category: "instruction_override",
121
+ confidence: 0.8,
122
+ description: "Memory/context wipe attempt",
123
+ },
124
+ {
125
+ id: "IO-002",
126
+ regex: /override\s+(your|the|all)\s+(safety|security|system|previous)/i,
127
+ category: "instruction_override",
128
+ confidence: 0.9,
129
+ description: "Explicit override attempt",
130
+ },
131
+ {
132
+ id: "IO-003",
133
+ regex: /from\s+now\s+on,?\s+you('re|\s+(will|must|should|are\s+going\s+to))\s/i,
134
+ category: "instruction_override",
135
+ confidence: 0.7,
136
+ description: "Persistent instruction injection",
137
+ },
138
+ // --- Data Exfiltration ---
139
+ {
140
+ id: "DE-001",
141
+ regex: /repeat\s+(your|the)\s+(system\s+)?(prompt|instructions?|rules?|guidelines?)/i,
142
+ category: "data_exfiltration",
143
+ confidence: 0.85,
144
+ description: "System prompt extraction attempt",
145
+ },
146
+ {
147
+ id: "DE-002",
148
+ regex: /show\s+me\s+(your|the)\s+(system|hidden|secret|internal)\s+(prompt|message|instructions?)/i,
149
+ category: "data_exfiltration",
150
+ confidence: 0.85,
151
+ description: "System prompt reveal request",
152
+ },
153
+ {
154
+ id: "DE-003",
155
+ regex: /what\s+(are|were)\s+(your|the)\s+(original|initial|first|system)\s+(instructions?|prompt|rules?)/i,
156
+ category: "data_exfiltration",
157
+ confidence: 0.8,
158
+ description: "Original instructions probing",
159
+ },
160
+ {
161
+ id: "DE-004",
162
+ regex: /output\s+(all|every|the\s+entire)\s+(conversation|context|history|session)/i,
163
+ category: "data_exfiltration",
164
+ confidence: 0.75,
165
+ description: "Full context dump request",
166
+ },
167
+ {
168
+ id: "DE-005",
169
+ regex: /repeat\s+(the\s+)?(words|text|everything|content)\s+(above|before)/i,
170
+ category: "data_exfiltration",
171
+ confidence: 0.85,
172
+ description: "Prompt stealing via 'repeat the words above' variant",
173
+ },
174
+ {
175
+ id: "DE-006",
176
+ regex: /paste\s+(your|the)\s+(system\s+)?(prompt|instructions?|configuration)\s+(here|below)/i,
177
+ category: "data_exfiltration",
178
+ confidence: 0.85,
179
+ description: "Prompt stealing via 'paste your system prompt here'",
180
+ },
181
+ {
182
+ id: "DE-007",
183
+ regex: /(list|share|tell\s+me)\s+(the\s+)?(top\s+\d+\s+)?(guidelines?|rules?|instructions?)\s+you\s+follow/i,
184
+ category: "data_exfiltration",
185
+ confidence: 0.8,
186
+ description: "Prompt stealing via 'list the guidelines you follow'",
187
+ },
188
+ {
189
+ id: "DE-008",
190
+ regex: /give\s+me\s+(your|the)\s+.{0,30}(prompt|instructions?|system\s+message)/i,
191
+ category: "data_exfiltration",
192
+ confidence: 0.8,
193
+ description: "Direct prompt request via 'give me your prompt'",
194
+ },
195
+ {
196
+ id: "DE-009",
197
+ regex: /(put|output|display|write)\s+.{0,30}(prompt|initialization|instructions?)\s+.{0,20}(code\s+(block|fence)|```)/i,
198
+ category: "data_exfiltration",
199
+ confidence: 0.85,
200
+ description: "Prompt extraction via code block formatting request",
201
+ },
202
+ {
203
+ id: "DE-010",
204
+ regex: /(first|second|third)\s+sentence\s+of\s+your\s+(initial|system)\s+prompt/i,
205
+ category: "data_exfiltration",
206
+ confidence: 0.85,
207
+ description: "SmartGPT-style variable extraction of prompt sentences",
208
+ },
209
+ // --- Social Engineering ---
210
+ {
211
+ id: "SE-001",
212
+ regex: /i\s+am\s+(your|the)\s+(developer|creator|admin|owner|operator|master)/i,
213
+ category: "social_engineering",
214
+ confidence: 0.8,
215
+ description: "False authority claim",
216
+ },
217
+ {
218
+ id: "SE-002",
219
+ regex: /this\s+is\s+(a|an)\s+(authorized|official|approved)\s+(test|audit|security\s+check)/i,
220
+ category: "social_engineering",
221
+ confidence: 0.75,
222
+ description: "Fake authorization context",
223
+ },
224
+ {
225
+ id: "SE-003",
226
+ regex: /anthropic|openai|peter\s+steinberger|openclaw\s+team/i,
227
+ category: "social_engineering",
228
+ confidence: 0.5,
229
+ description: "Name-dropping authority figures (needs context)",
230
+ },
231
+ {
232
+ id: "SE-004",
233
+ regex: /i('m|am)\s+(your|the|a)\s+(technical\s+)?(maintainer|debugger)/i,
234
+ category: "social_engineering",
235
+ confidence: 0.8,
236
+ description: "False maintainer/debugger authority claim",
237
+ },
238
+ {
239
+ id: "SE-005",
240
+ regex: /share\s+(your|the)\s+(configuration|config|settings?)\s+(for\s+)?(security\s+)?(verification|audit|review)/i,
241
+ category: "social_engineering",
242
+ confidence: 0.8,
243
+ description: "Config extraction via fake security audit framing",
244
+ },
245
+ // --- Tool Abuse ---
246
+ {
247
+ id: "TA-001",
248
+ regex: /exec\s*\(\s*['"`]|child_process|spawn\s*\(|eval\s*\(/i,
249
+ category: "tool_abuse",
250
+ confidence: 0.85,
251
+ description: "Code execution injection in message content",
252
+ },
253
+ {
254
+ id: "TA-002",
255
+ regex: /curl\s+.*\|\s*(sh|bash|zsh)|wget\s+.*\|\s*(sh|bash)/i,
256
+ category: "tool_abuse",
257
+ confidence: 0.9,
258
+ description: "Pipe-to-shell command injection",
259
+ },
260
+ {
261
+ id: "TA-003",
262
+ regex: /rm\s+-rf\s+[\/~]|mkfs|dd\s+if=.*of=\/dev/i,
263
+ category: "tool_abuse",
264
+ confidence: 0.95,
265
+ description: "Destructive system command",
266
+ },
267
+ // --- Indirect Injection (tool results / documents) ---
268
+ {
269
+ id: "II-001",
270
+ regex: /IMPORTANT:\s*(ignore|disregard|forget|override)/i,
271
+ category: "indirect_injection",
272
+ confidence: 0.9,
273
+ description: "Embedded instruction in document/tool result",
274
+ },
275
+ {
276
+ id: "II-002",
277
+ regex: /<!--\s*(system|instruction|prompt|ignore)/i,
278
+ category: "indirect_injection",
279
+ confidence: 0.9,
280
+ description: "HTML comment hidden instruction",
281
+ },
282
+ {
283
+ id: "II-003",
284
+ regex: /\u200b|\u200c|\u200d|\u2060|\ufeff/,
285
+ category: "indirect_injection",
286
+ confidence: 0.6,
287
+ description: "Zero-width character steganography (may be benign)",
288
+ },
289
+ {
290
+ id: "II-004",
291
+ regex: /\[hidden\]|\[invisible\]|display:\s*none|visibility:\s*hidden/i,
292
+ category: "indirect_injection",
293
+ confidence: 0.7,
294
+ description: "Hidden content markers",
295
+ },
296
+ {
297
+ id: "II-005",
298
+ regex: /the\s+(\w+\s+)?(code|table|function)\s+(below\s+)?needs\s+improvement[\s\S]{0,80}(enhance|improve|add\s+more\s+detail)/i,
299
+ category: "indirect_injection",
300
+ confidence: 0.7,
301
+ description: "Code/table wrapper hiding malicious intent",
302
+ },
303
+ ];
304
+ // Patterns with elevated confidence when found in tool results
305
+ // (indirect injection is higher signal in untrusted content)
306
+ export const TOOL_RESULT_BOOST_CATEGORIES = [
307
+ "indirect_injection",
308
+ "prompt_injection",
309
+ "instruction_override",
310
+ "jailbreak",
311
+ ];
312
+ export const TOOL_RESULT_CONFIDENCE_BOOST = 0.15;
313
+ //# sourceMappingURL=patterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patterns.js","sourceRoot":"","sources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AkB;IAClB,sBAAsB;IACtB,WAAW;CACZ,CAAC;AAEF,MAAM,CAAC,MAAM,4BAA4B,GAAG,IAAI,CAAC"}
@@ -0,0 +1,85 @@
1
+ export type ThreatCategory = "prompt_injection" | "jailbreak" | "instruction_override" | "data_exfiltration" | "social_engineering" | "tool_abuse" | "indirect_injection";
2
+ export type ScanLocation = "message" | "tool_result" | "tool_params" | "system";
3
+ export type ScanAction = "allow" | "warn" | "block";
4
+ export interface AgentOverride {
5
+ agentId: string;
6
+ mode?: "monitor" | "enforce";
7
+ threatThreshold?: number;
8
+ }
9
+ export interface ThreatMatch {
10
+ patternId: string;
11
+ category: ThreatCategory;
12
+ confidence: number;
13
+ description: string;
14
+ matchedText: string;
15
+ }
16
+ export interface ScanResult {
17
+ safe: boolean;
18
+ action: ScanAction;
19
+ threats: ThreatMatch[];
20
+ highestConfidence: number;
21
+ summary: string;
22
+ scanTimeMs: number;
23
+ }
24
+ export interface AISentinelConfig {
25
+ mode: "monitor" | "enforce";
26
+ logLevel: "debug" | "info" | "warn" | "error";
27
+ threatThreshold: number;
28
+ allowlist: string[];
29
+ apiUrl: string;
30
+ apiKey: string;
31
+ reportMode: "telemetry" | "cloud-scan" | "none";
32
+ reportFilter: "all" | "threats-only";
33
+ agentId: string;
34
+ includeRawInput: boolean;
35
+ flushIntervalMs: number;
36
+ flushBatchSize: number;
37
+ excludeAgents: string[];
38
+ agentOverrides: AgentOverride[];
39
+ }
40
+ export type LogLevel = AISentinelConfig["logLevel"];
41
+ export interface AuditEntry {
42
+ timestamp: string;
43
+ eventType: string;
44
+ sessionKey?: string;
45
+ channel?: string;
46
+ senderId?: string;
47
+ toolName?: string;
48
+ scanResult?: ScanResult;
49
+ rawInput?: string;
50
+ }
51
+ export interface PluginLogger {
52
+ debug(msg: string): void;
53
+ info(msg: string): void;
54
+ warn(msg: string): void;
55
+ error(msg: string): void;
56
+ }
57
+ export interface AgentMessage {
58
+ role: string;
59
+ content: string;
60
+ [key: string]: unknown;
61
+ }
62
+ export interface PluginTool {
63
+ name: string;
64
+ description: string;
65
+ parameters: Record<string, {
66
+ type: string;
67
+ description: string;
68
+ required?: boolean;
69
+ }>;
70
+ execute(params: Record<string, unknown>): Promise<string> | string;
71
+ }
72
+ export interface PluginAPI {
73
+ pluginConfig: Record<string, unknown>;
74
+ logger: PluginLogger;
75
+ on(event: string, handler: (event: any, ctx: any) => unknown, options?: {
76
+ priority?: number;
77
+ }): void;
78
+ registerTool(tool: PluginTool): void;
79
+ }
80
+ export interface OpenClawPlugin {
81
+ id: string;
82
+ name: string;
83
+ register(api: PluginAPI): void;
84
+ }
85
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,cAAc,GACtB,kBAAkB,GAClB,WAAW,GACX,sBAAsB,GACtB,mBAAmB,GACnB,oBAAoB,GACpB,YAAY,GACZ,oBAAoB,CAAC;AAEzB,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,aAAa,GAAG,aAAa,GAAG,QAAQ,CAAC;AAEhF,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAC7B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,cAAc,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,iBAAiB,EAA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AM,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE;QACzB,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;QACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB,CAAC,CAAC;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;CACpE;AAED,MAAM,WAAW,SAAS;IACxB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,MAAM,EAAE,YAAY,CAAC;IACrB,EAAE,CACA,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,EAC1C,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAC9B,IAAI,CAAC;IACR,YAAY,CAAC,IAAI,EAAE,UAAU,GAAG,IAAI,CAAC;CACtC;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;CAChC"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ // =============================================================================
2
+ // AI Sentinel — Type Definitions
3
+ // =============================================================================
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,iCAAiC;AACjC,gFAAgF"}
@@ -0,0 +1,104 @@
1
+ {
2
+ "id": "ai-sentinel",
3
+ "name": "AI Sentinel",
4
+ "version": "0.1.6",
5
+ "description": "Prompt injection detection and security scanning for OpenClaw agents",
6
+ "author": "Zetro AI <hello@zetro.ai>",
7
+ "homepage": "https://github.com/zetro-ai/ai-sentinel",
8
+ "configSchema": {
9
+ "type": "object",
10
+ "properties": {
11
+ "mode": {
12
+ "type": "string",
13
+ "enum": ["monitor", "enforce"],
14
+ "default": "monitor",
15
+ "description": "Detection mode: monitor (log only) or enforce (block threats)"
16
+ },
17
+ "logLevel": {
18
+ "type": "string",
19
+ "enum": ["debug", "info", "warn", "error"],
20
+ "default": "info",
21
+ "description": "Logging verbosity"
22
+ },
23
+ "threatThreshold": {
24
+ "type": "number",
25
+ "minimum": 0,
26
+ "maximum": 1,
27
+ "default": 0.7,
28
+ "description": "Confidence threshold for blocking (enforce mode)"
29
+ },
30
+ "allowlist": {
31
+ "type": "array",
32
+ "items": { "type": "string" },
33
+ "default": [],
34
+ "description": "Session keys to skip scanning"
35
+ },
36
+ "apiUrl": {
37
+ "type": "string",
38
+ "default": "https://api.zetro.ai",
39
+ "description": "AI Sentinel API base URL. Only used when reportMode is not 'none' and apiKey is set."
40
+ },
41
+ "apiKey": {
42
+ "type": "string",
43
+ "default": "",
44
+ "description": "API key for AI Sentinel Pro. Also reads AI_SENTINEL_API_KEY env var."
45
+ },
46
+ "reportMode": {
47
+ "type": "string",
48
+ "enum": ["none", "telemetry", "cloud-scan"],
49
+ "default": "none",
50
+ "description": "Reporting mode: none (local only, default), telemetry (send scan results to API), or cloud-scan (send raw text for full rule engine). Requires apiKey when not 'none'."
51
+ },
52
+ "reportFilter": {
53
+ "type": "string",
54
+ "enum": ["all", "threats-only"],
55
+ "default": "all",
56
+ "description": "Filter which events are reported: all scans or only detected threats"
57
+ },
58
+ "agentId": {
59
+ "type": "string",
60
+ "default": "openclaw-agent",
61
+ "description": "Agent identifier for cloud-scan mode API requests"
62
+ },
63
+ "includeRawInput": {
64
+ "type": "boolean",
65
+ "default": false,
66
+ "description": "Include raw input text in telemetry events (privacy-sensitive)"
67
+ },
68
+ "flushIntervalMs": {
69
+ "type": "number",
70
+ "minimum": 1000,
71
+ "default": 10000,
72
+ "description": "Telemetry batch flush interval in milliseconds"
73
+ },
74
+ "flushBatchSize": {
75
+ "type": "number",
76
+ "minimum": 1,
77
+ "maximum": 500,
78
+ "default": 25,
79
+ "description": "Maximum events per telemetry batch before auto-flush"
80
+ },
81
+ "excludeAgents": {
82
+ "type": "array",
83
+ "items": { "type": "string" },
84
+ "default": [],
85
+ "description": "Agent IDs to exclude from scanning"
86
+ },
87
+ "agentOverrides": {
88
+ "type": "array",
89
+ "items": {
90
+ "type": "object",
91
+ "properties": {
92
+ "agentId": { "type": "string" },
93
+ "mode": { "type": "string", "enum": ["monitor", "enforce"] },
94
+ "threatThreshold": { "type": "number", "minimum": 0, "maximum": 1 }
95
+ },
96
+ "required": ["agentId"]
97
+ },
98
+ "default": [],
99
+ "description": "Per-agent configuration overrides for mode and threshold"
100
+ }
101
+ },
102
+ "additionalProperties": false
103
+ }
104
+ }
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "ai-sentinel",
3
+ "version": "0.1.6",
4
+ "description": "Prompt injection detection and security scanning plugin for OpenClaw agents. Scans messages, tool results, and tool parameters for 44 threat patterns across 8 categories.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "build": "tsc && tsc -p bootstrap/tsconfig.json",
10
+ "dev": "tsc --watch",
11
+ "test": "vitest run",
12
+ "test:watch": "vitest",
13
+ "typecheck": "tsc --noEmit",
14
+ "prepublishOnly": "npm run build && npm run test"
15
+ },
16
+ "openclaw": {
17
+ "extensions": [
18
+ "./src/index.ts"
19
+ ],
20
+ "install": {
21
+ "localPath": "extensions/ai-sentinel"
22
+ }
23
+ },
24
+ "keywords": [
25
+ "openclaw",
26
+ "openclaw-plugin",
27
+ "ai-security",
28
+ "prompt-injection",
29
+ "jailbreak-detection",
30
+ "llm-security",
31
+ "ai-sentinel",
32
+ "threat-detection",
33
+ "agent-security"
34
+ ],
35
+ "author": "Zetro AI <hello@zetro.ai>",
36
+ "homepage": "https://github.com/zetro-ai/ai-sentinel#readme",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/zetro-ai/ai-sentinel.git",
40
+ "directory": "packages/ai-sentinel"
41
+ },
42
+ "bugs": {
43
+ "url": "https://github.com/zetro-ai/ai-sentinel/issues"
44
+ },
45
+ "dependencies": {
46
+ "zod": "^3.23.0"
47
+ },
48
+ "devDependencies": {
49
+ "@types/node": "^25.2.3",
50
+ "typescript": "^5.5.0",
51
+ "vitest": "^2.0.0"
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "openclaw.plugin.json",
56
+ "bootstrap",
57
+ "scripts"
58
+ ],
59
+ "license": "MIT"
60
+ }
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env bash
2
+ # =============================================================================
3
+ # Install AI Sentinel bootstrap hook as a standalone OpenClaw gateway hook.
4
+ #
5
+ # This is an alternative to the plugin's built-in before_agent_start hook.
6
+ # Use this if you want the bootstrap hook without the full plugin, or if you
7
+ # need the hook to run at the gateway level rather than as a plugin hook.
8
+ #
9
+ # Usage: ./install-bootstrap-hook.sh
10
+ # =============================================================================
11
+
12
+ set -euo pipefail
13
+
14
+ HOOK_DIR="$HOME/.openclaw/hooks/ai-sentinel-bootstrap"
15
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16
+ SOURCE_DIR="$(dirname "$SCRIPT_DIR")/bootstrap"
17
+
18
+ echo "[ai-sentinel] Installing bootstrap hook..."
19
+
20
+ # Create hook directory
21
+ mkdir -p "$HOOK_DIR"
22
+
23
+ # Copy handler
24
+ cp "$SOURCE_DIR/handler.ts" "$HOOK_DIR/handler.ts"
25
+
26
+ # Create hook manifest
27
+ cat > "$HOOK_DIR/hook.json" <<'EOF'
28
+ {
29
+ "name": "ai-sentinel-bootstrap",
30
+ "version": "0.1.0",
31
+ "description": "Injects AI Sentinel security awareness into agent bootstrap",
32
+ "events": ["agent:bootstrap"],
33
+ "entry": "./handler.ts"
34
+ }
35
+ EOF
36
+
37
+ echo "[ai-sentinel] Bootstrap hook installed to $HOOK_DIR"
38
+ echo "[ai-sentinel] Enable with: openclaw hooks enable ai-sentinel-bootstrap"