scream-code 0.9.7 → 0.10.1

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/main.mjs CHANGED
@@ -6,7 +6,7 @@ const __dirname = __cjsShimDirname(__filename);
6
6
  import "./suppress-sqlite-warning-C2VB0doZ.mjs";
7
7
  //#region src/main.ts
8
8
  try {
9
- (await import("./app-0DJZPbGz.mjs")).main();
9
+ (await import("./app-DVRLAZ8b.mjs")).main();
10
10
  } catch (error) {
11
11
  process.stderr.write(`${error instanceof Error ? error.stack ?? error.message : String(error)}\n`);
12
12
  process.exit(1);
@@ -3,5 +3,5 @@ import { fileURLToPath as __cjsShimFileURLToPath } from 'node:url';
3
3
  import { dirname as __cjsShimDirname } from 'node:path';
4
4
  const __filename = __cjsShimFileURLToPath(import.meta.url);
5
5
  const __dirname = __cjsShimDirname(__filename);
6
- import { n as multiSearchWithTrace } from "./src-1LHYB0xM.mjs";
6
+ import { n as multiSearchWithTrace } from "./src-oeUnRY3N.mjs";
7
7
  export { multiSearchWithTrace };
@@ -214,7 +214,10 @@ var KnowledgeStore = class {
214
214
  }
215
215
  async init() {
216
216
  if (this.initPromise) return this.initPromise;
217
- this.initPromise = this._doInit();
217
+ this.initPromise = this._doInit().catch((error) => {
218
+ this.initPromise = null;
219
+ throw error;
220
+ });
218
221
  return this.initPromise;
219
222
  }
220
223
  async _doInit() {
@@ -225,8 +228,32 @@ var KnowledgeStore = class {
225
228
  this.db.exec("PRAGMA foreign_keys = ON;");
226
229
  this.db.exec("PRAGMA busy_timeout = 5000;");
227
230
  this.createSchema();
231
+ this.migrateFtsTokenization();
228
232
  this.initialized = true;
229
233
  }
234
+ /**
235
+ * One-time migration: FTS rows written before toFtsText pre-tokenization
236
+ * indexed raw text (CJK runs became single tokens and are unsearchable).
237
+ * Rebuild all three FTS tables from the content tables with toFtsText.
238
+ * Tracked via PRAGMA user_version so it runs exactly once.
239
+ */
240
+ migrateFtsTokenization() {
241
+ if (this.db === void 0) return;
242
+ if (this.db.prepare("PRAGMA user_version").get().user_version >= 1) return;
243
+ this.db.exec("DELETE FROM knowledge_chunks_fts");
244
+ this.db.exec("DELETE FROM knowledge_events_fts");
245
+ this.db.exec("DELETE FROM knowledge_entities_fts");
246
+ const chunks = this.db.prepare("SELECT rowid, heading, content FROM knowledge_chunks").all();
247
+ const insChunk = this.db.prepare("INSERT INTO knowledge_chunks_fts (rowid, heading, content) VALUES (?, ?, ?)");
248
+ for (const c of chunks) insChunk.run(c.rowid, toFtsText(c.heading ?? ""), toFtsText(c.content));
249
+ const events = this.db.prepare("SELECT rowid, title, summary, content FROM knowledge_events").all();
250
+ const insEvent = this.db.prepare("INSERT INTO knowledge_events_fts (rowid, title, summary, content) VALUES (?, ?, ?, ?)");
251
+ for (const e of events) insEvent.run(e.rowid, toFtsText(e.title), toFtsText(e.summary ?? ""), toFtsText(e.content));
252
+ const entities = this.db.prepare("SELECT rowid, name, description FROM knowledge_entities").all();
253
+ const insEntity = this.db.prepare("INSERT INTO knowledge_entities_fts (rowid, name, description) VALUES (?, ?, ?)");
254
+ for (const e of entities) insEntity.run(e.rowid, toFtsText(e.name), toFtsText(e.description ?? ""));
255
+ this.db.exec("PRAGMA user_version = 1");
256
+ }
230
257
  close() {
231
258
  if (this.db !== void 0) {
232
259
  this.db.exec("PRAGMA wal_checkpoint(TRUNCATE)");
@@ -392,7 +419,19 @@ var KnowledgeStore = class {
392
419
  async deleteSource(id) {
393
420
  await this.init();
394
421
  if (this.db === void 0) return false;
395
- return this.db.prepare("DELETE FROM knowledge_sources WHERE id = ?").run(id).changes > 0;
422
+ const chunkRows = this.db.prepare("SELECT rowid, heading, content FROM knowledge_chunks WHERE source_id = ?").all(id);
423
+ const eventRows = this.db.prepare("SELECT rowid, title, summary, content FROM knowledge_events WHERE source_id = ?").all(id);
424
+ const entityRows = this.db.prepare("SELECT rowid, name, description FROM knowledge_entities WHERE source_id = ?").all(id);
425
+ const result = this.db.prepare("DELETE FROM knowledge_sources WHERE id = ?").run(id);
426
+ if (result.changes > 0) {
427
+ const delChunk = this.db.prepare("INSERT INTO knowledge_chunks_fts (knowledge_chunks_fts, rowid, heading, content) VALUES ('delete', ?, ?, ?)");
428
+ for (const row of chunkRows) delChunk.run(row.rowid, toFtsText(row.heading ?? ""), toFtsText(row.content));
429
+ const delEvent = this.db.prepare("INSERT INTO knowledge_events_fts (knowledge_events_fts, rowid, title, summary, content) VALUES ('delete', ?, ?, ?, ?)");
430
+ for (const row of eventRows) delEvent.run(row.rowid, toFtsText(row.title), toFtsText(row.summary ?? ""), toFtsText(row.content));
431
+ const delEntity = this.db.prepare("INSERT INTO knowledge_entities_fts (knowledge_entities_fts, rowid, name, description) VALUES ('delete', ?, ?, ?)");
432
+ for (const row of entityRows) delEntity.run(row.rowid, toFtsText(row.name), toFtsText(row.description ?? ""));
433
+ }
434
+ return result.changes > 0;
396
435
  }
397
436
  async createDocument(params) {
398
437
  if (this.db === void 0) throw new Error("knowledge store not initialized");
@@ -440,7 +479,7 @@ var KnowledgeStore = class {
440
479
  (id, source_id, document_id, rank, heading, content, raw_content, embedding_json, created_at)
441
480
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, params.sourceId, params.documentId, params.rank, params.heading, params.content, params.rawContent, embeddingJson, createdAt);
442
481
  this.db.prepare(`INSERT INTO knowledge_chunks_fts (rowid, heading, content)
443
- VALUES ((SELECT rowid FROM knowledge_chunks WHERE id = ?), ?, ?)`).run(id, params.heading ?? "", params.content);
482
+ VALUES ((SELECT rowid FROM knowledge_chunks WHERE id = ?), ?, ?)`).run(id, toFtsText(params.heading ?? ""), toFtsText(params.content));
444
483
  return {
445
484
  id,
446
485
  sourceId: params.sourceId,
@@ -488,7 +527,7 @@ var KnowledgeStore = class {
488
527
  title_embedding_json, content_embedding_json, created_at)
489
528
  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`).run(id, params.sourceId, params.documentId, params.chunkId, params.rank, params.title, params.summary, params.content, params.category, JSON.stringify(params.keywords), vectorToJson(params.titleEmbedding), vectorToJson(params.contentEmbedding), createdAt);
490
529
  this.db.prepare(`INSERT INTO knowledge_events_fts (rowid, title, summary, content)
491
- VALUES ((SELECT rowid FROM knowledge_events WHERE id = ?), ?, ?, ?)`).run(id, params.title, params.summary ?? "", params.content);
530
+ VALUES ((SELECT rowid FROM knowledge_events WHERE id = ?), ?, ?, ?)`).run(id, toFtsText(params.title), toFtsText(params.summary ?? ""), toFtsText(params.content));
492
531
  return {
493
532
  id,
494
533
  sourceId: params.sourceId,
@@ -551,8 +590,24 @@ var KnowledgeStore = class {
551
590
  const normalizedName = normalizeName(params.name);
552
591
  const existing = this.db.prepare("SELECT * FROM knowledge_entities WHERE source_id = ? AND type = ? AND normalized_name = ?").get(params.sourceId, params.type, normalizedName);
553
592
  if (existing !== void 0) {
554
- if (params.description !== null && existing["description"] === null) this.db.prepare("UPDATE knowledge_entities SET description = ? WHERE id = ?").run(params.description, String(existing["id"]));
555
- if (params.embedding !== null && existing["embedding_json"] === null) this.db.prepare("UPDATE knowledge_entities SET embedding_json = ? WHERE id = ?").run(vectorToJson(params.embedding), String(existing["id"]));
593
+ const existingId = String(existing["id"]);
594
+ let descriptionChanged = false;
595
+ if (params.description !== null && existing["description"] === null) {
596
+ this.db.prepare("UPDATE knowledge_entities SET description = ? WHERE id = ?").run(params.description, existingId);
597
+ existing["description"] = params.description;
598
+ descriptionChanged = true;
599
+ }
600
+ if (params.embedding !== null && existing["embedding_json"] === null) {
601
+ this.db.prepare("UPDATE knowledge_entities SET embedding_json = ? WHERE id = ?").run(vectorToJson(params.embedding), existingId);
602
+ existing["embedding_json"] = vectorToJson(params.embedding);
603
+ }
604
+ if (descriptionChanged) {
605
+ const ftsRow = this.db.prepare("SELECT rowid, name, description FROM knowledge_entities WHERE id = ?").get(existingId);
606
+ if (ftsRow !== void 0) {
607
+ this.db.prepare("INSERT INTO knowledge_entities_fts (knowledge_entities_fts, rowid, name, description) VALUES ('delete', ?, ?, ?)").run(ftsRow.rowid, toFtsText(ftsRow.name), "");
608
+ this.db.prepare(`INSERT INTO knowledge_entities_fts (rowid, name, description) VALUES (?, ?, ?)`).run(ftsRow.rowid, toFtsText(ftsRow.name), toFtsText(ftsRow.description ?? ""));
609
+ }
610
+ }
556
611
  return rowToEntity(existing);
557
612
  }
558
613
  const id = generateId("ent");
@@ -561,7 +616,7 @@ var KnowledgeStore = class {
561
616
  (id, source_id, type, name, normalized_name, description, embedding_json, created_at)
562
617
  VALUES (?, ?, ?, ?, ?, ?, ?, ?)`).run(id, params.sourceId, params.type, params.name, normalizedName, params.description, vectorToJson(params.embedding), createdAt);
563
618
  this.db.prepare(`INSERT INTO knowledge_entities_fts (rowid, name, description)
564
- VALUES ((SELECT rowid FROM knowledge_entities WHERE id = ?), ?, ?)`).run(id, params.name, params.description ?? "");
619
+ VALUES ((SELECT rowid FROM knowledge_entities WHERE id = ?), ?, ?)`).run(id, toFtsText(params.name), toFtsText(params.description ?? ""));
565
620
  return {
566
621
  id,
567
622
  sourceId: params.sourceId,