@signetai/signet-memory-openclaw 0.193.1 → 0.193.3
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.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +372 -26
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,11 @@ export interface SessionStartResult {
|
|
|
27
27
|
created_at: string;
|
|
28
28
|
}>;
|
|
29
29
|
recentContext?: string;
|
|
30
|
+
stableSystemPrompt?: string;
|
|
31
|
+
dynamicContext?: string;
|
|
30
32
|
inject: string;
|
|
33
|
+
contextHash?: string;
|
|
34
|
+
contextVersion?: number;
|
|
31
35
|
}
|
|
32
36
|
export interface PreCompactionResult {
|
|
33
37
|
summaryPrompt: string;
|
|
@@ -35,6 +39,9 @@ export interface PreCompactionResult {
|
|
|
35
39
|
}
|
|
36
40
|
export interface UserPromptSubmitResult {
|
|
37
41
|
inject: string;
|
|
42
|
+
dynamicContext?: string;
|
|
43
|
+
contextHash?: string;
|
|
44
|
+
contextVersion?: number;
|
|
38
45
|
memoryCount: number;
|
|
39
46
|
queryTerms?: string;
|
|
40
47
|
engine?: string;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiBH,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAG7D,OAAO,KAAK,EACX,iBAAiB,EAQjB,MAAM,qBAAqB,CAAC;AAmH7B,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAA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hB,CAAC;AAEX,eAAe,YAAY,CAAC"}
|
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;
|
|
@@ -12177,6 +12365,121 @@ function parseSimpleYaml(text) {
|
|
|
12177
12365
|
return {};
|
|
12178
12366
|
}
|
|
12179
12367
|
}
|
|
12368
|
+
var INTERNAL_FENCE_NAMES = ["signet-memory-context", "signet-memory", "memory-context"];
|
|
12369
|
+
function isFenceWhitespace(character) {
|
|
12370
|
+
return character === " " || character === "\t" || character === "\r" || character === `
|
|
12371
|
+
`;
|
|
12372
|
+
}
|
|
12373
|
+
function readFenceName(text, start) {
|
|
12374
|
+
for (const name of INTERNAL_FENCE_NAMES) {
|
|
12375
|
+
if (text.slice(start, start + name.length).toLowerCase() === name)
|
|
12376
|
+
return name;
|
|
12377
|
+
}
|
|
12378
|
+
return;
|
|
12379
|
+
}
|
|
12380
|
+
function parseFenceAt(text, index) {
|
|
12381
|
+
if (text[index] !== "<")
|
|
12382
|
+
return;
|
|
12383
|
+
let cursor = index + 1;
|
|
12384
|
+
if (text[cursor] === "\\")
|
|
12385
|
+
cursor += 1;
|
|
12386
|
+
while (isFenceWhitespace(text[cursor]))
|
|
12387
|
+
cursor += 1;
|
|
12388
|
+
const isClose = text[cursor] === "/";
|
|
12389
|
+
if (isClose)
|
|
12390
|
+
cursor += 1;
|
|
12391
|
+
while (isFenceWhitespace(text[cursor]))
|
|
12392
|
+
cursor += 1;
|
|
12393
|
+
const name = readFenceName(text, cursor);
|
|
12394
|
+
if (!name)
|
|
12395
|
+
return;
|
|
12396
|
+
const afterName = cursor + name.length;
|
|
12397
|
+
const boundary = text[afterName];
|
|
12398
|
+
if (!isClose && !isFenceWhitespace(boundary) && boundary !== "/" && boundary !== ">")
|
|
12399
|
+
return;
|
|
12400
|
+
cursor = afterName;
|
|
12401
|
+
if (isClose) {
|
|
12402
|
+
while (isFenceWhitespace(text[cursor]))
|
|
12403
|
+
cursor += 1;
|
|
12404
|
+
if (text[cursor] === ">")
|
|
12405
|
+
return { kind: "close", end: cursor + 1 };
|
|
12406
|
+
return cursor >= text.length ? { incomplete: true } : undefined;
|
|
12407
|
+
}
|
|
12408
|
+
let quote;
|
|
12409
|
+
while (cursor < text.length) {
|
|
12410
|
+
const character = text[cursor];
|
|
12411
|
+
if (quote) {
|
|
12412
|
+
if (character === quote)
|
|
12413
|
+
quote = undefined;
|
|
12414
|
+
} else if (character === '"' || character === "'") {
|
|
12415
|
+
quote = character;
|
|
12416
|
+
} else if (character === ">") {
|
|
12417
|
+
return { kind: "open", end: cursor + 1 };
|
|
12418
|
+
}
|
|
12419
|
+
cursor += 1;
|
|
12420
|
+
}
|
|
12421
|
+
return { incomplete: true };
|
|
12422
|
+
}
|
|
12423
|
+
function findNextFence(text, startIndex = 0) {
|
|
12424
|
+
for (let index = startIndex;index < text.length; index += 1) {
|
|
12425
|
+
if (text[index] !== "<")
|
|
12426
|
+
continue;
|
|
12427
|
+
const parsed = parseFenceAt(text, index);
|
|
12428
|
+
if (!parsed)
|
|
12429
|
+
continue;
|
|
12430
|
+
if ("incomplete" in parsed)
|
|
12431
|
+
return { kind: "open", match: { index, end: text.length } };
|
|
12432
|
+
return { kind: parsed.kind, match: { index, end: parsed.end } };
|
|
12433
|
+
}
|
|
12434
|
+
return;
|
|
12435
|
+
}
|
|
12436
|
+
function stripInternalMemoryContext(text) {
|
|
12437
|
+
let remaining = text;
|
|
12438
|
+
let output = "";
|
|
12439
|
+
while (remaining.length > 0) {
|
|
12440
|
+
const next = findNextFence(remaining);
|
|
12441
|
+
if (!next)
|
|
12442
|
+
return output + remaining;
|
|
12443
|
+
output += remaining.slice(0, next.match.index);
|
|
12444
|
+
remaining = remaining.slice(next.match.end);
|
|
12445
|
+
if (next.kind === "close")
|
|
12446
|
+
continue;
|
|
12447
|
+
let depth = 1;
|
|
12448
|
+
while (depth > 0) {
|
|
12449
|
+
const nested = findNextFence(remaining);
|
|
12450
|
+
if (!nested)
|
|
12451
|
+
return output;
|
|
12452
|
+
remaining = remaining.slice(nested.match.end);
|
|
12453
|
+
if (nested.kind === "open") {
|
|
12454
|
+
depth += 1;
|
|
12455
|
+
} else {
|
|
12456
|
+
depth -= 1;
|
|
12457
|
+
}
|
|
12458
|
+
}
|
|
12459
|
+
}
|
|
12460
|
+
return output;
|
|
12461
|
+
}
|
|
12462
|
+
function escapeMemoryContextForFence(text) {
|
|
12463
|
+
let output = "";
|
|
12464
|
+
let cursor = 0;
|
|
12465
|
+
let next = findNextFence(text);
|
|
12466
|
+
while (next) {
|
|
12467
|
+
output += text.slice(cursor, next.match.index);
|
|
12468
|
+
output += `<${text.slice(next.match.index + 1, next.match.end)}`;
|
|
12469
|
+
cursor = next.match.end;
|
|
12470
|
+
next = findNextFence(text, cursor);
|
|
12471
|
+
}
|
|
12472
|
+
return output + text.slice(cursor);
|
|
12473
|
+
}
|
|
12474
|
+
function wrapMemoryContext(context, source = "api-context") {
|
|
12475
|
+
const clean = escapeMemoryContextForFence(context).trim();
|
|
12476
|
+
if (!clean)
|
|
12477
|
+
return "";
|
|
12478
|
+
const safeSource = source.replace(/[^a-zA-Z0-9._-]/g, "-").slice(0, 40) || "api-context";
|
|
12479
|
+
return `<signet-memory source="${safeSource}">
|
|
12480
|
+
${clean}
|
|
12481
|
+
</signet-memory>`;
|
|
12482
|
+
}
|
|
12180
12483
|
var native = null;
|
|
12181
12484
|
try {
|
|
12182
12485
|
const esmRequire = createRequire22(import.meta.url);
|
|
@@ -15968,21 +16271,11 @@ var METADATA_LINE_PREFIXES = [
|
|
|
15968
16271
|
"Untrusted context",
|
|
15969
16272
|
"END_EXTERNAL_UNTRUSTED_CONTENT"
|
|
15970
16273
|
];
|
|
15971
|
-
var SIGNET_MEMORY_CLOSE = "</signet-memory>";
|
|
15972
16274
|
function stripSignetMemory(content) {
|
|
15973
|
-
|
|
15974
|
-
|
|
15975
|
-
|
|
15976
|
-
|
|
15977
|
-
if (start === -1)
|
|
15978
|
-
return clean(text);
|
|
15979
|
-
const closeOffset = text.slice(start).search(/<\/signet-memory>/i);
|
|
15980
|
-
if (closeOffset === -1)
|
|
15981
|
-
return clean(text.slice(0, start));
|
|
15982
|
-
const end = start + closeOffset;
|
|
15983
|
-
const stop = end + SIGNET_MEMORY_CLOSE.length;
|
|
15984
|
-
text = text.slice(0, start) + text.slice(stop);
|
|
15985
|
-
}
|
|
16275
|
+
return stripInternalMemoryContext(content).trim();
|
|
16276
|
+
}
|
|
16277
|
+
function readContextString(value) {
|
|
16278
|
+
return typeof value === "string" ? value.trim() : "";
|
|
15986
16279
|
}
|
|
15987
16280
|
function looksLikeMetadataJson(content) {
|
|
15988
16281
|
if (!content.includes("```json"))
|
|
@@ -16667,15 +16960,15 @@ function installSdkSanitizer() {
|
|
|
16667
16960
|
};
|
|
16668
16961
|
}
|
|
16669
16962
|
function buildInjectionResult(result) {
|
|
16670
|
-
|
|
16963
|
+
const dynamicContext = readContextString(result.dynamicContext) || readContextString(result.inject);
|
|
16964
|
+
if (!dynamicContext) {
|
|
16671
16965
|
return;
|
|
16672
16966
|
}
|
|
16673
16967
|
const queryAttr = result.queryTerms ? ` query="${result.queryTerms.replace(/"/g, "'").slice(0, 100)}"` : "";
|
|
16674
16968
|
const attrs = `source="auto-recall"${queryAttr} results="${result.memoryCount}" engine="${result.engine ?? "fts+decay"}"`;
|
|
16969
|
+
const context = wrapMemoryContext(dynamicContext, "auto-recall").replace('<signet-memory source="auto-recall">', `<signet-memory ${attrs}>`);
|
|
16675
16970
|
return {
|
|
16676
|
-
prependContext:
|
|
16677
|
-
${result.inject}
|
|
16678
|
-
</signet-memory>`
|
|
16971
|
+
prependContext: context
|
|
16679
16972
|
};
|
|
16680
16973
|
}
|
|
16681
16974
|
function buildSessionlessTurnKey(event, agentId) {
|
|
@@ -17237,6 +17530,8 @@ ${lines.join(`
|
|
|
17237
17530
|
if (mode === "tool-discovery")
|
|
17238
17531
|
return;
|
|
17239
17532
|
const claimedSessions = new Set;
|
|
17533
|
+
const sessionStartContexts = new Map;
|
|
17534
|
+
const sessionlessSessionStartContexts = new Map;
|
|
17240
17535
|
const sessionlessSessionStarts = new Map;
|
|
17241
17536
|
const SESSION_TURN_TTL_MS = 4 * 60 * 60 * 1000;
|
|
17242
17537
|
const injectedTurns = new Map;
|
|
@@ -17256,6 +17551,9 @@ ${lines.join(`
|
|
|
17256
17551
|
const state = checkpointTurns.get(scopedKey);
|
|
17257
17552
|
if (state && now - state.at > SESSION_TURN_TTL_MS) {
|
|
17258
17553
|
checkpointTurns.delete(scopedKey);
|
|
17554
|
+
} else {
|
|
17555
|
+
sessionlessSessionStartContexts.clear();
|
|
17556
|
+
sessionlessSessionStarts.clear();
|
|
17259
17557
|
}
|
|
17260
17558
|
if (msgCount !== undefined && checkpointTurns.get(scopedKey)?.lastMsgCount === msgCount)
|
|
17261
17559
|
return;
|
|
@@ -17343,6 +17641,11 @@ ${lines.join(`
|
|
|
17343
17641
|
const scopedKey = buildScopedSessionKey(resolved.sessionKey, resolved.agentId);
|
|
17344
17642
|
if (scopedKey) {
|
|
17345
17643
|
injectedTurns.delete(scopedKey);
|
|
17644
|
+
const sessionStartContext = sessionStartContexts.get(scopedKey);
|
|
17645
|
+
if (sessionStartContext) {
|
|
17646
|
+
sessionStartContext.dynamicContext = "";
|
|
17647
|
+
sessionStartContext.delivered = false;
|
|
17648
|
+
}
|
|
17346
17649
|
checkpointTurns.delete(scopedKey);
|
|
17347
17650
|
}
|
|
17348
17651
|
const sessionFile = resolveCompactionSessionFile(event, resolved.sessionFile);
|
|
@@ -17370,39 +17673,70 @@ ${lines.join(`
|
|
|
17370
17673
|
if (!sessionKey) {
|
|
17371
17674
|
const now = Date.now();
|
|
17372
17675
|
cleanupTimedMap(sessionlessSessionStarts, now);
|
|
17676
|
+
for (const key of sessionlessSessionStartContexts.keys()) {
|
|
17677
|
+
if (!sessionlessSessionStarts.has(key))
|
|
17678
|
+
sessionlessSessionStartContexts.delete(key);
|
|
17679
|
+
}
|
|
17373
17680
|
const sessionlessKey = buildSessionlessTurnKey(event, agentId);
|
|
17374
17681
|
const recentStartAt = sessionlessSessionStarts.get(sessionlessKey);
|
|
17375
17682
|
if (typeof recentStartAt === "number" && now - recentStartAt <= SESSIONLESS_DEDUPE_MS) {
|
|
17376
|
-
return;
|
|
17683
|
+
return sessionlessSessionStartContexts.get(sessionlessKey);
|
|
17377
17684
|
}
|
|
17378
17685
|
const startResult2 = await onSessionStart("openclaw", {
|
|
17379
17686
|
...opts,
|
|
17380
17687
|
sessionKey,
|
|
17381
17688
|
agentId
|
|
17382
17689
|
});
|
|
17383
|
-
if (startResult2)
|
|
17384
|
-
|
|
17385
|
-
|
|
17386
|
-
|
|
17690
|
+
if (!startResult2)
|
|
17691
|
+
return;
|
|
17692
|
+
const context2 = {
|
|
17693
|
+
stableSystemPrompt: readContextString(startResult2.stableSystemPrompt),
|
|
17694
|
+
dynamicContext: readContextString(startResult2.dynamicContext) || readContextString(startResult2.inject),
|
|
17695
|
+
delivered: false
|
|
17696
|
+
};
|
|
17697
|
+
sessionlessSessionStarts.set(sessionlessKey, Date.now());
|
|
17698
|
+
sessionlessSessionStartContexts.set(sessionlessKey, context2);
|
|
17699
|
+
return context2;
|
|
17387
17700
|
}
|
|
17388
17701
|
const scopedKey = buildScopedSessionKey(sessionKey, agentId);
|
|
17389
17702
|
if (scopedKey && claimedSessions.has(scopedKey)) {
|
|
17390
|
-
return;
|
|
17703
|
+
return sessionStartContexts.get(scopedKey);
|
|
17391
17704
|
}
|
|
17392
17705
|
const startResult = await onSessionStart("openclaw", {
|
|
17393
17706
|
...opts,
|
|
17394
17707
|
sessionKey,
|
|
17395
17708
|
agentId
|
|
17396
17709
|
});
|
|
17397
|
-
if (startResult
|
|
17710
|
+
if (!startResult)
|
|
17711
|
+
return;
|
|
17712
|
+
const context = {
|
|
17713
|
+
stableSystemPrompt: readContextString(startResult.stableSystemPrompt),
|
|
17714
|
+
dynamicContext: readContextString(startResult.dynamicContext) || readContextString(startResult.inject),
|
|
17715
|
+
delivered: false
|
|
17716
|
+
};
|
|
17717
|
+
if (scopedKey) {
|
|
17398
17718
|
claimedSessions.add(scopedKey);
|
|
17719
|
+
sessionStartContexts.set(scopedKey, context);
|
|
17399
17720
|
}
|
|
17721
|
+
return context;
|
|
17400
17722
|
};
|
|
17401
17723
|
const runPromptInjection = async (event, sessionKey, agentId) => {
|
|
17402
17724
|
if (!daemonReachable)
|
|
17403
17725
|
return;
|
|
17404
17726
|
const scopedKey = buildScopedSessionKey(sessionKey, agentId);
|
|
17727
|
+
const sessionlessKey = scopedKey ? undefined : buildSessionlessTurnKey(event, agentId);
|
|
17405
17728
|
const pendingNotification = scopedKey ? pendingNotifications.get(scopedKey)?.inject : undefined;
|
|
17729
|
+
const takeSessionStartInjection = () => {
|
|
17730
|
+
const context = scopedKey ? sessionStartContexts.get(scopedKey) : sessionlessKey ? sessionlessSessionStartContexts.get(sessionlessKey) : undefined;
|
|
17731
|
+
if (!context || context.delivered)
|
|
17732
|
+
return;
|
|
17733
|
+
context.delivered = true;
|
|
17734
|
+
if (sessionlessKey)
|
|
17735
|
+
sessionlessSessionStartContexts.delete(sessionlessKey);
|
|
17736
|
+
return wrapMemoryContext([context.stableSystemPrompt, context.dynamicContext].filter((part) => part.length > 0).join(`
|
|
17737
|
+
|
|
17738
|
+
`), "session-start");
|
|
17739
|
+
};
|
|
17406
17740
|
const rawPrompt = typeof event.prompt === "string" ? event.prompt : undefined;
|
|
17407
17741
|
const prompt = extractLastUserMessage(event.messages) ?? (rawPrompt ? extractUserMessage(rawPrompt) : undefined);
|
|
17408
17742
|
if (!prompt || prompt.length <= 3) {
|
|
@@ -17451,7 +17785,12 @@ ${lines.join(`
|
|
|
17451
17785
|
if (scopedKey && typeof count === "number") {
|
|
17452
17786
|
injectedTurns.set(scopedKey, { count, at: Date.now() });
|
|
17453
17787
|
}
|
|
17454
|
-
|
|
17788
|
+
const sessionStartInjection = takeSessionStartInjection();
|
|
17789
|
+
const promptInjection = buildInjectionResult(result)?.prependContext;
|
|
17790
|
+
const parts = [sessionStartInjection, promptInjection].filter((value) => Boolean(value));
|
|
17791
|
+
return parts.length > 0 ? { prependContext: parts.join(`
|
|
17792
|
+
|
|
17793
|
+
`) } : undefined;
|
|
17455
17794
|
};
|
|
17456
17795
|
api.on("before_prompt_build", async (event, ctx) => {
|
|
17457
17796
|
if (!cfg.enabled)
|
|
@@ -17530,6 +17869,7 @@ ${lines.join(`
|
|
|
17530
17869
|
});
|
|
17531
17870
|
if (scopedKey) {
|
|
17532
17871
|
claimedSessions.delete(scopedKey);
|
|
17872
|
+
sessionStartContexts.delete(scopedKey);
|
|
17533
17873
|
injectedTurns.delete(scopedKey);
|
|
17534
17874
|
pendingNotifications.delete(scopedKey);
|
|
17535
17875
|
checkpointTurns.delete(scopedKey);
|
|
@@ -17568,6 +17908,12 @@ ${lines.join(`
|
|
|
17568
17908
|
if (ok && knownPid !== null && pid !== knownPid) {
|
|
17569
17909
|
api.logger.info(`signet-memory: daemon restarted (pid ${knownPid} -> ${pid}), re-initializing sessions`);
|
|
17570
17910
|
claimedSessions.clear();
|
|
17911
|
+
sessionStartContexts.clear();
|
|
17912
|
+
sessionlessSessionStartContexts.clear();
|
|
17913
|
+
injectedTurns.clear();
|
|
17914
|
+
inFlightTurns.clear();
|
|
17915
|
+
pendingNotifications.clear();
|
|
17916
|
+
sessionlessSessionStarts.clear();
|
|
17571
17917
|
}
|
|
17572
17918
|
knownPid = pid;
|
|
17573
17919
|
}, HEARTBEAT_INTERVAL_MS);
|