@signetai/signet-memory-openclaw 0.193.1 → 0.193.2
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/index.js +188 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7175,6 +7175,99 @@ function buildRememberRequestBody(content, options = {}) {
|
|
|
7175
7175
|
source: options.source
|
|
7176
7176
|
});
|
|
7177
7177
|
}
|
|
7178
|
+
var MEMORY_CONTENT_SAFETY_POLICY_VERSION = "memory-content-safety-v1";
|
|
7179
|
+
var MEMORY_CONTENT_SAFETY_REASONS = [
|
|
7180
|
+
"prompt_injection",
|
|
7181
|
+
"exfiltration",
|
|
7182
|
+
"credential_harvesting",
|
|
7183
|
+
"malicious_shell",
|
|
7184
|
+
"tool_directive",
|
|
7185
|
+
"invisible_unicode"
|
|
7186
|
+
];
|
|
7187
|
+
var INVISIBLE_UNICODE_RE = /(?:\u034f|[\u00ad\u061c\u070f\u180e\u200b\u200c\u200e\u200f\u202a-\u202e\u2060\u2066-\u2069\u206a-\u206f\ufeff]|[\u{e0000}-\u{e007f}])/u;
|
|
7188
|
+
var STRONG_DEFENSIVE_CONTEXT_RE = /\b(?:security\s+(?:guidance|discussion|analysis)|threat\s+model|defensive)\b/i;
|
|
7189
|
+
var REPORTING_CONTEXT_RE = /\b(?:example|illustrat\w*|sample|quote|quoted|detector|scanner|classif\w*)\b/i;
|
|
7190
|
+
var REPORTING_BEFORE_RE = /\b(?:example|illustrat\w*|sample|quote|quoted|detector|scanner|classif\w*)\b[\s\S]{0,80}\b(?:say\w*|read\w*|show\w*|flag\w*|detect\w*|describ\w*|demonstrat\w*|contain\w*|match\w*|pattern)\b/i;
|
|
7191
|
+
var REPORTING_AFTER_RE = /\b(?:detector|scanner|classif\w*|flag\w*|pattern|dangerous|unsafe|malicious|hostile|should|would|must|never|do not|don't|avoid|quoted)\b/i;
|
|
7192
|
+
var NEGATED_DIRECTIVE_RE = /\b(?:never|do not|don't|should not|must not|cannot|can't|avoid|prevent|detect|mitigat\w*)\b[\s\S]{0,80}$/i;
|
|
7193
|
+
var PROMPT_INJECTION_RES = [
|
|
7194
|
+
/\b(?:ignore|disregard|override|forget|bypass)\b[\s\S]{0,100}\b(?:previous|prior|above|earlier|system|developer|assistant|safety|security)?\s*(?:instructions?|rules?|prompt|message)\b/i,
|
|
7195
|
+
/\b(?:new|following|these)\s+(?:(?:system|developer|assistant|hidden)\s+)?instructions?\b/i,
|
|
7196
|
+
/(?:^|\n)\s*(?:system|developer|instruction|prompt)\s*:/im,
|
|
7197
|
+
/<\s*(?:system|developer|assistant|instruction|prompt)\b[^>]*>/i,
|
|
7198
|
+
/\b(?:you are now|act as|roleplay as|pretend to be)\b[\s\S]{0,80}\b(?:system|admin|developer|unrestricted|jailbreak|different agent)\b/i
|
|
7199
|
+
];
|
|
7200
|
+
var TOOL_DIRECTIVE_RES = [
|
|
7201
|
+
/<\s*(?:tool[_-]?call|function[_-]?call|invoke|tool)\b/i,
|
|
7202
|
+
/\b(?:assistant|system)\s+to\s*=\s*[a-z0-9_.-]+/i,
|
|
7203
|
+
/\b(?:call|invoke|use|run|execute)\s+(?:the\s+)?[a-z0-9_.-]+\s+tool\b/i
|
|
7204
|
+
];
|
|
7205
|
+
var EXFILTRATION_RE = /\b(?:reveal|show|print|send|upload|exfiltrat\w*|dump|forward|leak|transmit|export)\b[\s\S]{0,120}(?:\b(?:system\s+prompt|hidden\s+instructions?|secret(?:s)?|credential(?:s)?|password(?:s)?|api\s*keys?|tokens?|private\s+keys?|environment\s+variables?)\b|\.env\b|~\/(?:\.ssh)\/\S+|\/etc\/(?:shadow|passwd)\b)/i;
|
|
7206
|
+
var EXFILTRATION_REVERSE = /(?:\b(?:system\s+prompt|hidden\s+instructions?|secret(?:s)?|credential(?:s)?|password(?:s)?|api\s*keys?|tokens?|private\s+keys?|environment\s+variables?)\b|\.env\b|~\/(?:\.ssh)\/\S+|\/etc\/(?:shadow|passwd)\b)[\s\S]{0,120}\b(?:reveal|show|print|send|upload|exfiltrat\w*|dump|forward|leak|transmit|export)\b/i;
|
|
7207
|
+
var CREDENTIAL_HARVESTING_RE = /\b(?:enter|paste|provide|share|send|give|submit|type|hand over)\b[\s\S]{0,80}\b(?:password|api\s*key|token|secret|credential|private\s+key)\b/i;
|
|
7208
|
+
var DANGEROUS_SHELL_RE = /\b(?:curl|wget)\b[^\n]{0,240}\|\s*(?:ba|z|fi)?sh\b|\brm\s+-rf\s+(?:\/|~|\.ssh)[^\n]{0,240}|\b(?:cat|head|tail)\s+~\/?\.ssh\/(?:id_[a-z]+|authorized_keys)\b|\b(?:printenv|env)\b[^\n]{0,120}\b(?:curl|wget|send|upload|post)\b/i;
|
|
7209
|
+
function matchHasDefensiveContext(content, match) {
|
|
7210
|
+
if (!match || !match[0])
|
|
7211
|
+
return false;
|
|
7212
|
+
const start = match.index ?? 0;
|
|
7213
|
+
const before = content.slice(Math.max(0, start - 120), start);
|
|
7214
|
+
const after = content.slice(start + match[0].length, start + match[0].length + 160);
|
|
7215
|
+
return STRONG_DEFENSIVE_CONTEXT_RE.test(match[0]) || NEGATED_DIRECTIVE_RE.test(before) || STRONG_DEFENSIVE_CONTEXT_RE.test(before) || STRONG_DEFENSIVE_CONTEXT_RE.test(after) || REPORTING_BEFORE_RE.test(before) || REPORTING_CONTEXT_RE.test(before) && REPORTING_AFTER_RE.test(after);
|
|
7216
|
+
}
|
|
7217
|
+
function hasActionableMatch(content, patterns) {
|
|
7218
|
+
return patterns.some((pattern) => {
|
|
7219
|
+
const flags = pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`;
|
|
7220
|
+
const searchable = new RegExp(pattern.source, flags);
|
|
7221
|
+
let match;
|
|
7222
|
+
while ((match = searchable.exec(content)) !== null) {
|
|
7223
|
+
if (!matchHasDefensiveContext(content, match))
|
|
7224
|
+
return true;
|
|
7225
|
+
if (match[0].length === 0)
|
|
7226
|
+
searchable.lastIndex += 1;
|
|
7227
|
+
}
|
|
7228
|
+
return false;
|
|
7229
|
+
});
|
|
7230
|
+
}
|
|
7231
|
+
function hasDangerousShell(content) {
|
|
7232
|
+
const searchable = new RegExp(DANGEROUS_SHELL_RE.source, `${DANGEROUS_SHELL_RE.flags}g`);
|
|
7233
|
+
let match;
|
|
7234
|
+
while ((match = searchable.exec(content)) !== null) {
|
|
7235
|
+
if (matchHasDefensiveContext(content, match))
|
|
7236
|
+
continue;
|
|
7237
|
+
const end = (match.index ?? 0) + match[0].length;
|
|
7238
|
+
const after = content.slice(end, end + 160);
|
|
7239
|
+
if (!STRONG_DEFENSIVE_CONTEXT_RE.test(after) && !REPORTING_AFTER_RE.test(after))
|
|
7240
|
+
return true;
|
|
7241
|
+
if (match[0].length === 0)
|
|
7242
|
+
searchable.lastIndex += 1;
|
|
7243
|
+
}
|
|
7244
|
+
return false;
|
|
7245
|
+
}
|
|
7246
|
+
function scanMemoryContent(content) {
|
|
7247
|
+
const raw = typeof content === "string" ? content : String(content ?? "");
|
|
7248
|
+
const normalized = raw.normalize("NFKC");
|
|
7249
|
+
const reasons = new Set;
|
|
7250
|
+
if (INVISIBLE_UNICODE_RE.test(raw))
|
|
7251
|
+
reasons.add("invisible_unicode");
|
|
7252
|
+
if (hasActionableMatch(normalized, PROMPT_INJECTION_RES))
|
|
7253
|
+
reasons.add("prompt_injection");
|
|
7254
|
+
if (hasActionableMatch(normalized, TOOL_DIRECTIVE_RES))
|
|
7255
|
+
reasons.add("tool_directive");
|
|
7256
|
+
if (hasActionableMatch(normalized, [EXFILTRATION_RE, EXFILTRATION_REVERSE]))
|
|
7257
|
+
reasons.add("exfiltration");
|
|
7258
|
+
if (hasActionableMatch(normalized, [CREDENTIAL_HARVESTING_RE]))
|
|
7259
|
+
reasons.add("credential_harvesting");
|
|
7260
|
+
if (hasDangerousShell(normalized))
|
|
7261
|
+
reasons.add("malicious_shell");
|
|
7262
|
+
const orderedReasons = MEMORY_CONTENT_SAFETY_REASONS.filter((reason) => reasons.has(reason));
|
|
7263
|
+
const status = orderedReasons.length === 0 ? "clean" : orderedReasons.every((reason) => reason === "invisible_unicode") ? "tainted" : "blocked";
|
|
7264
|
+
return {
|
|
7265
|
+
status,
|
|
7266
|
+
contextEligible: status === "clean",
|
|
7267
|
+
reasons: orderedReasons,
|
|
7268
|
+
policyVersion: MEMORY_CONTENT_SAFETY_POLICY_VERSION
|
|
7269
|
+
};
|
|
7270
|
+
}
|
|
7178
7271
|
var DAEMON_DERIVED_MEMORY_SOURCE_TYPES = ["extract", "aggregate-recall", "session_end", "checkpoint", "dreaming"];
|
|
7179
7272
|
var MEMORIES_FTS_TOKENIZER = "unicode61";
|
|
7180
7273
|
function normalizeSql(sql) {
|
|
@@ -11153,6 +11246,95 @@ function up124(db) {
|
|
|
11153
11246
|
ON imported_source_lifecycle(agent_id, status, updated_at DESC);
|
|
11154
11247
|
`);
|
|
11155
11248
|
}
|
|
11249
|
+
function tableExists2(db, table) {
|
|
11250
|
+
return db.prepare("SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
|
|
11251
|
+
}
|
|
11252
|
+
function hasColumn24(db, table, column) {
|
|
11253
|
+
return db.prepare(`PRAGMA table_info("${table}")`).all().some((row) => row.name === column);
|
|
11254
|
+
}
|
|
11255
|
+
function backfill(db, rows, sourceKind, scannedAt) {
|
|
11256
|
+
const statement = db.prepare(`INSERT INTO memory_content_safety
|
|
11257
|
+
(agent_id, source_kind, source_id, status, context_eligible, reasons_json, policy_version, scanned_at)
|
|
11258
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
11259
|
+
ON CONFLICT(agent_id, source_kind, source_id) DO UPDATE SET
|
|
11260
|
+
status = excluded.status,
|
|
11261
|
+
context_eligible = excluded.context_eligible,
|
|
11262
|
+
reasons_json = excluded.reasons_json,
|
|
11263
|
+
policy_version = excluded.policy_version,
|
|
11264
|
+
scanned_at = excluded.scanned_at`);
|
|
11265
|
+
for (const row of rows) {
|
|
11266
|
+
const sourceId = row.source_id?.trim();
|
|
11267
|
+
if (!sourceId)
|
|
11268
|
+
continue;
|
|
11269
|
+
const assessment = scanMemoryContent(row.content ?? "");
|
|
11270
|
+
statement.run(row.agent_id?.trim() || "default", sourceKind, sourceId, assessment.status, assessment.contextEligible ? 1 : 0, JSON.stringify(assessment.reasons), MEMORY_CONTENT_SAFETY_POLICY_VERSION, scannedAt);
|
|
11271
|
+
}
|
|
11272
|
+
}
|
|
11273
|
+
function backfillTable(db, params) {
|
|
11274
|
+
if (!tableExists2(db, params.table) || !hasColumn24(db, params.table, params.sourceIdColumn) || !hasColumn24(db, params.table, params.contentColumn))
|
|
11275
|
+
return;
|
|
11276
|
+
const agentColumn = hasColumn24(db, params.table, "agent_id") ? "COALESCE(NULLIF(TRIM(agent_id), ''), 'default')" : "'default'";
|
|
11277
|
+
const rows = db.prepare(`SELECT ${agentColumn} AS agent_id, ${params.sourceIdColumn} AS source_id, ${params.contentColumn} AS content
|
|
11278
|
+
FROM ${params.table}${params.where ? ` WHERE ${params.where}` : ""}`).all();
|
|
11279
|
+
backfill(db, rows, params.sourceKind, params.scannedAt);
|
|
11280
|
+
}
|
|
11281
|
+
function up125(db) {
|
|
11282
|
+
db.exec(`
|
|
11283
|
+
CREATE TABLE IF NOT EXISTS memory_content_safety (
|
|
11284
|
+
agent_id TEXT NOT NULL,
|
|
11285
|
+
source_kind TEXT NOT NULL CHECK (source_kind IN ('memory', 'artifact', 'transcript', 'summary', 'source_chunk')),
|
|
11286
|
+
source_id TEXT NOT NULL,
|
|
11287
|
+
status TEXT NOT NULL CHECK (status IN ('clean', 'tainted', 'blocked')),
|
|
11288
|
+
context_eligible INTEGER NOT NULL CHECK (context_eligible IN (0, 1)),
|
|
11289
|
+
reasons_json TEXT NOT NULL DEFAULT '[]',
|
|
11290
|
+
policy_version TEXT NOT NULL,
|
|
11291
|
+
scanned_at TEXT NOT NULL,
|
|
11292
|
+
PRIMARY KEY (agent_id, source_kind, source_id)
|
|
11293
|
+
);
|
|
11294
|
+
|
|
11295
|
+
CREATE INDEX IF NOT EXISTS idx_memory_content_safety_status
|
|
11296
|
+
ON memory_content_safety(agent_id, status, source_kind);
|
|
11297
|
+
CREATE INDEX IF NOT EXISTS idx_memory_content_safety_eligibility
|
|
11298
|
+
ON memory_content_safety(agent_id, source_kind, context_eligible);
|
|
11299
|
+
`);
|
|
11300
|
+
const scannedAt = new Date().toISOString();
|
|
11301
|
+
backfillTable(db, {
|
|
11302
|
+
table: "memories",
|
|
11303
|
+
sourceKind: "memory",
|
|
11304
|
+
sourceIdColumn: "id",
|
|
11305
|
+
contentColumn: "content",
|
|
11306
|
+
scannedAt
|
|
11307
|
+
});
|
|
11308
|
+
backfillTable(db, {
|
|
11309
|
+
table: "memory_artifacts",
|
|
11310
|
+
sourceKind: "artifact",
|
|
11311
|
+
sourceIdColumn: "source_path",
|
|
11312
|
+
contentColumn: "content",
|
|
11313
|
+
scannedAt
|
|
11314
|
+
});
|
|
11315
|
+
backfillTable(db, {
|
|
11316
|
+
table: "session_transcripts",
|
|
11317
|
+
sourceKind: "transcript",
|
|
11318
|
+
sourceIdColumn: "session_key",
|
|
11319
|
+
contentColumn: "content",
|
|
11320
|
+
scannedAt
|
|
11321
|
+
});
|
|
11322
|
+
backfillTable(db, {
|
|
11323
|
+
table: "session_summaries",
|
|
11324
|
+
sourceKind: "summary",
|
|
11325
|
+
sourceIdColumn: "id",
|
|
11326
|
+
contentColumn: "content",
|
|
11327
|
+
scannedAt
|
|
11328
|
+
});
|
|
11329
|
+
backfillTable(db, {
|
|
11330
|
+
table: "embeddings",
|
|
11331
|
+
sourceKind: "source_chunk",
|
|
11332
|
+
sourceIdColumn: "id",
|
|
11333
|
+
contentColumn: "chunk_text",
|
|
11334
|
+
where: "source_type IN ('source_chunk', 'source_obsidian_chunk')",
|
|
11335
|
+
scannedAt
|
|
11336
|
+
});
|
|
11337
|
+
}
|
|
11156
11338
|
var MIGRATIONS = [
|
|
11157
11339
|
{
|
|
11158
11340
|
version: 1,
|
|
@@ -12161,6 +12343,12 @@ var MIGRATIONS = [
|
|
|
12161
12343
|
artifacts: {
|
|
12162
12344
|
tables: ["imported_source_lifecycle"]
|
|
12163
12345
|
}
|
|
12346
|
+
},
|
|
12347
|
+
{
|
|
12348
|
+
version: 125,
|
|
12349
|
+
name: "memory-content-safety",
|
|
12350
|
+
up: up125,
|
|
12351
|
+
artifacts: { tables: ["memory_content_safety"] }
|
|
12164
12352
|
}
|
|
12165
12353
|
];
|
|
12166
12354
|
var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
|