@signetai/signet-memory-openclaw 0.77.4 → 0.77.5
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 +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +508 -16
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -109,10 +109,13 @@ export declare function onPreCompaction(harness: string, options?: {
|
|
|
109
109
|
}): Promise<PreCompactionResult | null>;
|
|
110
110
|
export declare function onCompactionComplete(harness: string, summary: string, options?: {
|
|
111
111
|
daemonUrl?: string;
|
|
112
|
+
agentId?: string;
|
|
112
113
|
sessionKey?: string;
|
|
114
|
+
project?: string;
|
|
113
115
|
}): Promise<boolean>;
|
|
114
116
|
export declare function onSessionEnd(harness: string, options?: {
|
|
115
117
|
daemonUrl?: string;
|
|
118
|
+
agentId?: string;
|
|
116
119
|
transcriptPath?: string;
|
|
117
120
|
sessionKey?: string;
|
|
118
121
|
sessionId?: 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;AAOH,OAAO,KAAK,EAAE,iBAAiB,EAAsB,MAAM,qBAAqB,CAAC;AA8EjF,MAAM,WAAW,YAAY;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,QAAQ,EAAE,KAAK,CAAC;QACf,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;Q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all) => {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
// src/index.ts
|
|
17
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
17
18
|
import { homedir } from "node:os";
|
|
18
19
|
import { join as join3 } from "node:path";
|
|
19
20
|
|
|
@@ -8175,6 +8176,268 @@ function up43(db) {
|
|
|
8175
8176
|
ON memories(agent_id, visibility);
|
|
8176
8177
|
`);
|
|
8177
8178
|
}
|
|
8179
|
+
function addColumnIfMissing15(db, table, column, definition) {
|
|
8180
|
+
const cols = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
8181
|
+
if (cols.some((c) => c.name === column))
|
|
8182
|
+
return;
|
|
8183
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
8184
|
+
}
|
|
8185
|
+
function up44(db) {
|
|
8186
|
+
addColumnIfMissing15(db, "session_summaries", "source_type", "TEXT");
|
|
8187
|
+
addColumnIfMissing15(db, "session_summaries", "source_ref", "TEXT");
|
|
8188
|
+
addColumnIfMissing15(db, "session_summaries", "meta_json", "TEXT");
|
|
8189
|
+
db.exec(`
|
|
8190
|
+
UPDATE session_summaries
|
|
8191
|
+
SET source_type = CASE
|
|
8192
|
+
WHEN source_type IS NOT NULL THEN source_type
|
|
8193
|
+
WHEN kind = 'session' THEN 'summary'
|
|
8194
|
+
WHEN kind IN ('arc', 'epoch') THEN 'condensation'
|
|
8195
|
+
ELSE kind
|
|
8196
|
+
END
|
|
8197
|
+
WHERE source_type IS NULL;
|
|
8198
|
+
|
|
8199
|
+
CREATE INDEX IF NOT EXISTS idx_summaries_source_type
|
|
8200
|
+
ON session_summaries(source_type);
|
|
8201
|
+
CREATE INDEX IF NOT EXISTS idx_summaries_source_ref
|
|
8202
|
+
ON session_summaries(source_ref);
|
|
8203
|
+
`);
|
|
8204
|
+
}
|
|
8205
|
+
function addColumnIfMissing16(db, table, column, definition) {
|
|
8206
|
+
const cols = db.prepare(`PRAGMA table_info(${table})`).all();
|
|
8207
|
+
if (cols.some((col) => col.name === column))
|
|
8208
|
+
return;
|
|
8209
|
+
db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
|
|
8210
|
+
}
|
|
8211
|
+
function up45(db) {
|
|
8212
|
+
addColumnIfMissing16(db, "session_transcripts", "updated_at", "TEXT");
|
|
8213
|
+
addColumnIfMissing16(db, "summary_jobs", "agent_id", "TEXT NOT NULL DEFAULT 'default'");
|
|
8214
|
+
addColumnIfMissing16(db, "session_scores", "agent_id", "TEXT NOT NULL DEFAULT 'default'");
|
|
8215
|
+
db.exec(`
|
|
8216
|
+
UPDATE session_transcripts
|
|
8217
|
+
SET updated_at = COALESCE(updated_at, created_at)
|
|
8218
|
+
WHERE updated_at IS NULL;
|
|
8219
|
+
|
|
8220
|
+
UPDATE summary_jobs
|
|
8221
|
+
SET agent_id = COALESCE(agent_id, 'default')
|
|
8222
|
+
WHERE agent_id IS NULL;
|
|
8223
|
+
|
|
8224
|
+
UPDATE session_scores
|
|
8225
|
+
SET agent_id = COALESCE(agent_id, 'default')
|
|
8226
|
+
WHERE agent_id IS NULL;
|
|
8227
|
+
|
|
8228
|
+
CREATE INDEX IF NOT EXISTS idx_st_agent_updated
|
|
8229
|
+
ON session_transcripts(agent_id, updated_at);
|
|
8230
|
+
CREATE INDEX IF NOT EXISTS idx_summary_jobs_agent
|
|
8231
|
+
ON summary_jobs(agent_id, created_at);
|
|
8232
|
+
CREATE INDEX IF NOT EXISTS idx_session_scores_agent_session
|
|
8233
|
+
ON session_scores(agent_id, session_key, created_at);
|
|
8234
|
+
`);
|
|
8235
|
+
db.exec(`
|
|
8236
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS session_transcripts_fts USING fts5(
|
|
8237
|
+
content,
|
|
8238
|
+
content='session_transcripts',
|
|
8239
|
+
content_rowid='rowid'
|
|
8240
|
+
)
|
|
8241
|
+
`);
|
|
8242
|
+
db.exec(`
|
|
8243
|
+
CREATE TRIGGER IF NOT EXISTS session_transcripts_fts_ai AFTER INSERT ON session_transcripts BEGIN
|
|
8244
|
+
INSERT INTO session_transcripts_fts(rowid, content)
|
|
8245
|
+
VALUES (new.rowid, new.content);
|
|
8246
|
+
END
|
|
8247
|
+
`);
|
|
8248
|
+
db.exec(`
|
|
8249
|
+
CREATE TRIGGER IF NOT EXISTS session_transcripts_fts_ad AFTER DELETE ON session_transcripts BEGIN
|
|
8250
|
+
INSERT INTO session_transcripts_fts(session_transcripts_fts, rowid, content)
|
|
8251
|
+
VALUES ('delete', old.rowid, old.content);
|
|
8252
|
+
END
|
|
8253
|
+
`);
|
|
8254
|
+
db.exec(`
|
|
8255
|
+
CREATE TRIGGER IF NOT EXISTS session_transcripts_fts_au AFTER UPDATE ON session_transcripts BEGIN
|
|
8256
|
+
INSERT INTO session_transcripts_fts(session_transcripts_fts, rowid, content)
|
|
8257
|
+
VALUES ('delete', old.rowid, old.content);
|
|
8258
|
+
INSERT INTO session_transcripts_fts(rowid, content)
|
|
8259
|
+
VALUES (new.rowid, new.content);
|
|
8260
|
+
END
|
|
8261
|
+
`);
|
|
8262
|
+
db.exec(`
|
|
8263
|
+
INSERT INTO session_transcripts_fts(session_transcripts_fts)
|
|
8264
|
+
VALUES ('rebuild');
|
|
8265
|
+
`);
|
|
8266
|
+
db.exec(`
|
|
8267
|
+
CREATE TABLE IF NOT EXISTS memory_md_heads (
|
|
8268
|
+
agent_id TEXT PRIMARY KEY,
|
|
8269
|
+
content TEXT NOT NULL DEFAULT '',
|
|
8270
|
+
content_hash TEXT NOT NULL DEFAULT '',
|
|
8271
|
+
revision INTEGER NOT NULL DEFAULT 0,
|
|
8272
|
+
updated_at TEXT NOT NULL,
|
|
8273
|
+
lease_token TEXT,
|
|
8274
|
+
lease_owner TEXT,
|
|
8275
|
+
lease_expires_at TEXT
|
|
8276
|
+
);
|
|
8277
|
+
|
|
8278
|
+
CREATE INDEX IF NOT EXISTS idx_memory_md_heads_lease
|
|
8279
|
+
ON memory_md_heads(lease_expires_at);
|
|
8280
|
+
`);
|
|
8281
|
+
}
|
|
8282
|
+
function up46(db) {
|
|
8283
|
+
db.exec(`
|
|
8284
|
+
DROP INDEX IF EXISTS idx_summaries_session_depth;
|
|
8285
|
+
|
|
8286
|
+
CREATE TEMP TABLE IF NOT EXISTS session_summary_duplicate_map AS
|
|
8287
|
+
WITH ranked AS (
|
|
8288
|
+
SELECT
|
|
8289
|
+
id,
|
|
8290
|
+
agent_id,
|
|
8291
|
+
session_key,
|
|
8292
|
+
depth,
|
|
8293
|
+
ROW_NUMBER() OVER (
|
|
8294
|
+
PARTITION BY agent_id, session_key, depth
|
|
8295
|
+
ORDER BY latest_at DESC, created_at DESC, id ASC
|
|
8296
|
+
) AS rn
|
|
8297
|
+
FROM session_summaries
|
|
8298
|
+
WHERE session_key IS NOT NULL
|
|
8299
|
+
AND COALESCE(source_type, 'summary') = 'summary'
|
|
8300
|
+
)
|
|
8301
|
+
SELECT dup.id AS drop_id, keep.id AS keep_id
|
|
8302
|
+
FROM ranked dup
|
|
8303
|
+
JOIN ranked keep
|
|
8304
|
+
ON keep.agent_id = dup.agent_id
|
|
8305
|
+
AND keep.session_key = dup.session_key
|
|
8306
|
+
AND keep.depth = dup.depth
|
|
8307
|
+
AND keep.rn = 1
|
|
8308
|
+
WHERE dup.rn > 1;
|
|
8309
|
+
|
|
8310
|
+
INSERT OR IGNORE INTO session_summary_memories (summary_id, memory_id)
|
|
8311
|
+
SELECT map.keep_id, link.memory_id
|
|
8312
|
+
FROM session_summary_duplicate_map map
|
|
8313
|
+
JOIN session_summary_memories link ON link.summary_id = map.drop_id;
|
|
8314
|
+
|
|
8315
|
+
INSERT OR IGNORE INTO session_summary_children (parent_id, child_id, ordinal)
|
|
8316
|
+
SELECT
|
|
8317
|
+
COALESCE(parent_map.keep_id, rel.parent_id),
|
|
8318
|
+
COALESCE(child_map.keep_id, rel.child_id),
|
|
8319
|
+
rel.ordinal
|
|
8320
|
+
FROM session_summary_children rel
|
|
8321
|
+
LEFT JOIN session_summary_duplicate_map parent_map ON parent_map.drop_id = rel.parent_id
|
|
8322
|
+
LEFT JOIN session_summary_duplicate_map child_map ON child_map.drop_id = rel.child_id
|
|
8323
|
+
WHERE parent_map.drop_id IS NOT NULL OR child_map.drop_id IS NOT NULL;
|
|
8324
|
+
|
|
8325
|
+
DELETE FROM session_summary_children
|
|
8326
|
+
WHERE parent_id IN (SELECT drop_id FROM session_summary_duplicate_map)
|
|
8327
|
+
OR child_id IN (SELECT drop_id FROM session_summary_duplicate_map);
|
|
8328
|
+
|
|
8329
|
+
DELETE FROM session_summary_memories
|
|
8330
|
+
WHERE summary_id IN (SELECT drop_id FROM session_summary_duplicate_map);
|
|
8331
|
+
|
|
8332
|
+
DELETE FROM session_summaries
|
|
8333
|
+
WHERE id IN (SELECT drop_id FROM session_summary_duplicate_map);
|
|
8334
|
+
|
|
8335
|
+
DROP TABLE session_summary_duplicate_map;
|
|
8336
|
+
|
|
8337
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_summaries_session_depth_summary
|
|
8338
|
+
ON session_summaries(agent_id, session_key, depth)
|
|
8339
|
+
WHERE session_key IS NOT NULL
|
|
8340
|
+
AND COALESCE(source_type, 'summary') = 'summary';
|
|
8341
|
+
`);
|
|
8342
|
+
}
|
|
8343
|
+
function up47(db) {
|
|
8344
|
+
db.exec(`
|
|
8345
|
+
DROP TRIGGER IF EXISTS session_transcripts_fts_ai;
|
|
8346
|
+
DROP TRIGGER IF EXISTS session_transcripts_fts_ad;
|
|
8347
|
+
DROP TRIGGER IF EXISTS session_transcripts_fts_au;
|
|
8348
|
+
DROP TABLE IF EXISTS session_transcripts_fts;
|
|
8349
|
+
|
|
8350
|
+
CREATE TABLE IF NOT EXISTS session_transcripts_next (
|
|
8351
|
+
session_key TEXT NOT NULL,
|
|
8352
|
+
content TEXT NOT NULL,
|
|
8353
|
+
harness TEXT,
|
|
8354
|
+
project TEXT,
|
|
8355
|
+
agent_id TEXT NOT NULL DEFAULT 'default',
|
|
8356
|
+
created_at TEXT NOT NULL,
|
|
8357
|
+
updated_at TEXT,
|
|
8358
|
+
PRIMARY KEY (agent_id, session_key)
|
|
8359
|
+
);
|
|
8360
|
+
|
|
8361
|
+
INSERT INTO session_transcripts_next (
|
|
8362
|
+
session_key,
|
|
8363
|
+
content,
|
|
8364
|
+
harness,
|
|
8365
|
+
project,
|
|
8366
|
+
agent_id,
|
|
8367
|
+
created_at,
|
|
8368
|
+
updated_at
|
|
8369
|
+
)
|
|
8370
|
+
SELECT
|
|
8371
|
+
session_key,
|
|
8372
|
+
content,
|
|
8373
|
+
harness,
|
|
8374
|
+
project,
|
|
8375
|
+
agent_id,
|
|
8376
|
+
created_at,
|
|
8377
|
+
updated_at
|
|
8378
|
+
FROM (
|
|
8379
|
+
SELECT
|
|
8380
|
+
session_key,
|
|
8381
|
+
content,
|
|
8382
|
+
harness,
|
|
8383
|
+
project,
|
|
8384
|
+
COALESCE(agent_id, 'default') AS agent_id,
|
|
8385
|
+
created_at,
|
|
8386
|
+
COALESCE(updated_at, created_at) AS updated_at,
|
|
8387
|
+
ROW_NUMBER() OVER (
|
|
8388
|
+
PARTITION BY COALESCE(agent_id, 'default'), session_key
|
|
8389
|
+
ORDER BY COALESCE(updated_at, created_at) DESC, LENGTH(content) DESC, created_at DESC, rowid DESC
|
|
8390
|
+
) AS rn
|
|
8391
|
+
FROM session_transcripts
|
|
8392
|
+
) ranked
|
|
8393
|
+
WHERE rn = 1;
|
|
8394
|
+
|
|
8395
|
+
DROP TABLE session_transcripts;
|
|
8396
|
+
ALTER TABLE session_transcripts_next RENAME TO session_transcripts;
|
|
8397
|
+
|
|
8398
|
+
CREATE INDEX IF NOT EXISTS idx_st_project
|
|
8399
|
+
ON session_transcripts(project);
|
|
8400
|
+
CREATE INDEX IF NOT EXISTS idx_st_created
|
|
8401
|
+
ON session_transcripts(created_at);
|
|
8402
|
+
CREATE INDEX IF NOT EXISTS idx_st_agent_updated
|
|
8403
|
+
ON session_transcripts(agent_id, updated_at);
|
|
8404
|
+
|
|
8405
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS session_transcripts_fts USING fts5(
|
|
8406
|
+
content,
|
|
8407
|
+
content='session_transcripts',
|
|
8408
|
+
content_rowid='rowid'
|
|
8409
|
+
);
|
|
8410
|
+
|
|
8411
|
+
CREATE TRIGGER IF NOT EXISTS session_transcripts_fts_ai AFTER INSERT ON session_transcripts BEGIN
|
|
8412
|
+
INSERT INTO session_transcripts_fts(rowid, content)
|
|
8413
|
+
VALUES (new.rowid, new.content);
|
|
8414
|
+
END;
|
|
8415
|
+
|
|
8416
|
+
CREATE TRIGGER IF NOT EXISTS session_transcripts_fts_ad AFTER DELETE ON session_transcripts BEGIN
|
|
8417
|
+
INSERT INTO session_transcripts_fts(session_transcripts_fts, rowid, content)
|
|
8418
|
+
VALUES ('delete', old.rowid, old.content);
|
|
8419
|
+
END;
|
|
8420
|
+
|
|
8421
|
+
CREATE TRIGGER IF NOT EXISTS session_transcripts_fts_au AFTER UPDATE ON session_transcripts BEGIN
|
|
8422
|
+
INSERT INTO session_transcripts_fts(session_transcripts_fts, rowid, content)
|
|
8423
|
+
VALUES ('delete', old.rowid, old.content);
|
|
8424
|
+
INSERT INTO session_transcripts_fts(rowid, content)
|
|
8425
|
+
VALUES (new.rowid, new.content);
|
|
8426
|
+
END;
|
|
8427
|
+
|
|
8428
|
+
INSERT INTO session_transcripts_fts(session_transcripts_fts)
|
|
8429
|
+
VALUES ('rebuild');
|
|
8430
|
+
|
|
8431
|
+
DROP INDEX IF EXISTS idx_summaries_session_depth;
|
|
8432
|
+
DROP INDEX IF EXISTS idx_summaries_session_depth_summary;
|
|
8433
|
+
CREATE INDEX IF NOT EXISTS idx_summaries_agent_session_key
|
|
8434
|
+
ON session_summaries(agent_id, session_key);
|
|
8435
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_summaries_agent_session_depth_summary
|
|
8436
|
+
ON session_summaries(agent_id, session_key, depth)
|
|
8437
|
+
WHERE session_key IS NOT NULL
|
|
8438
|
+
AND COALESCE(source_type, 'summary') = 'summary';
|
|
8439
|
+
`);
|
|
8440
|
+
}
|
|
8178
8441
|
var MIGRATIONS = [
|
|
8179
8442
|
{
|
|
8180
8443
|
version: 1,
|
|
@@ -8508,6 +8771,41 @@ var MIGRATIONS = [
|
|
|
8508
8771
|
{ table: "memories", column: "visibility" }
|
|
8509
8772
|
]
|
|
8510
8773
|
}
|
|
8774
|
+
},
|
|
8775
|
+
{
|
|
8776
|
+
version: 44,
|
|
8777
|
+
name: "memory-md-temporal-head",
|
|
8778
|
+
up: up44,
|
|
8779
|
+
artifacts: {
|
|
8780
|
+
columns: [
|
|
8781
|
+
{ table: "session_summaries", column: "source_type" },
|
|
8782
|
+
{ table: "session_summaries", column: "source_ref" },
|
|
8783
|
+
{ table: "session_summaries", column: "meta_json" }
|
|
8784
|
+
]
|
|
8785
|
+
}
|
|
8786
|
+
},
|
|
8787
|
+
{
|
|
8788
|
+
version: 45,
|
|
8789
|
+
name: "lossless-working-memory-hardening",
|
|
8790
|
+
up: up45,
|
|
8791
|
+
artifacts: {
|
|
8792
|
+
tables: ["session_transcripts_fts", "memory_md_heads"],
|
|
8793
|
+
columns: [
|
|
8794
|
+
{ table: "session_transcripts", column: "updated_at" },
|
|
8795
|
+
{ table: "summary_jobs", column: "agent_id" },
|
|
8796
|
+
{ table: "session_scores", column: "agent_id" }
|
|
8797
|
+
]
|
|
8798
|
+
}
|
|
8799
|
+
},
|
|
8800
|
+
{
|
|
8801
|
+
version: 46,
|
|
8802
|
+
name: "session-summary-uniqueness",
|
|
8803
|
+
up: up46
|
|
8804
|
+
},
|
|
8805
|
+
{
|
|
8806
|
+
version: 47,
|
|
8807
|
+
name: "agent-scoped-temporal-uniqueness",
|
|
8808
|
+
up: up47
|
|
8511
8809
|
}
|
|
8512
8810
|
];
|
|
8513
8811
|
var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
|
|
@@ -11351,6 +11649,7 @@ var DEFAULT_DAEMON_URL = "http://localhost:3850";
|
|
|
11351
11649
|
var RUNTIME_PATH = "plugin";
|
|
11352
11650
|
var READ_TIMEOUT = 5000;
|
|
11353
11651
|
var WRITE_TIMEOUT = 1e4;
|
|
11652
|
+
var COMPACTION_HOOK_DEDUPE_MS = 1000;
|
|
11354
11653
|
var METADATA_LINE_PREFIXES = [
|
|
11355
11654
|
"<<<EXTERNAL_UNTRUSTED_CONTENT",
|
|
11356
11655
|
">>>",
|
|
@@ -11589,7 +11888,9 @@ async function onCompactionComplete(harness, summary, options = {}) {
|
|
|
11589
11888
|
body: {
|
|
11590
11889
|
harness,
|
|
11591
11890
|
summary,
|
|
11891
|
+
agentId: options.agentId,
|
|
11592
11892
|
sessionKey: options.sessionKey,
|
|
11893
|
+
project: options.project,
|
|
11593
11894
|
runtimePath: RUNTIME_PATH
|
|
11594
11895
|
},
|
|
11595
11896
|
timeout: WRITE_TIMEOUT
|
|
@@ -11601,6 +11902,7 @@ async function onSessionEnd(harness, options = {}) {
|
|
|
11601
11902
|
method: "POST",
|
|
11602
11903
|
body: {
|
|
11603
11904
|
harness,
|
|
11905
|
+
agentId: options.agentId,
|
|
11604
11906
|
transcriptPath: options.transcriptPath,
|
|
11605
11907
|
sessionKey: options.sessionKey,
|
|
11606
11908
|
sessionId: options.sessionId,
|
|
@@ -11752,9 +12054,9 @@ function textResult(text, details) {
|
|
|
11752
12054
|
};
|
|
11753
12055
|
}
|
|
11754
12056
|
var SESSIONLESS_DEDUPE_MS = 1000;
|
|
11755
|
-
function cleanupTimedMap(map, now) {
|
|
12057
|
+
function cleanupTimedMap(map, now, ttlMs = SESSIONLESS_DEDUPE_MS) {
|
|
11756
12058
|
for (const [key, ts] of map) {
|
|
11757
|
-
if (now - ts >
|
|
12059
|
+
if (now - ts > ttlMs) {
|
|
11758
12060
|
map.delete(key);
|
|
11759
12061
|
}
|
|
11760
12062
|
}
|
|
@@ -11777,6 +12079,77 @@ function buildSessionlessTurnKey(event, agentId) {
|
|
|
11777
12079
|
const messageCount = Array.isArray(event.messages) ? event.messages.length : -1;
|
|
11778
12080
|
return `${agentId ?? "-"}|${messageCount}|${normalizedPrompt}`;
|
|
11779
12081
|
}
|
|
12082
|
+
function buildScopedSessionKey(sessionKey, agentId) {
|
|
12083
|
+
if (!sessionKey)
|
|
12084
|
+
return;
|
|
12085
|
+
return `${agentId ?? "-"}|${sessionKey}`;
|
|
12086
|
+
}
|
|
12087
|
+
function readString(value) {
|
|
12088
|
+
return typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
|
|
12089
|
+
}
|
|
12090
|
+
function readNumber(value) {
|
|
12091
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
12092
|
+
}
|
|
12093
|
+
function resolveCompactionSessionFile(event, sessionFile) {
|
|
12094
|
+
const compaction = isRecord(event.compaction) ? event.compaction : undefined;
|
|
12095
|
+
return firstNonEmptyString(event.sessionFile, event.session_file, compaction?.sessionFile, compaction?.session_file, sessionFile);
|
|
12096
|
+
}
|
|
12097
|
+
function readSessionFileProject(sessionFile) {
|
|
12098
|
+
if (!sessionFile || !existsSync(sessionFile))
|
|
12099
|
+
return;
|
|
12100
|
+
try {
|
|
12101
|
+
const lines = readFileSync(sessionFile, "utf-8").split(`
|
|
12102
|
+
`).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
12103
|
+
for (const line of lines) {
|
|
12104
|
+
try {
|
|
12105
|
+
const row = JSON.parse(line);
|
|
12106
|
+
if (!isRecord(row) || row.type !== "session")
|
|
12107
|
+
continue;
|
|
12108
|
+
return firstNonEmptyString(row.cwd, row.project, row.workspace);
|
|
12109
|
+
} catch {}
|
|
12110
|
+
}
|
|
12111
|
+
} catch {}
|
|
12112
|
+
return;
|
|
12113
|
+
}
|
|
12114
|
+
function extractCompactionSummary(event, sessionFile) {
|
|
12115
|
+
const direct = readString(event.summary);
|
|
12116
|
+
if (direct)
|
|
12117
|
+
return direct;
|
|
12118
|
+
const compaction = isRecord(event.compaction) ? event.compaction : undefined;
|
|
12119
|
+
const nested = readString(compaction?.summary);
|
|
12120
|
+
if (nested)
|
|
12121
|
+
return nested;
|
|
12122
|
+
if (!sessionFile || !existsSync(sessionFile))
|
|
12123
|
+
return;
|
|
12124
|
+
try {
|
|
12125
|
+
const lines = readFileSync(sessionFile, "utf-8").split(`
|
|
12126
|
+
`).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
12127
|
+
for (let i = lines.length - 1;i >= 0; i--) {
|
|
12128
|
+
try {
|
|
12129
|
+
const row = JSON.parse(lines[i]);
|
|
12130
|
+
if (!isRecord(row) || row.type !== "compaction")
|
|
12131
|
+
continue;
|
|
12132
|
+
const summary = readString(row.summary);
|
|
12133
|
+
if (summary)
|
|
12134
|
+
return summary;
|
|
12135
|
+
} catch {}
|
|
12136
|
+
}
|
|
12137
|
+
} catch {}
|
|
12138
|
+
return;
|
|
12139
|
+
}
|
|
12140
|
+
function buildCompactionEventKey(event, options) {
|
|
12141
|
+
const compaction = isRecord(event.compaction) ? event.compaction : undefined;
|
|
12142
|
+
const parts = [
|
|
12143
|
+
options.agentId ?? "-",
|
|
12144
|
+
options.sessionKey ?? "-",
|
|
12145
|
+
readString(event.runId) ?? readString(compaction?.runId) ?? "-",
|
|
12146
|
+
readString(event.id) ?? readString(compaction?.id) ?? "-",
|
|
12147
|
+
String(readNumber(event.messageCount) ?? readNumber(event.compactingCount) ?? readNumber(event.compactedCount) ?? readNumber(compaction?.messageCount) ?? readNumber(compaction?.compactingCount) ?? readNumber(compaction?.compactedCount) ?? -1),
|
|
12148
|
+
String(readNumber(event.tokenCount) ?? readNumber(compaction?.tokenCount) ?? -1),
|
|
12149
|
+
options.summary ?? "-"
|
|
12150
|
+
];
|
|
12151
|
+
return parts.join("|");
|
|
12152
|
+
}
|
|
11780
12153
|
async function registerMarketplaceProxyTools(api, options, knownNames, proxyNameByToolKey) {
|
|
11781
12154
|
const [catalog, policy] = await Promise.all([
|
|
11782
12155
|
marketplaceToolList({ ...options, refresh: true }),
|
|
@@ -12163,6 +12536,8 @@ ${lines.join(`
|
|
|
12163
12536
|
const SESSION_TURN_TTL_MS = 4 * 60 * 60 * 1000;
|
|
12164
12537
|
const injectedTurns = new Map;
|
|
12165
12538
|
const inFlightTurns = new Set;
|
|
12539
|
+
const beforeCompactions = new Map;
|
|
12540
|
+
const afterCompactions = new Map;
|
|
12166
12541
|
const resolveHookContext = (ctx) => {
|
|
12167
12542
|
if (!isRecord(ctx)) {
|
|
12168
12543
|
return {};
|
|
@@ -12170,9 +12545,100 @@ ${lines.join(`
|
|
|
12170
12545
|
const sessionContext = ctx;
|
|
12171
12546
|
return {
|
|
12172
12547
|
sessionKey: typeof sessionContext?.sessionKey === "string" ? sessionContext.sessionKey : undefined,
|
|
12173
|
-
|
|
12548
|
+
sessionFile: typeof sessionContext?.sessionFile === "string" ? sessionContext.sessionFile.trim() : undefined,
|
|
12549
|
+
agentId: typeof sessionContext?.agentId === "string" ? sessionContext.agentId : undefined,
|
|
12550
|
+
project: firstNonEmptyString(sessionContext.project, sessionContext.cwd, sessionContext.workspace)
|
|
12551
|
+
};
|
|
12552
|
+
};
|
|
12553
|
+
const resolveCompactionSessionKey = (event, ctx) => {
|
|
12554
|
+
const fromEvent = readString(event.sessionKey) ?? readString(event.sessionId);
|
|
12555
|
+
if (fromEvent)
|
|
12556
|
+
return fromEvent;
|
|
12557
|
+
if (ctx.sessionKey)
|
|
12558
|
+
return ctx.sessionKey;
|
|
12559
|
+
return;
|
|
12560
|
+
};
|
|
12561
|
+
const resolveCompactionProject = (event, ctx) => {
|
|
12562
|
+
const compaction = isRecord(event.compaction) ? event.compaction : undefined;
|
|
12563
|
+
const sessionFile = resolveCompactionSessionFile(event, ctx.sessionFile);
|
|
12564
|
+
return firstNonEmptyString(event.project, event.cwd, event.workspace, compaction?.project, compaction?.cwd, compaction?.workspace, ctx.project, readSessionFileProject(sessionFile));
|
|
12565
|
+
};
|
|
12566
|
+
const resolveSessionEndSessionKey = (event, ctx) => {
|
|
12567
|
+
const fromEvent = readString(event.sessionKey) ?? readString(event.sessionId);
|
|
12568
|
+
if (fromEvent)
|
|
12569
|
+
return fromEvent;
|
|
12570
|
+
if (ctx.sessionKey)
|
|
12571
|
+
return ctx.sessionKey;
|
|
12572
|
+
return;
|
|
12573
|
+
};
|
|
12574
|
+
const resolveSessionEndTranscript = (event, ctx) => firstNonEmptyString(event.transcriptPath, event.sessionFile, ctx.sessionFile);
|
|
12575
|
+
const resolveSessionEndProject = (event, ctx) => firstNonEmptyString(event.cwd, event.project, event.workspace, ctx.project);
|
|
12576
|
+
const dedupeCompaction = (map, key) => {
|
|
12577
|
+
const now = Date.now();
|
|
12578
|
+
cleanupTimedMap(map, now, COMPACTION_HOOK_DEDUPE_MS);
|
|
12579
|
+
const seenAt = map.get(key);
|
|
12580
|
+
if (typeof seenAt === "number" && now - seenAt <= COMPACTION_HOOK_DEDUPE_MS) {
|
|
12581
|
+
return true;
|
|
12582
|
+
}
|
|
12583
|
+
map.set(key, now);
|
|
12584
|
+
return false;
|
|
12585
|
+
};
|
|
12586
|
+
const handleBeforeCompaction = async (event, ctx) => {
|
|
12587
|
+
if (!cfg.enabled || !daemonReachable)
|
|
12588
|
+
return;
|
|
12589
|
+
const sessionKey = resolveCompactionSessionKey(event, ctx);
|
|
12590
|
+
const messageCount = typeof event.messageCount === "number" ? event.messageCount : typeof event.compactingCount === "number" ? event.compactingCount : typeof event.compactedCount === "number" ? event.compactedCount : isRecord(event.compaction) && typeof event.compaction.compactingCount === "number" ? event.compaction.compactingCount : isRecord(event.compaction) && typeof event.compaction.compactedCount === "number" ? event.compaction.compactedCount : undefined;
|
|
12591
|
+
const dedupeKey = buildCompactionEventKey(event, {
|
|
12592
|
+
agentId: ctx.agentId,
|
|
12593
|
+
sessionKey
|
|
12594
|
+
});
|
|
12595
|
+
if (dedupeCompaction(beforeCompactions, dedupeKey)) {
|
|
12596
|
+
return;
|
|
12597
|
+
}
|
|
12598
|
+
const result = await onPreCompaction("openclaw", {
|
|
12599
|
+
...opts,
|
|
12600
|
+
sessionKey,
|
|
12601
|
+
messageCount
|
|
12602
|
+
});
|
|
12603
|
+
const parts = [result?.summaryPrompt, result?.guidelines].filter((value) => typeof value === "string" && value.length > 0);
|
|
12604
|
+
if (parts.length === 0) {
|
|
12605
|
+
return;
|
|
12606
|
+
}
|
|
12607
|
+
return {
|
|
12608
|
+
prependContext: parts.join(`
|
|
12609
|
+
|
|
12610
|
+
`)
|
|
12174
12611
|
};
|
|
12175
12612
|
};
|
|
12613
|
+
const handleAfterCompaction = async (event, ctx) => {
|
|
12614
|
+
if (!cfg.enabled || !daemonReachable)
|
|
12615
|
+
return;
|
|
12616
|
+
const sessionKey = resolveCompactionSessionKey(event, ctx);
|
|
12617
|
+
const scopedKey = buildScopedSessionKey(sessionKey, ctx.agentId);
|
|
12618
|
+
if (scopedKey) {
|
|
12619
|
+
injectedTurns.delete(scopedKey);
|
|
12620
|
+
}
|
|
12621
|
+
const sessionFile = resolveCompactionSessionFile(event, ctx.sessionFile);
|
|
12622
|
+
const summary = extractCompactionSummary(event, sessionFile);
|
|
12623
|
+
if (!summary) {
|
|
12624
|
+
api.logger.warn(`signet-memory: compaction summary unavailable, skipping save${sessionFile ? ` (${sessionFile})` : ""}`);
|
|
12625
|
+
return;
|
|
12626
|
+
}
|
|
12627
|
+
const dedupeKey = buildCompactionEventKey(event, {
|
|
12628
|
+
agentId: ctx.agentId,
|
|
12629
|
+
sessionKey,
|
|
12630
|
+
summary
|
|
12631
|
+
});
|
|
12632
|
+
if (dedupeCompaction(afterCompactions, dedupeKey)) {
|
|
12633
|
+
return;
|
|
12634
|
+
}
|
|
12635
|
+
await onCompactionComplete("openclaw", summary, {
|
|
12636
|
+
...opts,
|
|
12637
|
+
agentId: ctx.agentId,
|
|
12638
|
+
project: resolveCompactionProject(event, ctx),
|
|
12639
|
+
sessionKey
|
|
12640
|
+
});
|
|
12641
|
+
};
|
|
12176
12642
|
const ensureSessionStarted = async (event, sessionKey, agentId) => {
|
|
12177
12643
|
if (!sessionKey) {
|
|
12178
12644
|
const now = Date.now();
|
|
@@ -12192,7 +12658,8 @@ ${lines.join(`
|
|
|
12192
12658
|
}
|
|
12193
12659
|
return;
|
|
12194
12660
|
}
|
|
12195
|
-
|
|
12661
|
+
const scopedKey = buildScopedSessionKey(sessionKey, agentId);
|
|
12662
|
+
if (scopedKey && claimedSessions.has(scopedKey)) {
|
|
12196
12663
|
return;
|
|
12197
12664
|
}
|
|
12198
12665
|
const startResult = await onSessionStart("openclaw", {
|
|
@@ -12200,8 +12667,8 @@ ${lines.join(`
|
|
|
12200
12667
|
sessionKey,
|
|
12201
12668
|
agentId
|
|
12202
12669
|
});
|
|
12203
|
-
if (startResult) {
|
|
12204
|
-
claimedSessions.add(
|
|
12670
|
+
if (startResult && scopedKey) {
|
|
12671
|
+
claimedSessions.add(scopedKey);
|
|
12205
12672
|
}
|
|
12206
12673
|
};
|
|
12207
12674
|
const runPromptInjection = async (event, sessionKey, agentId) => {
|
|
@@ -12213,7 +12680,8 @@ ${lines.join(`
|
|
|
12213
12680
|
return;
|
|
12214
12681
|
}
|
|
12215
12682
|
const count = Array.isArray(event.messages) ? event.messages.length : undefined;
|
|
12216
|
-
const
|
|
12683
|
+
const scopedKey = buildScopedSessionKey(sessionKey, agentId);
|
|
12684
|
+
const sig = scopedKey && typeof count === "number" ? `${scopedKey}|${count}` : undefined;
|
|
12217
12685
|
if (sig) {
|
|
12218
12686
|
const now = Date.now();
|
|
12219
12687
|
for (const [k, v] of injectedTurns) {
|
|
@@ -12221,7 +12689,7 @@ ${lines.join(`
|
|
|
12221
12689
|
injectedTurns.delete(k);
|
|
12222
12690
|
}
|
|
12223
12691
|
}
|
|
12224
|
-
if (sig && (inFlightTurns.has(sig) ||
|
|
12692
|
+
if (sig && (inFlightTurns.has(sig) || scopedKey !== undefined && injectedTurns.get(scopedKey)?.count === count)) {
|
|
12225
12693
|
return;
|
|
12226
12694
|
}
|
|
12227
12695
|
if (sig)
|
|
@@ -12239,8 +12707,8 @@ ${lines.join(`
|
|
|
12239
12707
|
if (!result) {
|
|
12240
12708
|
return;
|
|
12241
12709
|
}
|
|
12242
|
-
if (
|
|
12243
|
-
injectedTurns.set(
|
|
12710
|
+
if (scopedKey && typeof count === "number") {
|
|
12711
|
+
injectedTurns.set(scopedKey, { count, at: Date.now() });
|
|
12244
12712
|
}
|
|
12245
12713
|
return buildInjectionResult(result);
|
|
12246
12714
|
};
|
|
@@ -12258,17 +12726,41 @@ ${lines.join(`
|
|
|
12258
12726
|
await ensureSessionStarted(event, sessionKey, agentId);
|
|
12259
12727
|
return runPromptInjection(event, sessionKey, agentId);
|
|
12260
12728
|
});
|
|
12261
|
-
api.on("agent_end", async (
|
|
12729
|
+
api.on("agent_end", async (event, ctx) => {
|
|
12262
12730
|
if (!cfg.enabled)
|
|
12263
12731
|
return;
|
|
12264
|
-
const
|
|
12265
|
-
|
|
12266
|
-
|
|
12267
|
-
|
|
12268
|
-
|
|
12732
|
+
const hook = resolveHookContext(ctx);
|
|
12733
|
+
const sessionKey = resolveSessionEndSessionKey(event, hook);
|
|
12734
|
+
const agentId = hook.agentId;
|
|
12735
|
+
const scopedKey = buildScopedSessionKey(sessionKey, agentId);
|
|
12736
|
+
await onSessionEnd("openclaw", {
|
|
12737
|
+
...opts,
|
|
12738
|
+
agentId,
|
|
12739
|
+
cwd: resolveSessionEndProject(event, hook),
|
|
12740
|
+
sessionId: readString(event.sessionId),
|
|
12741
|
+
sessionKey,
|
|
12742
|
+
transcriptPath: resolveSessionEndTranscript(event, hook)
|
|
12743
|
+
});
|
|
12744
|
+
if (scopedKey) {
|
|
12745
|
+
claimedSessions.delete(scopedKey);
|
|
12746
|
+
injectedTurns.delete(scopedKey);
|
|
12269
12747
|
}
|
|
12270
12748
|
return;
|
|
12271
12749
|
});
|
|
12750
|
+
api.on("before_compaction", async (event, ctx) => {
|
|
12751
|
+
return handleBeforeCompaction(event, resolveHookContext(ctx));
|
|
12752
|
+
});
|
|
12753
|
+
api.on("after_compaction", async (event, ctx) => {
|
|
12754
|
+
await handleAfterCompaction(event, resolveHookContext(ctx));
|
|
12755
|
+
return;
|
|
12756
|
+
});
|
|
12757
|
+
api.on("session:compact:before", async (event, ctx) => {
|
|
12758
|
+
return handleBeforeCompaction(event, resolveHookContext(ctx));
|
|
12759
|
+
});
|
|
12760
|
+
api.on("session:compact:after", async (event, ctx) => {
|
|
12761
|
+
await handleAfterCompaction(event, resolveHookContext(ctx));
|
|
12762
|
+
return;
|
|
12763
|
+
});
|
|
12272
12764
|
api.registerService({
|
|
12273
12765
|
id: "signet-memory-openclaw",
|
|
12274
12766
|
start() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signetai/signet-memory-openclaw",
|
|
3
|
-
"version": "0.77.
|
|
3
|
+
"version": "0.77.5",
|
|
4
4
|
"description": "Signet adapter for OpenClaw — runtime plugin for AI agent memory",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@sinclair/typebox": "0.34.47"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@signet/core": "0.77.
|
|
39
|
+
"@signet/core": "0.77.5",
|
|
40
40
|
"@types/node": "^22.0.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|