@signetai/connector-claude-code 0.185.4 → 0.185.6

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 +527 -25
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import { dirname as dirname5, isAbsolute, join as join3, relative, sep } from "n
11
11
  import { createRequire } from "node:module";
12
12
  import { dirname, join } from "node:path";
13
13
  import { fileURLToPath } from "node:url";
14
+ import { createHash } from "node:crypto";
14
15
  import { createRequire as createRequire2 } from "node:module";
15
16
  import { homedir as homedir4 } from "node:os";
16
17
  import { dirname as dirname3, join as join6, resolve as resolve2 } from "node:path";
@@ -10542,6 +10543,240 @@ function up116(db) {
10542
10543
  ON cross_agent_messages(delivery_path, delivery_state, delivery_lease_expires_at, delivery_updated_at);
10543
10544
  `);
10544
10545
  }
10546
+ function hasTable4(db, table) {
10547
+ return db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
10548
+ }
10549
+ function addColumnIfMissing25(db, table, column, definition) {
10550
+ const columns = db.prepare(`PRAGMA table_info(${table})`).all();
10551
+ if (columns.some((row) => row.name === column))
10552
+ return;
10553
+ db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
10554
+ }
10555
+ function tableColumns(db, table) {
10556
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
10557
+ return new Set(rows.map((row) => typeof row.name === "string" ? row.name : ""));
10558
+ }
10559
+ function hashTranscript(content) {
10560
+ return createHash("sha256").update(content, "utf8").digest("hex");
10561
+ }
10562
+ function backfillTranscriptHashes(db) {
10563
+ const columns = tableColumns(db, "session_transcripts");
10564
+ if (!columns.has("content_hash") || !columns.has("content"))
10565
+ return;
10566
+ const rows = db.prepare("SELECT session_key, agent_id, content FROM session_transcripts WHERE content_hash IS NULL").all();
10567
+ const update = db.prepare("UPDATE session_transcripts SET content_hash = ? WHERE agent_id = ? AND session_key = ? AND content_hash IS NULL");
10568
+ for (const row of rows) {
10569
+ if (typeof row.content !== "string" || typeof row.session_key !== "string")
10570
+ continue;
10571
+ update.run(hashTranscript(row.content), typeof row.agent_id === "string" ? row.agent_id : "default", row.session_key);
10572
+ }
10573
+ }
10574
+ var COMPLETION_BOUNDARY_REASONS = new Set(["session_closed", "session_clear", "stale_session", "ttl_expired"]);
10575
+ function summaryJobTimestamp(job) {
10576
+ return job.completed_at ?? job.ended_at ?? job.captured_at ?? job.created_at ?? new Date(0).toISOString();
10577
+ }
10578
+ function laterTimestamp(current, candidate) {
10579
+ if (current === null)
10580
+ return candidate;
10581
+ if (candidate === null)
10582
+ return current;
10583
+ const currentMillis = Date.parse(current);
10584
+ const candidateMillis = Date.parse(candidate);
10585
+ if (Number.isFinite(currentMillis) && Number.isFinite(candidateMillis)) {
10586
+ return candidateMillis > currentMillis ? candidate : current;
10587
+ }
10588
+ return candidate > current ? candidate : current;
10589
+ }
10590
+ function isCompletionBoundary(job, columns) {
10591
+ return columns.has("trigger") && job.trigger === "session_end" || columns.has("boundary_reason") && COMPLETION_BOUNDARY_REASONS.has(job.boundary_reason ?? "");
10592
+ }
10593
+ function mergeTranscriptContent(current, next) {
10594
+ if (current.length === 0)
10595
+ return next;
10596
+ if (next.length === 0 || current === next || current.includes(next))
10597
+ return current;
10598
+ if (next.includes(current))
10599
+ return next;
10600
+ return `${current}
10601
+ ${next}`;
10602
+ }
10603
+ function backfillTranscriptsFromSummaryJobs(db) {
10604
+ if (!hasTable4(db, "summary_jobs"))
10605
+ return;
10606
+ const summaryColumns = tableColumns(db, "summary_jobs");
10607
+ if (!summaryColumns.has("transcript"))
10608
+ return;
10609
+ const select = (name) => summaryColumns.has(name) ? `"${name}" AS "${name}"` : `NULL AS "${name}"`;
10610
+ const jobs = db.prepare(`SELECT ${[
10611
+ "id",
10612
+ "session_key",
10613
+ "transcript",
10614
+ "harness",
10615
+ "project",
10616
+ "agent_id",
10617
+ "trigger",
10618
+ "boundary_reason",
10619
+ "captured_at",
10620
+ "ended_at",
10621
+ "completed_at",
10622
+ "created_at"
10623
+ ].map(select).join(", ")} FROM summary_jobs`).all();
10624
+ const candidates = new Map;
10625
+ for (const job of jobs) {
10626
+ if (typeof job.transcript !== "string" || job.transcript.trim().length === 0)
10627
+ continue;
10628
+ const agentId = typeof job.agent_id === "string" && job.agent_id.length > 0 ? job.agent_id : "default";
10629
+ 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}`)}`;
10630
+ const key = `${agentId}\x00${sessionKey}`;
10631
+ const current = candidates.get(key);
10632
+ const timestamp = summaryJobTimestamp(job);
10633
+ const boundary = isCompletionBoundary(job, summaryColumns);
10634
+ const createdAt = job.captured_at ?? job.created_at ?? job.ended_at ?? timestamp;
10635
+ if (!current) {
10636
+ candidates.set(key, {
10637
+ sessionKey,
10638
+ job: { ...job, agent_id: agentId },
10639
+ content: job.transcript,
10640
+ createdAt,
10641
+ completedAt: boundary ? timestamp : null
10642
+ });
10643
+ continue;
10644
+ }
10645
+ const currentTimestamp = summaryJobTimestamp(current.job);
10646
+ const preferred = timestamp > currentTimestamp || timestamp === currentTimestamp && job.transcript.length > current.content.length ? { ...job, agent_id: agentId } : current.job;
10647
+ candidates.set(key, {
10648
+ sessionKey,
10649
+ job: preferred,
10650
+ content: mergeTranscriptContent(current.content, job.transcript),
10651
+ createdAt: current.createdAt < createdAt ? current.createdAt : createdAt,
10652
+ completedAt: laterTimestamp(current.completedAt, boundary ? timestamp : null)
10653
+ });
10654
+ }
10655
+ const transcriptColumns = tableColumns(db, "session_transcripts");
10656
+ const hasUpdated = transcriptColumns.has("updated_at");
10657
+ const hasCompleted = transcriptColumns.has("completed_at");
10658
+ const hasHash = transcriptColumns.has("content_hash");
10659
+ const insertColumns = ["session_key", "content", "harness", "project", "agent_id", "created_at"];
10660
+ if (hasUpdated)
10661
+ insertColumns.push("updated_at");
10662
+ if (hasCompleted)
10663
+ insertColumns.push("completed_at");
10664
+ if (hasHash)
10665
+ insertColumns.push("content_hash");
10666
+ const insert = db.prepare(`INSERT OR IGNORE INTO session_transcripts (${insertColumns.join(", ")}) VALUES (${insertColumns.map(() => "?").join(", ")})`);
10667
+ const existing = db.prepare("SELECT content, completed_at FROM session_transcripts WHERE agent_id = ? AND session_key = ?");
10668
+ for (const candidate of candidates.values()) {
10669
+ const job = candidate.job;
10670
+ const agentId = job.agent_id ?? "default";
10671
+ const existingRow = existing.get(agentId, candidate.sessionKey);
10672
+ if (existingRow != null) {
10673
+ const previousContent = typeof existingRow.content === "string" ? existingRow.content : "";
10674
+ const mergedContent = mergeTranscriptContent(previousContent, candidate.content);
10675
+ const completedAt = typeof existingRow.completed_at === "string" && existingRow.completed_at.length > 0 ? existingRow.completed_at : candidate.completedAt;
10676
+ const assignments = ["content = ?"];
10677
+ const values2 = [mergedContent];
10678
+ if (hasUpdated && mergedContent !== previousContent) {
10679
+ assignments.push("updated_at = ?");
10680
+ values2.push(candidate.createdAt);
10681
+ }
10682
+ if (hasCompleted && completedAt && !existingRow.completed_at) {
10683
+ assignments.push("completed_at = ?");
10684
+ values2.push(completedAt);
10685
+ }
10686
+ if (hasHash) {
10687
+ assignments.push("content_hash = ?");
10688
+ values2.push(hashTranscript(mergedContent));
10689
+ }
10690
+ values2.push(agentId, candidate.sessionKey);
10691
+ db.prepare(`UPDATE session_transcripts SET ${assignments.join(", ")} WHERE agent_id = ? AND session_key = ?`).run(...values2);
10692
+ continue;
10693
+ }
10694
+ const values = [
10695
+ candidate.sessionKey,
10696
+ candidate.content,
10697
+ job.harness ?? null,
10698
+ job.project ?? null,
10699
+ agentId,
10700
+ candidate.createdAt
10701
+ ];
10702
+ if (hasUpdated)
10703
+ values.push(candidate.createdAt);
10704
+ if (hasCompleted)
10705
+ values.push(candidate.completedAt);
10706
+ if (hasHash)
10707
+ values.push(hashTranscript(candidate.content));
10708
+ insert.run(...values);
10709
+ }
10710
+ }
10711
+ function up117(db) {
10712
+ if (!hasTable4(db, "session_transcripts"))
10713
+ return;
10714
+ addColumnIfMissing25(db, "session_transcripts", "completed_at", "TEXT");
10715
+ addColumnIfMissing25(db, "session_transcripts", "content_hash", "TEXT");
10716
+ backfillTranscriptHashes(db);
10717
+ if (hasTable4(db, "transcript_capture_jobs")) {
10718
+ const captureColumns = db.prepare("PRAGMA table_info(transcript_capture_jobs)").all();
10719
+ if (captureColumns.some((row) => row.name === "summary_status")) {
10720
+ db.exec("UPDATE transcript_capture_jobs SET summary_status = 'not_requested' WHERE summary_status IN ('pending', 'failed', 'skipped')");
10721
+ }
10722
+ }
10723
+ if (hasTable4(db, "summary_jobs")) {
10724
+ backfillTranscriptsFromSummaryJobs(db);
10725
+ backfillTranscriptHashes(db);
10726
+ const summaryColumns = tableColumns(db, "summary_jobs");
10727
+ const timestampParts = ["completed_at", "ended_at", "captured_at", "created_at"].filter((column) => summaryColumns.has(column)).map((column) => `sj.${column}`);
10728
+ const timestampValue = timestampParts.length === 1 ? timestampParts[0] : `COALESCE(${timestampParts.join(", ")})`;
10729
+ const completionTimestamp = timestampValue ? `MAX(${timestampValue})` : "NULL";
10730
+ const boundaryParts = [
10731
+ summaryColumns.has("trigger") ? "sj.trigger = 'session_end'" : null,
10732
+ summaryColumns.has("boundary_reason") ? "sj.boundary_reason IN ('session_closed', 'session_clear', 'stale_session', 'ttl_expired')" : null
10733
+ ].filter((part) => part !== null);
10734
+ const boundaryPredicate = boundaryParts.length > 0 ? `(${boundaryParts.join(" OR ")})` : "1=1";
10735
+ const agentPredicate = summaryColumns.has("agent_id") ? "sj.agent_id = session_transcripts.agent_id" : "session_transcripts.agent_id = 'default'";
10736
+ if (completionTimestamp !== "NULL") {
10737
+ db.exec(`
10738
+ UPDATE session_transcripts
10739
+ SET completed_at = COALESCE(
10740
+ completed_at,
10741
+ (
10742
+ SELECT ${completionTimestamp}
10743
+ FROM summary_jobs AS sj
10744
+ WHERE ${agentPredicate}
10745
+ AND sj.session_key = session_transcripts.session_key
10746
+ AND ${boundaryPredicate}
10747
+ )
10748
+ )
10749
+ WHERE completed_at IS NULL;
10750
+ `);
10751
+ }
10752
+ db.exec("DELETE FROM summary_jobs");
10753
+ }
10754
+ const completionIndexColumns = ["agent_id", "completed_at"];
10755
+ if (tableColumns(db, "session_transcripts").has("updated_at"))
10756
+ completionIndexColumns.push("updated_at");
10757
+ db.exec(`
10758
+ CREATE INDEX IF NOT EXISTS idx_st_agent_completed
10759
+ ON session_transcripts(${completionIndexColumns.join(", ")});
10760
+ CREATE INDEX IF NOT EXISTS idx_st_agent_hash
10761
+ ON session_transcripts(agent_id, content_hash);
10762
+ `);
10763
+ }
10764
+ function up118(db) {
10765
+ db.exec(`
10766
+ CREATE INDEX IF NOT EXISTS idx_memory_jobs_pressure_status
10767
+ ON memory_jobs(status)
10768
+ WHERE status IN ('pending', 'leased') AND job_type <> 'extract';
10769
+ CREATE INDEX IF NOT EXISTS idx_memory_jobs_pressure_created_at
10770
+ ON memory_jobs(created_at)
10771
+ WHERE status IN ('pending', 'leased') AND job_type <> 'extract';
10772
+ CREATE INDEX IF NOT EXISTS idx_summary_jobs_pressure_status
10773
+ ON summary_jobs(status)
10774
+ WHERE status IN ('pending', 'leased');
10775
+ CREATE INDEX IF NOT EXISTS idx_summary_jobs_pressure_created_at
10776
+ ON summary_jobs(created_at)
10777
+ WHERE status IN ('pending', 'leased');
10778
+ `);
10779
+ }
10545
10780
  var MIGRATIONS = [
10546
10781
  {
10547
10782
  version: 1,
@@ -11481,6 +11716,22 @@ var MIGRATIONS = [
11481
11716
  { table: "cross_agent_messages", column: "acp_target_agent_name" }
11482
11717
  ]
11483
11718
  }
11719
+ },
11720
+ {
11721
+ version: 117,
11722
+ name: "retire-summary-worker",
11723
+ up: up117,
11724
+ artifacts: {
11725
+ columns: [
11726
+ { table: "session_transcripts", column: "completed_at" },
11727
+ { table: "session_transcripts", column: "content_hash" }
11728
+ ]
11729
+ }
11730
+ },
11731
+ {
11732
+ version: 118,
11733
+ name: "queue-pressure-indices",
11734
+ up: up118
11484
11735
  }
11485
11736
  ];
11486
11737
  var LATEST_SCHEMA_VERSION = MIGRATIONS[MIGRATIONS.length - 1]?.version ?? 0;
@@ -11818,6 +12069,7 @@ function resolveSignetMcpCommand() {
11818
12069
  import { createRequire as createRequire3 } from "node:module";
11819
12070
  import { dirname as dirname2, join as join2 } from "node:path";
11820
12071
  import { fileURLToPath as fileURLToPath2 } from "node:url";
12072
+ import { createHash as createHash2 } from "node:crypto";
11821
12073
  import { homedir as homedir2 } from "os";
11822
12074
  import { join as join22 } from "path";
11823
12075
  import { createRequire as createRequire22 } from "node:module";
@@ -18773,7 +19025,7 @@ function memoriesFtsNeedsTokenizerRepair2(sql) {
18773
19025
  return true;
18774
19026
  return !normalized.includes(`tokenize='${MEMORIES_FTS_TOKENIZER2}'`);
18775
19027
  }
18776
- function up117(db) {
19028
+ function up119(db) {
18777
19029
  db.exec(`
18778
19030
  CREATE TABLE IF NOT EXISTS schema_migrations (
18779
19031
  version INTEGER PRIMARY KEY,
@@ -18866,27 +19118,27 @@ function hasColumn22(db, table, column) {
18866
19118
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
18867
19119
  return rows.some((r) => r.name === column);
18868
19120
  }
18869
- function addColumnIfMissing25(db, table, column, definition) {
19121
+ function addColumnIfMissing26(db, table, column, definition) {
18870
19122
  if (!hasColumn22(db, table, column)) {
18871
19123
  db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
18872
19124
  }
18873
19125
  }
18874
19126
  function up210(db) {
18875
- addColumnIfMissing25(db, "memories", "content_hash", "TEXT");
18876
- addColumnIfMissing25(db, "memories", "normalized_content", "TEXT");
18877
- addColumnIfMissing25(db, "memories", "is_deleted", "INTEGER DEFAULT 0");
18878
- addColumnIfMissing25(db, "memories", "deleted_at", "TEXT");
18879
- addColumnIfMissing25(db, "memories", "extraction_status", "TEXT DEFAULT 'none'");
18880
- addColumnIfMissing25(db, "memories", "embedding_model", "TEXT");
18881
- addColumnIfMissing25(db, "memories", "extraction_model", "TEXT");
18882
- addColumnIfMissing25(db, "memories", "update_count", "INTEGER DEFAULT 0");
18883
- addColumnIfMissing25(db, "memories", "who", "TEXT");
18884
- addColumnIfMissing25(db, "memories", "why", "TEXT");
18885
- addColumnIfMissing25(db, "memories", "project", "TEXT");
18886
- addColumnIfMissing25(db, "memories", "pinned", "INTEGER DEFAULT 0");
18887
- addColumnIfMissing25(db, "memories", "importance", "REAL DEFAULT 0.5");
18888
- addColumnIfMissing25(db, "memories", "last_accessed", "TEXT");
18889
- addColumnIfMissing25(db, "memories", "access_count", "INTEGER DEFAULT 0");
19127
+ addColumnIfMissing26(db, "memories", "content_hash", "TEXT");
19128
+ addColumnIfMissing26(db, "memories", "normalized_content", "TEXT");
19129
+ addColumnIfMissing26(db, "memories", "is_deleted", "INTEGER DEFAULT 0");
19130
+ addColumnIfMissing26(db, "memories", "deleted_at", "TEXT");
19131
+ addColumnIfMissing26(db, "memories", "extraction_status", "TEXT DEFAULT 'none'");
19132
+ addColumnIfMissing26(db, "memories", "embedding_model", "TEXT");
19133
+ addColumnIfMissing26(db, "memories", "extraction_model", "TEXT");
19134
+ addColumnIfMissing26(db, "memories", "update_count", "INTEGER DEFAULT 0");
19135
+ addColumnIfMissing26(db, "memories", "who", "TEXT");
19136
+ addColumnIfMissing26(db, "memories", "why", "TEXT");
19137
+ addColumnIfMissing26(db, "memories", "project", "TEXT");
19138
+ addColumnIfMissing26(db, "memories", "pinned", "INTEGER DEFAULT 0");
19139
+ addColumnIfMissing26(db, "memories", "importance", "REAL DEFAULT 0.5");
19140
+ addColumnIfMissing26(db, "memories", "last_accessed", "TEXT");
19141
+ addColumnIfMissing26(db, "memories", "access_count", "INTEGER DEFAULT 0");
18890
19142
  db.exec(`
18891
19143
  CREATE TABLE IF NOT EXISTS memory_history (
18892
19144
  id TEXT PRIMARY KEY,
@@ -18982,7 +19234,7 @@ function up210(db) {
18982
19234
  ON memory_entity_mentions(entity_id);
18983
19235
  `);
18984
19236
  }
18985
- function addColumnIfMissing26(db, table, column, definition) {
19237
+ function addColumnIfMissing27(db, table, column, definition) {
18986
19238
  const rows = db.prepare(`PRAGMA table_info(${table})`).all();
18987
19239
  if (rows.some((r) => r.name === column))
18988
19240
  return false;
@@ -18990,8 +19242,8 @@ function addColumnIfMissing26(db, table, column, definition) {
18990
19242
  return true;
18991
19243
  }
18992
19244
  function up310(db) {
18993
- addColumnIfMissing26(db, "memories", "why", "TEXT");
18994
- addColumnIfMissing26(db, "memories", "project", "TEXT");
19245
+ addColumnIfMissing27(db, "memories", "why", "TEXT");
19246
+ addColumnIfMissing27(db, "memories", "project", "TEXT");
18995
19247
  db.exec(`DROP INDEX IF EXISTS idx_memories_content_hash`);
18996
19248
  db.exec(`
18997
19249
  UPDATE memories
@@ -19196,7 +19448,7 @@ function up1010(db) {
19196
19448
  )
19197
19449
  `);
19198
19450
  }
19199
- function up118(db) {
19451
+ function up1110(db) {
19200
19452
  db.exec(`
19201
19453
  CREATE TABLE IF NOT EXISTS session_scores (
19202
19454
  id TEXT PRIMARY KEY,
@@ -20417,7 +20669,7 @@ function up492(db) {
20417
20669
  );
20418
20670
  `);
20419
20671
  }
20420
- function hasTable4(db, name) {
20672
+ function hasTable5(db, name) {
20421
20673
  return db.prepare(`SELECT name
20422
20674
  FROM sqlite_master
20423
20675
  WHERE type = 'table' AND name = ?
@@ -20447,7 +20699,7 @@ function up502(db) {
20447
20699
  CREATE INDEX IF NOT EXISTS idx_entity_dependency_history_created
20448
20700
  ON entity_dependency_history(created_at DESC);
20449
20701
  `);
20450
- if (!hasTable4(db, "entity_dependencies"))
20702
+ if (!hasTable5(db, "entity_dependencies"))
20451
20703
  return;
20452
20704
  db.exec("DROP TRIGGER IF EXISTS trg_entity_dependencies_related_to_reason_insert");
20453
20705
  db.exec("DROP TRIGGER IF EXISTS trg_entity_dependencies_related_to_reason_update");
@@ -22349,11 +22601,245 @@ function up1162(db) {
22349
22601
  ON cross_agent_messages(delivery_path, delivery_state, delivery_lease_expires_at, delivery_updated_at);
22350
22602
  `);
22351
22603
  }
22604
+ function hasTable42(db, table) {
22605
+ return db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' AND name = ?").get(table) != null;
22606
+ }
22607
+ function addColumnIfMissing252(db, table, column, definition) {
22608
+ const columns = db.prepare(`PRAGMA table_info(${table})`).all();
22609
+ if (columns.some((row) => row.name === column))
22610
+ return;
22611
+ db.exec(`ALTER TABLE ${table} ADD COLUMN ${column} ${definition}`);
22612
+ }
22613
+ function tableColumns2(db, table) {
22614
+ const rows = db.prepare(`PRAGMA table_info(${table})`).all();
22615
+ return new Set(rows.map((row) => typeof row.name === "string" ? row.name : ""));
22616
+ }
22617
+ function hashTranscript2(content) {
22618
+ return createHash2("sha256").update(content, "utf8").digest("hex");
22619
+ }
22620
+ function backfillTranscriptHashes2(db) {
22621
+ const columns = tableColumns2(db, "session_transcripts");
22622
+ if (!columns.has("content_hash") || !columns.has("content"))
22623
+ return;
22624
+ const rows = db.prepare("SELECT session_key, agent_id, content FROM session_transcripts WHERE content_hash IS NULL").all();
22625
+ const update = db.prepare("UPDATE session_transcripts SET content_hash = ? WHERE agent_id = ? AND session_key = ? AND content_hash IS NULL");
22626
+ for (const row of rows) {
22627
+ if (typeof row.content !== "string" || typeof row.session_key !== "string")
22628
+ continue;
22629
+ update.run(hashTranscript2(row.content), typeof row.agent_id === "string" ? row.agent_id : "default", row.session_key);
22630
+ }
22631
+ }
22632
+ var COMPLETION_BOUNDARY_REASONS2 = new Set(["session_closed", "session_clear", "stale_session", "ttl_expired"]);
22633
+ function summaryJobTimestamp2(job) {
22634
+ return job.completed_at ?? job.ended_at ?? job.captured_at ?? job.created_at ?? new Date(0).toISOString();
22635
+ }
22636
+ function laterTimestamp2(current, candidate) {
22637
+ if (current === null)
22638
+ return candidate;
22639
+ if (candidate === null)
22640
+ return current;
22641
+ const currentMillis = Date.parse(current);
22642
+ const candidateMillis = Date.parse(candidate);
22643
+ if (Number.isFinite(currentMillis) && Number.isFinite(candidateMillis)) {
22644
+ return candidateMillis > currentMillis ? candidate : current;
22645
+ }
22646
+ return candidate > current ? candidate : current;
22647
+ }
22648
+ function isCompletionBoundary2(job, columns) {
22649
+ return columns.has("trigger") && job.trigger === "session_end" || columns.has("boundary_reason") && COMPLETION_BOUNDARY_REASONS2.has(job.boundary_reason ?? "");
22650
+ }
22651
+ function mergeTranscriptContent2(current, next) {
22652
+ if (current.length === 0)
22653
+ return next;
22654
+ if (next.length === 0 || current === next || current.includes(next))
22655
+ return current;
22656
+ if (next.includes(current))
22657
+ return next;
22658
+ return `${current}
22659
+ ${next}`;
22660
+ }
22661
+ function backfillTranscriptsFromSummaryJobs2(db) {
22662
+ if (!hasTable42(db, "summary_jobs"))
22663
+ return;
22664
+ const summaryColumns = tableColumns2(db, "summary_jobs");
22665
+ if (!summaryColumns.has("transcript"))
22666
+ return;
22667
+ const select = (name) => summaryColumns.has(name) ? `"${name}" AS "${name}"` : `NULL AS "${name}"`;
22668
+ const jobs = db.prepare(`SELECT ${[
22669
+ "id",
22670
+ "session_key",
22671
+ "transcript",
22672
+ "harness",
22673
+ "project",
22674
+ "agent_id",
22675
+ "trigger",
22676
+ "boundary_reason",
22677
+ "captured_at",
22678
+ "ended_at",
22679
+ "completed_at",
22680
+ "created_at"
22681
+ ].map(select).join(", ")} FROM summary_jobs`).all();
22682
+ const candidates = new Map;
22683
+ for (const job of jobs) {
22684
+ if (typeof job.transcript !== "string" || job.transcript.trim().length === 0)
22685
+ continue;
22686
+ const agentId = typeof job.agent_id === "string" && job.agent_id.length > 0 ? job.agent_id : "default";
22687
+ const sessionKey = typeof job.session_key === "string" && job.session_key.trim().length > 0 ? job.session_key : `legacy-summary-job:${job.id ?? hashTranscript2(`${summaryJobTimestamp2(job)}\x00${job.transcript}`)}`;
22688
+ const key = `${agentId}\x00${sessionKey}`;
22689
+ const current = candidates.get(key);
22690
+ const timestamp = summaryJobTimestamp2(job);
22691
+ const boundary = isCompletionBoundary2(job, summaryColumns);
22692
+ const createdAt = job.captured_at ?? job.created_at ?? job.ended_at ?? timestamp;
22693
+ if (!current) {
22694
+ candidates.set(key, {
22695
+ sessionKey,
22696
+ job: { ...job, agent_id: agentId },
22697
+ content: job.transcript,
22698
+ createdAt,
22699
+ completedAt: boundary ? timestamp : null
22700
+ });
22701
+ continue;
22702
+ }
22703
+ const currentTimestamp = summaryJobTimestamp2(current.job);
22704
+ const preferred = timestamp > currentTimestamp || timestamp === currentTimestamp && job.transcript.length > current.content.length ? { ...job, agent_id: agentId } : current.job;
22705
+ candidates.set(key, {
22706
+ sessionKey,
22707
+ job: preferred,
22708
+ content: mergeTranscriptContent2(current.content, job.transcript),
22709
+ createdAt: current.createdAt < createdAt ? current.createdAt : createdAt,
22710
+ completedAt: laterTimestamp2(current.completedAt, boundary ? timestamp : null)
22711
+ });
22712
+ }
22713
+ const transcriptColumns = tableColumns2(db, "session_transcripts");
22714
+ const hasUpdated = transcriptColumns.has("updated_at");
22715
+ const hasCompleted = transcriptColumns.has("completed_at");
22716
+ const hasHash = transcriptColumns.has("content_hash");
22717
+ const insertColumns = ["session_key", "content", "harness", "project", "agent_id", "created_at"];
22718
+ if (hasUpdated)
22719
+ insertColumns.push("updated_at");
22720
+ if (hasCompleted)
22721
+ insertColumns.push("completed_at");
22722
+ if (hasHash)
22723
+ insertColumns.push("content_hash");
22724
+ const insert = db.prepare(`INSERT OR IGNORE INTO session_transcripts (${insertColumns.join(", ")}) VALUES (${insertColumns.map(() => "?").join(", ")})`);
22725
+ const existing = db.prepare("SELECT content, completed_at FROM session_transcripts WHERE agent_id = ? AND session_key = ?");
22726
+ for (const candidate of candidates.values()) {
22727
+ const job = candidate.job;
22728
+ const agentId = job.agent_id ?? "default";
22729
+ const existingRow = existing.get(agentId, candidate.sessionKey);
22730
+ if (existingRow != null) {
22731
+ const previousContent = typeof existingRow.content === "string" ? existingRow.content : "";
22732
+ const mergedContent = mergeTranscriptContent2(previousContent, candidate.content);
22733
+ const completedAt = typeof existingRow.completed_at === "string" && existingRow.completed_at.length > 0 ? existingRow.completed_at : candidate.completedAt;
22734
+ const assignments = ["content = ?"];
22735
+ const values2 = [mergedContent];
22736
+ if (hasUpdated && mergedContent !== previousContent) {
22737
+ assignments.push("updated_at = ?");
22738
+ values2.push(candidate.createdAt);
22739
+ }
22740
+ if (hasCompleted && completedAt && !existingRow.completed_at) {
22741
+ assignments.push("completed_at = ?");
22742
+ values2.push(completedAt);
22743
+ }
22744
+ if (hasHash) {
22745
+ assignments.push("content_hash = ?");
22746
+ values2.push(hashTranscript2(mergedContent));
22747
+ }
22748
+ values2.push(agentId, candidate.sessionKey);
22749
+ db.prepare(`UPDATE session_transcripts SET ${assignments.join(", ")} WHERE agent_id = ? AND session_key = ?`).run(...values2);
22750
+ continue;
22751
+ }
22752
+ const values = [
22753
+ candidate.sessionKey,
22754
+ candidate.content,
22755
+ job.harness ?? null,
22756
+ job.project ?? null,
22757
+ agentId,
22758
+ candidate.createdAt
22759
+ ];
22760
+ if (hasUpdated)
22761
+ values.push(candidate.createdAt);
22762
+ if (hasCompleted)
22763
+ values.push(candidate.completedAt);
22764
+ if (hasHash)
22765
+ values.push(hashTranscript2(candidate.content));
22766
+ insert.run(...values);
22767
+ }
22768
+ }
22769
+ function up1172(db) {
22770
+ if (!hasTable42(db, "session_transcripts"))
22771
+ return;
22772
+ addColumnIfMissing252(db, "session_transcripts", "completed_at", "TEXT");
22773
+ addColumnIfMissing252(db, "session_transcripts", "content_hash", "TEXT");
22774
+ backfillTranscriptHashes2(db);
22775
+ if (hasTable42(db, "transcript_capture_jobs")) {
22776
+ const captureColumns = db.prepare("PRAGMA table_info(transcript_capture_jobs)").all();
22777
+ if (captureColumns.some((row) => row.name === "summary_status")) {
22778
+ db.exec("UPDATE transcript_capture_jobs SET summary_status = 'not_requested' WHERE summary_status IN ('pending', 'failed', 'skipped')");
22779
+ }
22780
+ }
22781
+ if (hasTable42(db, "summary_jobs")) {
22782
+ backfillTranscriptsFromSummaryJobs2(db);
22783
+ backfillTranscriptHashes2(db);
22784
+ const summaryColumns = tableColumns2(db, "summary_jobs");
22785
+ const timestampParts = ["completed_at", "ended_at", "captured_at", "created_at"].filter((column) => summaryColumns.has(column)).map((column) => `sj.${column}`);
22786
+ const timestampValue = timestampParts.length === 1 ? timestampParts[0] : `COALESCE(${timestampParts.join(", ")})`;
22787
+ const completionTimestamp = timestampValue ? `MAX(${timestampValue})` : "NULL";
22788
+ const boundaryParts = [
22789
+ summaryColumns.has("trigger") ? "sj.trigger = 'session_end'" : null,
22790
+ summaryColumns.has("boundary_reason") ? "sj.boundary_reason IN ('session_closed', 'session_clear', 'stale_session', 'ttl_expired')" : null
22791
+ ].filter((part) => part !== null);
22792
+ const boundaryPredicate = boundaryParts.length > 0 ? `(${boundaryParts.join(" OR ")})` : "1=1";
22793
+ const agentPredicate = summaryColumns.has("agent_id") ? "sj.agent_id = session_transcripts.agent_id" : "session_transcripts.agent_id = 'default'";
22794
+ if (completionTimestamp !== "NULL") {
22795
+ db.exec(`
22796
+ UPDATE session_transcripts
22797
+ SET completed_at = COALESCE(
22798
+ completed_at,
22799
+ (
22800
+ SELECT ${completionTimestamp}
22801
+ FROM summary_jobs AS sj
22802
+ WHERE ${agentPredicate}
22803
+ AND sj.session_key = session_transcripts.session_key
22804
+ AND ${boundaryPredicate}
22805
+ )
22806
+ )
22807
+ WHERE completed_at IS NULL;
22808
+ `);
22809
+ }
22810
+ db.exec("DELETE FROM summary_jobs");
22811
+ }
22812
+ const completionIndexColumns = ["agent_id", "completed_at"];
22813
+ if (tableColumns2(db, "session_transcripts").has("updated_at"))
22814
+ completionIndexColumns.push("updated_at");
22815
+ db.exec(`
22816
+ CREATE INDEX IF NOT EXISTS idx_st_agent_completed
22817
+ ON session_transcripts(${completionIndexColumns.join(", ")});
22818
+ CREATE INDEX IF NOT EXISTS idx_st_agent_hash
22819
+ ON session_transcripts(agent_id, content_hash);
22820
+ `);
22821
+ }
22822
+ function up1182(db) {
22823
+ db.exec(`
22824
+ CREATE INDEX IF NOT EXISTS idx_memory_jobs_pressure_status
22825
+ ON memory_jobs(status)
22826
+ WHERE status IN ('pending', 'leased') AND job_type <> 'extract';
22827
+ CREATE INDEX IF NOT EXISTS idx_memory_jobs_pressure_created_at
22828
+ ON memory_jobs(created_at)
22829
+ WHERE status IN ('pending', 'leased') AND job_type <> 'extract';
22830
+ CREATE INDEX IF NOT EXISTS idx_summary_jobs_pressure_status
22831
+ ON summary_jobs(status)
22832
+ WHERE status IN ('pending', 'leased');
22833
+ CREATE INDEX IF NOT EXISTS idx_summary_jobs_pressure_created_at
22834
+ ON summary_jobs(created_at)
22835
+ WHERE status IN ('pending', 'leased');
22836
+ `);
22837
+ }
22352
22838
  var MIGRATIONS2 = [
22353
22839
  {
22354
22840
  version: 1,
22355
22841
  name: "baseline",
22356
- up: up117,
22842
+ up: up119,
22357
22843
  artifacts: { tables: ["memories", "conversations", "embeddings"] }
22358
22844
  },
22359
22845
  {
@@ -22419,7 +22905,7 @@ var MIGRATIONS2 = [
22419
22905
  {
22420
22906
  version: 11,
22421
22907
  name: "session-scores",
22422
- up: up118,
22908
+ up: up1110,
22423
22909
  artifacts: { tables: ["session_scores"] }
22424
22910
  },
22425
22911
  {
@@ -23288,6 +23774,22 @@ var MIGRATIONS2 = [
23288
23774
  { table: "cross_agent_messages", column: "acp_target_agent_name" }
23289
23775
  ]
23290
23776
  }
23777
+ },
23778
+ {
23779
+ version: 117,
23780
+ name: "retire-summary-worker",
23781
+ up: up1172,
23782
+ artifacts: {
23783
+ columns: [
23784
+ { table: "session_transcripts", column: "completed_at" },
23785
+ { table: "session_transcripts", column: "content_hash" }
23786
+ ]
23787
+ }
23788
+ },
23789
+ {
23790
+ version: 118,
23791
+ name: "queue-pressure-indices",
23792
+ up: up1182
23291
23793
  }
23292
23794
  ];
23293
23795
  var LATEST_SCHEMA_VERSION2 = MIGRATIONS2[MIGRATIONS2.length - 1]?.version ?? 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signetai/connector-claude-code",
3
- "version": "0.185.4",
3
+ "version": "0.185.6",
4
4
  "description": "Signet connector for Claude Code (Anthropic CLI)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -24,8 +24,8 @@
24
24
  "typecheck": "tsc --noEmit"
25
25
  },
26
26
  "dependencies": {
27
- "@signetai/connector-base": "0.185.4",
28
- "@signetai/core": "0.185.4"
27
+ "@signetai/connector-base": "0.185.6",
28
+ "@signetai/core": "0.185.6"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.0.0",