@signetai/signet-memory-openclaw 0.193.2 → 0.194.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/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +184 -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
|
@@ -12365,6 +12365,121 @@ function parseSimpleYaml(text) {
|
|
|
12365
12365
|
return {};
|
|
12366
12366
|
}
|
|
12367
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
|
+
}
|
|
12368
12483
|
var native = null;
|
|
12369
12484
|
try {
|
|
12370
12485
|
const esmRequire = createRequire22(import.meta.url);
|
|
@@ -16156,21 +16271,11 @@ var METADATA_LINE_PREFIXES = [
|
|
|
16156
16271
|
"Untrusted context",
|
|
16157
16272
|
"END_EXTERNAL_UNTRUSTED_CONTENT"
|
|
16158
16273
|
];
|
|
16159
|
-
var SIGNET_MEMORY_CLOSE = "</signet-memory>";
|
|
16160
16274
|
function stripSignetMemory(content) {
|
|
16161
|
-
|
|
16162
|
-
|
|
16163
|
-
|
|
16164
|
-
|
|
16165
|
-
if (start === -1)
|
|
16166
|
-
return clean(text);
|
|
16167
|
-
const closeOffset = text.slice(start).search(/<\/signet-memory>/i);
|
|
16168
|
-
if (closeOffset === -1)
|
|
16169
|
-
return clean(text.slice(0, start));
|
|
16170
|
-
const end = start + closeOffset;
|
|
16171
|
-
const stop = end + SIGNET_MEMORY_CLOSE.length;
|
|
16172
|
-
text = text.slice(0, start) + text.slice(stop);
|
|
16173
|
-
}
|
|
16275
|
+
return stripInternalMemoryContext(content).trim();
|
|
16276
|
+
}
|
|
16277
|
+
function readContextString(value) {
|
|
16278
|
+
return typeof value === "string" ? value.trim() : "";
|
|
16174
16279
|
}
|
|
16175
16280
|
function looksLikeMetadataJson(content) {
|
|
16176
16281
|
if (!content.includes("```json"))
|
|
@@ -16855,15 +16960,15 @@ function installSdkSanitizer() {
|
|
|
16855
16960
|
};
|
|
16856
16961
|
}
|
|
16857
16962
|
function buildInjectionResult(result) {
|
|
16858
|
-
|
|
16963
|
+
const dynamicContext = readContextString(result.dynamicContext) || readContextString(result.inject);
|
|
16964
|
+
if (!dynamicContext) {
|
|
16859
16965
|
return;
|
|
16860
16966
|
}
|
|
16861
16967
|
const queryAttr = result.queryTerms ? ` query="${result.queryTerms.replace(/"/g, "'").slice(0, 100)}"` : "";
|
|
16862
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}>`);
|
|
16863
16970
|
return {
|
|
16864
|
-
prependContext:
|
|
16865
|
-
${result.inject}
|
|
16866
|
-
</signet-memory>`
|
|
16971
|
+
prependContext: context
|
|
16867
16972
|
};
|
|
16868
16973
|
}
|
|
16869
16974
|
function buildSessionlessTurnKey(event, agentId) {
|
|
@@ -17425,6 +17530,8 @@ ${lines.join(`
|
|
|
17425
17530
|
if (mode === "tool-discovery")
|
|
17426
17531
|
return;
|
|
17427
17532
|
const claimedSessions = new Set;
|
|
17533
|
+
const sessionStartContexts = new Map;
|
|
17534
|
+
const sessionlessSessionStartContexts = new Map;
|
|
17428
17535
|
const sessionlessSessionStarts = new Map;
|
|
17429
17536
|
const SESSION_TURN_TTL_MS = 4 * 60 * 60 * 1000;
|
|
17430
17537
|
const injectedTurns = new Map;
|
|
@@ -17444,6 +17551,9 @@ ${lines.join(`
|
|
|
17444
17551
|
const state = checkpointTurns.get(scopedKey);
|
|
17445
17552
|
if (state && now - state.at > SESSION_TURN_TTL_MS) {
|
|
17446
17553
|
checkpointTurns.delete(scopedKey);
|
|
17554
|
+
} else {
|
|
17555
|
+
sessionlessSessionStartContexts.clear();
|
|
17556
|
+
sessionlessSessionStarts.clear();
|
|
17447
17557
|
}
|
|
17448
17558
|
if (msgCount !== undefined && checkpointTurns.get(scopedKey)?.lastMsgCount === msgCount)
|
|
17449
17559
|
return;
|
|
@@ -17531,6 +17641,11 @@ ${lines.join(`
|
|
|
17531
17641
|
const scopedKey = buildScopedSessionKey(resolved.sessionKey, resolved.agentId);
|
|
17532
17642
|
if (scopedKey) {
|
|
17533
17643
|
injectedTurns.delete(scopedKey);
|
|
17644
|
+
const sessionStartContext = sessionStartContexts.get(scopedKey);
|
|
17645
|
+
if (sessionStartContext) {
|
|
17646
|
+
sessionStartContext.dynamicContext = "";
|
|
17647
|
+
sessionStartContext.delivered = false;
|
|
17648
|
+
}
|
|
17534
17649
|
checkpointTurns.delete(scopedKey);
|
|
17535
17650
|
}
|
|
17536
17651
|
const sessionFile = resolveCompactionSessionFile(event, resolved.sessionFile);
|
|
@@ -17558,39 +17673,70 @@ ${lines.join(`
|
|
|
17558
17673
|
if (!sessionKey) {
|
|
17559
17674
|
const now = Date.now();
|
|
17560
17675
|
cleanupTimedMap(sessionlessSessionStarts, now);
|
|
17676
|
+
for (const key of sessionlessSessionStartContexts.keys()) {
|
|
17677
|
+
if (!sessionlessSessionStarts.has(key))
|
|
17678
|
+
sessionlessSessionStartContexts.delete(key);
|
|
17679
|
+
}
|
|
17561
17680
|
const sessionlessKey = buildSessionlessTurnKey(event, agentId);
|
|
17562
17681
|
const recentStartAt = sessionlessSessionStarts.get(sessionlessKey);
|
|
17563
17682
|
if (typeof recentStartAt === "number" && now - recentStartAt <= SESSIONLESS_DEDUPE_MS) {
|
|
17564
|
-
return;
|
|
17683
|
+
return sessionlessSessionStartContexts.get(sessionlessKey);
|
|
17565
17684
|
}
|
|
17566
17685
|
const startResult2 = await onSessionStart("openclaw", {
|
|
17567
17686
|
...opts,
|
|
17568
17687
|
sessionKey,
|
|
17569
17688
|
agentId
|
|
17570
17689
|
});
|
|
17571
|
-
if (startResult2)
|
|
17572
|
-
|
|
17573
|
-
|
|
17574
|
-
|
|
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;
|
|
17575
17700
|
}
|
|
17576
17701
|
const scopedKey = buildScopedSessionKey(sessionKey, agentId);
|
|
17577
17702
|
if (scopedKey && claimedSessions.has(scopedKey)) {
|
|
17578
|
-
return;
|
|
17703
|
+
return sessionStartContexts.get(scopedKey);
|
|
17579
17704
|
}
|
|
17580
17705
|
const startResult = await onSessionStart("openclaw", {
|
|
17581
17706
|
...opts,
|
|
17582
17707
|
sessionKey,
|
|
17583
17708
|
agentId
|
|
17584
17709
|
});
|
|
17585
|
-
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) {
|
|
17586
17718
|
claimedSessions.add(scopedKey);
|
|
17719
|
+
sessionStartContexts.set(scopedKey, context);
|
|
17587
17720
|
}
|
|
17721
|
+
return context;
|
|
17588
17722
|
};
|
|
17589
17723
|
const runPromptInjection = async (event, sessionKey, agentId) => {
|
|
17590
17724
|
if (!daemonReachable)
|
|
17591
17725
|
return;
|
|
17592
17726
|
const scopedKey = buildScopedSessionKey(sessionKey, agentId);
|
|
17727
|
+
const sessionlessKey = scopedKey ? undefined : buildSessionlessTurnKey(event, agentId);
|
|
17593
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
|
+
};
|
|
17594
17740
|
const rawPrompt = typeof event.prompt === "string" ? event.prompt : undefined;
|
|
17595
17741
|
const prompt = extractLastUserMessage(event.messages) ?? (rawPrompt ? extractUserMessage(rawPrompt) : undefined);
|
|
17596
17742
|
if (!prompt || prompt.length <= 3) {
|
|
@@ -17639,7 +17785,12 @@ ${lines.join(`
|
|
|
17639
17785
|
if (scopedKey && typeof count === "number") {
|
|
17640
17786
|
injectedTurns.set(scopedKey, { count, at: Date.now() });
|
|
17641
17787
|
}
|
|
17642
|
-
|
|
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;
|
|
17643
17794
|
};
|
|
17644
17795
|
api.on("before_prompt_build", async (event, ctx) => {
|
|
17645
17796
|
if (!cfg.enabled)
|
|
@@ -17718,6 +17869,7 @@ ${lines.join(`
|
|
|
17718
17869
|
});
|
|
17719
17870
|
if (scopedKey) {
|
|
17720
17871
|
claimedSessions.delete(scopedKey);
|
|
17872
|
+
sessionStartContexts.delete(scopedKey);
|
|
17721
17873
|
injectedTurns.delete(scopedKey);
|
|
17722
17874
|
pendingNotifications.delete(scopedKey);
|
|
17723
17875
|
checkpointTurns.delete(scopedKey);
|
|
@@ -17756,6 +17908,12 @@ ${lines.join(`
|
|
|
17756
17908
|
if (ok && knownPid !== null && pid !== knownPid) {
|
|
17757
17909
|
api.logger.info(`signet-memory: daemon restarted (pid ${knownPid} -> ${pid}), re-initializing sessions`);
|
|
17758
17910
|
claimedSessions.clear();
|
|
17911
|
+
sessionStartContexts.clear();
|
|
17912
|
+
sessionlessSessionStartContexts.clear();
|
|
17913
|
+
injectedTurns.clear();
|
|
17914
|
+
inFlightTurns.clear();
|
|
17915
|
+
pendingNotifications.clear();
|
|
17916
|
+
sessionlessSessionStarts.clear();
|
|
17759
17917
|
}
|
|
17760
17918
|
knownPid = pid;
|
|
17761
17919
|
}, HEARTBEAT_INTERVAL_MS);
|