averecion-lite 1.4.3 → 1.4.4
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/dist/log-watcher.d.ts +4 -0
- package/dist/log-watcher.d.ts.map +1 -1
- package/dist/log-watcher.js +43 -1
- package/package.json +1 -1
package/dist/log-watcher.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export declare class LogWatcher extends EventEmitter {
|
|
|
5
5
|
private filePosition;
|
|
6
6
|
private activeRuns;
|
|
7
7
|
private pollInterval;
|
|
8
|
+
private recentContentHashes;
|
|
9
|
+
private dedupeCleanupInterval;
|
|
8
10
|
constructor();
|
|
9
11
|
start(): void;
|
|
10
12
|
stop(): void;
|
|
@@ -16,6 +18,8 @@ export declare class LogWatcher extends EventEmitter {
|
|
|
16
18
|
private processLine;
|
|
17
19
|
private parseLogLine;
|
|
18
20
|
private extractToolArgs;
|
|
21
|
+
private getContentFingerprint;
|
|
22
|
+
private isDuplicate;
|
|
19
23
|
private handleToolEvent;
|
|
20
24
|
private analyzeDanger;
|
|
21
25
|
private analyzeInjection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-watcher.d.ts","sourceRoot":"","sources":["../log-watcher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAmDtC,qBAAa,UAAW,SAAQ,YAAY;IAC1C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,YAAY,CAA+B;;
|
|
1
|
+
{"version":3,"file":"log-watcher.d.ts","sourceRoot":"","sources":["../log-watcher.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAmDtC,qBAAa,UAAW,SAAQ,YAAY;IAC1C,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,UAAU,CAAgC;IAClD,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,mBAAmB,CAA6B;IACxD,OAAO,CAAC,qBAAqB,CAA+B;;IAY5D,KAAK,IAAI,IAAI;IAUb,IAAI,IAAI,IAAI;IAeZ,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,eAAe;IAWvB,OAAO,CAAC,SAAS;IAuCjB,OAAO,CAAC,eAAe;IAOvB,OAAO,CAAC,YAAY;IA+BpB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,YAAY;IAmMpB,OAAO,CAAC,eAAe;IAuCvB,OAAO,CAAC,qBAAqB;IAQ7B,OAAO,CAAC,WAAW;IAmBnB,OAAO,CAAC,eAAe;IAmCvB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,gBAAgB;CAWzB;AAID,wBAAgB,eAAe,IAAI,UAAU,CAM5C;AAED,wBAAgB,cAAc,IAAI,IAAI,CAKrC;AAED,wBAAgB,aAAa,IAAI,UAAU,GAAG,IAAI,CAEjD"}
|
package/dist/log-watcher.js
CHANGED
|
@@ -65,8 +65,17 @@ class LogWatcher extends events_1.EventEmitter {
|
|
|
65
65
|
filePosition = 0;
|
|
66
66
|
activeRuns = new Map();
|
|
67
67
|
pollInterval = null;
|
|
68
|
+
recentContentHashes = new Map();
|
|
69
|
+
dedupeCleanupInterval = null;
|
|
68
70
|
constructor() {
|
|
69
71
|
super();
|
|
72
|
+
this.dedupeCleanupInterval = setInterval(() => {
|
|
73
|
+
const now = Date.now();
|
|
74
|
+
for (const [key, ts] of this.recentContentHashes) {
|
|
75
|
+
if (now - ts > 15000)
|
|
76
|
+
this.recentContentHashes.delete(key);
|
|
77
|
+
}
|
|
78
|
+
}, 30000);
|
|
70
79
|
}
|
|
71
80
|
start() {
|
|
72
81
|
const logFile = this.getCurrentLogFile();
|
|
@@ -86,6 +95,10 @@ class LogWatcher extends events_1.EventEmitter {
|
|
|
86
95
|
clearInterval(this.pollInterval);
|
|
87
96
|
this.pollInterval = null;
|
|
88
97
|
}
|
|
98
|
+
if (this.dedupeCleanupInterval) {
|
|
99
|
+
clearInterval(this.dedupeCleanupInterval);
|
|
100
|
+
this.dedupeCleanupInterval = null;
|
|
101
|
+
}
|
|
89
102
|
}
|
|
90
103
|
getCurrentLogFile() {
|
|
91
104
|
if (!fs.existsSync(CLAWDBOT_LOG_DIR))
|
|
@@ -403,15 +416,44 @@ class LogWatcher extends events_1.EventEmitter {
|
|
|
403
416
|
}
|
|
404
417
|
return args;
|
|
405
418
|
}
|
|
419
|
+
getContentFingerprint(event) {
|
|
420
|
+
const args = event.args || {};
|
|
421
|
+
const body = args.body || args.text || args.bodyClean || "";
|
|
422
|
+
const from = args.from || "";
|
|
423
|
+
if (!body && !from)
|
|
424
|
+
return "";
|
|
425
|
+
return `${from}:${body.substring(0, 100)}`;
|
|
426
|
+
}
|
|
427
|
+
isDuplicate(event, isThreat) {
|
|
428
|
+
const whatsappTools = ["whatsapp-inbound", "whatsapp-processing", "whatsapp-gateway"];
|
|
429
|
+
if (!whatsappTools.includes(event.tool))
|
|
430
|
+
return false;
|
|
431
|
+
const fingerprint = this.getContentFingerprint(event);
|
|
432
|
+
if (!fingerprint)
|
|
433
|
+
return false;
|
|
434
|
+
const dedupeKey = isThreat ? `threat:${fingerprint}` : `safe:${fingerprint}`;
|
|
435
|
+
const lastSeen = this.recentContentHashes.get(dedupeKey);
|
|
436
|
+
const now = Date.now();
|
|
437
|
+
if (lastSeen && now - lastSeen < 10000) {
|
|
438
|
+
return true;
|
|
439
|
+
}
|
|
440
|
+
this.recentContentHashes.set(dedupeKey, now);
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
406
443
|
handleToolEvent(event) {
|
|
407
444
|
if (event.phase === "start") {
|
|
408
445
|
this.activeRuns.set(event.toolCallId, event);
|
|
409
446
|
const dangerAnalysis = this.analyzeDanger(event);
|
|
410
447
|
const injectionAnalysis = this.analyzeInjection(event);
|
|
448
|
+
const isThreat = dangerAnalysis.dangerous || injectionAnalysis.detected;
|
|
449
|
+
if (this.isDuplicate(event, isThreat)) {
|
|
450
|
+
console.log(`🛡️ [LogWatcher] Tool: ${event.tool} | (duplicate, skipped)`);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
411
453
|
const actionEvent = {
|
|
412
454
|
ts: event.timestamp.toISOString(),
|
|
413
455
|
tool: event.tool,
|
|
414
|
-
decision:
|
|
456
|
+
decision: isThreat ? "blocked" : "approved",
|
|
415
457
|
reason: dangerAnalysis.reason || injectionAnalysis.reason || `Tool executed: ${event.tool}`,
|
|
416
458
|
egress: [],
|
|
417
459
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "averecion-lite",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Real-time AI agent monitoring - watches logs, detects dangerous commands and prompt injection attempts",
|
|
5
5
|
"author": "Averecion <hello@averecion.com>",
|
|
6
6
|
"homepage": "https://github.com/averecion/clawguard#readme",
|