@signetai/signet-memory-openclaw 0.185.4 → 0.185.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.
Files changed (2) hide show
  1. package/dist/index.js +230 -0
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ import { join as join2 } from "node:path";
24
24
  import { createRequire as createRequire2 } from "node:module";
25
25
  import { dirname, join } from "node:path";
26
26
  import { fileURLToPath } from "node:url";
27
+ import { createHash } from "node:crypto";
27
28
  import { createRequire as createRequire22 } from "node:module";
28
29
  import { homedir as homedir4 } from "node:os";
29
30
  import { dirname as dirname3, join as join6, resolve as resolve2 } from "node:path";
@@ -10801,6 +10802,224 @@ function up116(db) {
10801
10802
  ON cross_agent_messages(delivery_path, delivery_state, delivery_lease_expires_at, delivery_updated_at);
10802
10803
  `);
10803
10804
  }
10805
+ function hasTable4(db, table) {
10806
+ return db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
10807
+ }
10808
+ function addColumnIfMissing25(db, table, column, definition) {
10809
+ const columns = db.prepare(`PRAGMA table_info(${table})`).all();
10810
+ if (columns.some((row) => row.name === column))
10811
+ return;
10812
+ db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
10813
+ }
10814
+ function tableColumns(db, table) {
10815
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
10816
+ return new Set(rows.map((row) => typeof row.name === "string" ? row.name : ""));
10817
+ }
10818
+ function hashTranscript(content) {
10819
+ return createHash("sha256").update(content, "utf8").digest("hex");
10820
+ }
10821
+ function backfillTranscriptHashes(db) {
10822
+ const columns = tableColumns(db, "session_transcripts");
10823
+ if (!columns.has("content_hash") || !columns.has("content"))
10824
+ return;
10825
+ const rows = db.prepare("SELECT session_key, agent_id, content FROM session_transcripts WHERE content_hash IS NULL").all();
10826
+ const update = db.prepare("UPDATE session_transcripts SET content_hash = ? WHERE agent_id = ? AND session_key = ? AND content_hash IS NULL");
10827
+ for (const row of rows) {
10828
+ if (typeof row.content !== "string" || typeof row.session_key !== "string")
10829
+ continue;
10830
+ update.run(hashTranscript(row.content), typeof row.agent_id === "string" ? row.agent_id : "default", row.session_key);
10831
+ }
10832
+ }
10833
+ var COMPLETION_BOUNDARY_REASONS = new Set(["session_closed", "session_clear", "stale_session", "ttl_expired"]);
10834
+ function summaryJobTimestamp(job) {
10835
+ return job.completed_at ?? job.ended_at ?? job.captured_at ?? job.created_at ?? new Date(0).toISOString();
10836
+ }
10837
+ function laterTimestamp(current, candidate) {
10838
+ if (current === null)
10839
+ return candidate;
10840
+ if (candidate === null)
10841
+ return current;
10842
+ const currentMillis = Date.parse(current);
10843
+ const candidateMillis = Date.parse(candidate);
10844
+ if (Number.isFinite(currentMillis) && Number.isFinite(candidateMillis)) {
10845
+ return candidateMillis > currentMillis ? candidate : current;
10846
+ }
10847
+ return candidate > current ? candidate : current;
10848
+ }
10849
+ function isCompletionBoundary(job, columns) {
10850
+ return columns.has("trigger") && job.trigger === "session_end" || columns.has("boundary_reason") && COMPLETION_BOUNDARY_REASONS.has(job.boundary_reason ?? "");
10851
+ }
10852
+ function mergeTranscriptContent(current, next) {
10853
+ if (current.length === 0)
10854
+ return next;
10855
+ if (next.length === 0 || current === next || current.includes(next))
10856
+ return current;
10857
+ if (next.includes(current))
10858
+ return next;
10859
+ return `${current}
10860
+ ${next}`;
10861
+ }
10862
+ function backfillTranscriptsFromSummaryJobs(db) {
10863
+ if (!hasTable4(db, "summary_jobs"))
10864
+ return;
10865
+ const summaryColumns = tableColumns(db, "summary_jobs");
10866
+ if (!summaryColumns.has("transcript"))
10867
+ return;
10868
+ const select = (name) => summaryColumns.has(name) ? `"${name}" AS "${name}"` : `NULL AS "${name}"`;
10869
+ const jobs = db.prepare(`SELECT ${[
10870
+ "id",
10871
+ "session_key",
10872
+ "transcript",
10873
+ "harness",
10874
+ "project",
10875
+ "agent_id",
10876
+ "trigger",
10877
+ "boundary_reason",
10878
+ "captured_at",
10879
+ "ended_at",
10880
+ "completed_at",
10881
+ "created_at"
10882
+ ].map(select).join(", ")} FROM summary_jobs`).all();
10883
+ const candidates = new Map;
10884
+ for (const job of jobs) {
10885
+ if (typeof job.transcript !== "string" || job.transcript.trim().length === 0)
10886
+ continue;
10887
+ const agentId = typeof job.agent_id === "string" && job.agent_id.length > 0 ? job.agent_id : "default";
10888
+ const sessionKey = typeof job.session_key === "string" && job.session_key.trim().length > 0 ? job.session_key : `legacy-summary-job:${job.id ?? hashTranscript(`${summaryJobTimestamp(job)}\x00${job.transcript}`)}`;
10889
+ const key = `${agentId}\x00${sessionKey}`;
10890
+ const current = candidates.get(key);
10891
+ const timestamp = summaryJobTimestamp(job);
10892
+ const boundary = isCompletionBoundary(job, summaryColumns);
10893
+ const createdAt = job.captured_at ?? job.created_at ?? job.ended_at ?? timestamp;
10894
+ if (!current) {
10895
+ candidates.set(key, {
10896
+ sessionKey,
10897
+ job: { ...job, agent_id: agentId },
10898
+ content: job.transcript,
10899
+ createdAt,
10900
+ completedAt: boundary ? timestamp : null
10901
+ });
10902
+ continue;
10903
+ }
10904
+ const currentTimestamp = summaryJobTimestamp(current.job);
10905
+ const preferred = timestamp > currentTimestamp || timestamp === currentTimestamp && job.transcript.length > current.content.length ? { ...job, agent_id: agentId } : current.job;
10906
+ candidates.set(key, {
10907
+ sessionKey,
10908
+ job: preferred,
10909
+ content: mergeTranscriptContent(current.content, job.transcript),
10910
+ createdAt: current.createdAt < createdAt ? current.createdAt : createdAt,
10911
+ completedAt: laterTimestamp(current.completedAt, boundary ? timestamp : null)
10912
+ });
10913
+ }
10914
+ const transcriptColumns = tableColumns(db, "session_transcripts");
10915
+ const hasUpdated = transcriptColumns.has("updated_at");
10916
+ const hasCompleted = transcriptColumns.has("completed_at");
10917
+ const hasHash = transcriptColumns.has("content_hash");
10918
+ const insertColumns = ["session_key", "content", "harness", "project", "agent_id", "created_at"];
10919
+ if (hasUpdated)
10920
+ insertColumns.push("updated_at");
10921
+ if (hasCompleted)
10922
+ insertColumns.push("completed_at");
10923
+ if (hasHash)
10924
+ insertColumns.push("content_hash");
10925
+ const insert = db.prepare(`INSERT OR IGNORE INTO session_transcripts (${insertColumns.join(", ")}) VALUES (${insertColumns.map(() => "?").join(", ")})`);
10926
+ const existing = db.prepare("SELECT content, completed_at FROM session_transcripts WHERE agent_id = ? AND session_key = ?");
10927
+ for (const candidate of candidates.values()) {
10928
+ const job = candidate.job;
10929
+ const agentId = job.agent_id ?? "default";
10930
+ const existingRow = existing.get(agentId, candidate.sessionKey);
10931
+ if (existingRow != null) {
10932
+ const previousContent = typeof existingRow.content === "string" ? existingRow.content : "";
10933
+ const mergedContent = mergeTranscriptContent(previousContent, candidate.content);
10934
+ const completedAt = typeof existingRow.completed_at === "string" && existingRow.completed_at.length > 0 ? existingRow.completed_at : candidate.completedAt;
10935
+ const assignments = ["content = ?"];
10936
+ const values2 = [mergedContent];
10937
+ if (hasUpdated && mergedContent !== previousContent) {
10938
+ assignments.push("updated_at = ?");
10939
+ values2.push(candidate.createdAt);
10940
+ }
10941
+ if (hasCompleted && completedAt && !existingRow.completed_at) {
10942
+ assignments.push("completed_at = ?");
10943
+ values2.push(completedAt);
10944
+ }
10945
+ if (hasHash) {
10946
+ assignments.push("content_hash = ?");
10947
+ values2.push(hashTranscript(mergedContent));
10948
+ }
10949
+ values2.push(agentId, candidate.sessionKey);
10950
+ db.prepare(`UPDATE session_transcripts SET ${assignments.join(", ")} WHERE agent_id = ? AND session_key = ?`).run(...values2);
10951
+ continue;
10952
+ }
10953
+ const values = [
10954
+ candidate.sessionKey,
10955
+ candidate.content,
10956
+ job.harness ?? null,
10957
+ job.project ?? null,
10958
+ agentId,
10959
+ candidate.createdAt
10960
+ ];
10961
+ if (hasUpdated)
10962
+ values.push(candidate.createdAt);
10963
+ if (hasCompleted)
10964
+ values.push(candidate.completedAt);
10965
+ if (hasHash)
10966
+ values.push(hashTranscript(candidate.content));
10967
+ insert.run(...values);
10968
+ }
10969
+ }
10970
+ function up117(db) {
10971
+ if (!hasTable4(db, "session_transcripts"))
10972
+ return;
10973
+ addColumnIfMissing25(db, "session_transcripts", "completed_at", "TEXT");
10974
+ addColumnIfMissing25(db, "session_transcripts", "content_hash", "TEXT");
10975
+ backfillTranscriptHashes(db);
10976
+ if (hasTable4(db, "transcript_capture_jobs")) {
10977
+ const captureColumns = db.prepare("PRAGMA table_info(transcript_capture_jobs)").all();
10978
+ if (captureColumns.some((row) => row.name === "summary_status")) {
10979
+ db.exec("UPDATE transcript_capture_jobs SET summary_status = 'not_requested' WHERE summary_status IN ('pending', 'failed', 'skipped')");
10980
+ }
10981
+ }
10982
+ if (hasTable4(db, "summary_jobs")) {
10983
+ backfillTranscriptsFromSummaryJobs(db);
10984
+ backfillTranscriptHashes(db);
10985
+ const summaryColumns = tableColumns(db, "summary_jobs");
10986
+ const timestampParts = ["completed_at", "ended_at", "captured_at", "created_at"].filter((column) => summaryColumns.has(column)).map((column) => `sj.${column}`);
10987
+ const timestampValue = timestampParts.length === 1 ? timestampParts[0] : `COALESCE(${timestampParts.join(", ")})`;
10988
+ const completionTimestamp = timestampValue ? `MAX(${timestampValue})` : "NULL";
10989
+ const boundaryParts = [
10990
+ summaryColumns.has("trigger") ? "sj.trigger = 'session_end'" : null,
10991
+ summaryColumns.has("boundary_reason") ? "sj.boundary_reason IN ('session_closed', 'session_clear', 'stale_session', 'ttl_expired')" : null
10992
+ ].filter((part) => part !== null);
10993
+ const boundaryPredicate = boundaryParts.length > 0 ? `(${boundaryParts.join(" OR ")})` : "1=1";
10994
+ const agentPredicate = summaryColumns.has("agent_id") ? "sj.agent_id = session_transcripts.agent_id" : "session_transcripts.agent_id = 'default'";
10995
+ if (completionTimestamp !== "NULL") {
10996
+ db.exec(`
10997
+ UPDATE session_transcripts
10998
+ SET completed_at = COALESCE(
10999
+ completed_at,
11000
+ (
11001
+ SELECT ${completionTimestamp}
11002
+ FROM summary_jobs AS sj
11003
+ WHERE ${agentPredicate}
11004
+ AND sj.session_key = session_transcripts.session_key
11005
+ AND ${boundaryPredicate}
11006
+ )
11007
+ )
11008
+ WHERE completed_at IS NULL;
11009
+ `);
11010
+ }
11011
+ db.exec("DELETE FROM summary_jobs");
11012
+ }
11013
+ const completionIndexColumns = ["agent_id", "completed_at"];
11014
+ if (tableColumns(db, "session_transcripts").has("updated_at"))
11015
+ completionIndexColumns.push("updated_at");
11016
+ db.exec(`
11017
+ CREATE INDEX IF NOT EXISTS idx_st_agent_completed
11018
+ ON session_transcripts(${completionIndexColumns.join(", ")});
11019
+ CREATE INDEX IF NOT EXISTS idx_st_agent_hash
11020
+ ON session_transcripts(agent_id, content_hash);
11021
+ `);
11022
+ }
10804
11023
  var MIGRATIONS = [
10805
11024
  {
10806
11025
  version: 1,
@@ -11740,6 +11959,17 @@ var MIGRATIONS = [
11740
11959
  { table: "cross_agent_messages", column: "acp_target_agent_name" }
11741
11960
  ]
11742
11961
  }
11962
+ },
11963
+ {
11964
+ version: 117,
11965
+ name: "retire-summary-worker",
11966
+ up: up117,
11967
+ artifacts: {
11968
+ columns: [
11969
+ { table: "session_transcripts", column: "completed_at" },
11970
+ { table: "session_transcripts", column: "content_hash" }
11971
+ ]
11972
+ }
11743
11973
  }
11744
11974
  ];
11745
11975
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signetai/signet-memory-openclaw",
3
- "version": "0.185.4",
3
+ "version": "0.185.5",
4
4
  "description": "Signet adapter for OpenClaw — runtime plugin for AI agent memory",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",