@equationalapplications/core-llm-wiki 9.4.3 → 9.5.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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-BVY5P6BS.mjs';
2
- export { C as CheckpointIncompleteError, d as ChunkFailure, e as ClassifierAnswer, f as ClassifierQuestion, g as ClassifyRequest, h as ClassifyResponse, D as DegradedRecord, i as DraftPage, E as EmbedFactResult, j as EmbedFailureKind, k as EmbeddingMarkerKind, l as EntityMaintenanceReport, m as EntityStatus, n as EraseReport, o as EraseStepError, p as ExtractedFact, q as ExtractedFactEdge, r as ExtractedFactWithOntology, s as ExtractedTask, t as ForgetParams, u as ForgetResult, v as GraphTraversalOptions, w as GroundingConfig, H as HEAL_BATCH_SIZE, x as HEAL_RECHECK_MS, y as HOOK_TIMEOUT_MARKER, z as HealResult, I as ImportDumpResult, A as IngestDocumentResult, L as LLMProvider, B as LibrarianConfig, J as LibrarianGateConfig, K as LockedMaintenanceJob, N as MaintenanceJob, P as MaintenanceStopReason, Q as MemoryDumpEntity, T as MigrationPolicy, U as ONTOLOGY_BACKFILL_BATCH_SIZE, V as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, X as ONTOLOGY_BACKFILL_RECHECK_MS, Y as OntologyBackfillResult, Z as OntologyConfig, _ as OntologyEdgeType, $ as OntologyManifest, a0 as OntologyNodeType, a1 as OntologyPromptContext, a2 as OntologyUpdates, a3 as PendingMaintenance, a4 as PendingMigrationWork, a5 as PendingSourceStatus, a6 as PromptOverrides, a7 as PromptService, a8 as PrunePartialFailureError, a9 as ReembedResult, aa as RememberInput, ab as RunPendingMaintenanceOptions, ac as RunPendingMaintenanceResult, ad as SourcePassage, ae as StoreSourceResult, af as StoredSource, ag as StoredSourceDump, ah as StoredSourceSummary, ai as SupersedeReplacement, aj as VectorRanker, ak as VectorRankerFallback, al as VectorRankerRankArgs, am as VectorRankerSemanticResult, an as WikiBusyError, ao as WikiBusyOperation, ap as WikiCheckpoint, aq as WikiConfig, ar as WikiDiagnostic, as as WikiDiagnosticCode, at as WikiDiagnosticDetail, au as WikiDiagnosticOperation, av as WikiDiagnosticSeverity, aw as WikiDiagnosticTrigger, ax as WikiDraftNotFound, ay as WikiDuplicateHashError, az as WikiEdge, aA as WikiEvent, aB as WikiExternalDeletionError, aC as WikiFact, aD as WikiGraphNodeOwnershipConflict, aE as WikiIngestEmptyError, aF as WikiInstructions, aG as WikiInvalidReadOptions, aH as WikiLintReport, aI as WikiMemoryTestAccess, aJ as WikiMigrationRequiredError, aK as WikiOutboxEvent, aL as WikiParseError, aM as WikiSearchUnavailableError, aN as WikiSourcePointer, aO as WikiSourceRefHashCollision, aP as WikiStrictOntologyViolation, aQ as WikiSupersedeError, aR as WikiSupersedeReason, aS as WikiTask, aT as WikiTransactionError, aU as isWikiSearchUnavailableError, aV as validateManifest } from './testing-BVY5P6BS.mjs';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-BZyrIoJp.mjs';
2
+ export { C as CheckpointIncompleteError, d as ChunkFailure, e as ClassifierAnswer, f as ClassifierQuestion, g as ClassifyRequest, h as ClassifyResponse, D as DegradedRecord, i as DraftPage, E as EmbedFactResult, j as EmbedFailureKind, k as EmbeddingMarkerKind, l as EntityMaintenanceReport, m as EntityStatus, n as EraseReport, o as EraseStepError, p as ExtractedFact, q as ExtractedFactEdge, r as ExtractedFactWithOntology, s as ExtractedTask, t as ForgetParams, u as ForgetResult, v as GraphTraversalOptions, w as GroundingConfig, H as HEAL_BATCH_SIZE, x as HEAL_RECHECK_MS, y as HOOK_TIMEOUT_MARKER, z as HealResult, I as ImportDumpResult, A as IngestDocumentResult, L as LLMProvider, B as LibrarianConfig, J as LibrarianGateConfig, K as LockedMaintenanceJob, N as MaintenanceJob, P as MaintenanceStopReason, Q as MemoryDumpEntity, T as MigrationPolicy, U as ONTOLOGY_BACKFILL_BATCH_SIZE, V as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, X as ONTOLOGY_BACKFILL_RECHECK_MS, Y as OntologyBackfillResult, Z as OntologyConfig, _ as OntologyEdgeType, $ as OntologyManifest, a0 as OntologyNodeType, a1 as OntologyPromptContext, a2 as OntologyUpdates, a3 as PendingMaintenance, a4 as PendingMigrationWork, a5 as PendingSourceStatus, a6 as PromptOverrides, a7 as PromptService, a8 as PrunePartialFailureError, a9 as ReembedResult, aa as RememberInput, ab as RunPendingMaintenanceOptions, ac as RunPendingMaintenanceResult, ad as SourcePassage, ae as StoreSourceResult, af as StoredSource, ag as StoredSourceDump, ah as StoredSourceSummary, ai as SupersedeReplacement, aj as VectorRanker, ak as VectorRankerFallback, al as VectorRankerRankArgs, am as VectorRankerSemanticResult, an as WikiBusyError, ao as WikiBusyOperation, ap as WikiCheckpoint, aq as WikiConfig, ar as WikiDiagnostic, as as WikiDiagnosticCode, at as WikiDiagnosticDetail, au as WikiDiagnosticOperation, av as WikiDiagnosticSeverity, aw as WikiDiagnosticTrigger, ax as WikiDraftNotFound, ay as WikiDuplicateHashError, az as WikiEdge, aA as WikiEvent, aB as WikiExternalDeletionError, aC as WikiFact, aD as WikiGraphNodeOwnershipConflict, aE as WikiIngestEmptyError, aF as WikiInstructions, aG as WikiInvalidReadOptions, aH as WikiLintReport, aI as WikiMemoryTestAccess, aJ as WikiMigrationRequiredError, aK as WikiOutboxEvent, aL as WikiParseError, aM as WikiSearchUnavailableError, aN as WikiSourcePointer, aO as WikiSourceRefHashCollision, aP as WikiStrictOntologyViolation, aQ as WikiSupersedeError, aR as WikiSupersedeReason, aS as WikiTask, aT as WikiTransactionError, aU as isWikiSearchUnavailableError, aV as validateManifest } from './testing-BZyrIoJp.mjs';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
 
5
5
  /**
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-BVY5P6BS.js';
2
- export { C as CheckpointIncompleteError, d as ChunkFailure, e as ClassifierAnswer, f as ClassifierQuestion, g as ClassifyRequest, h as ClassifyResponse, D as DegradedRecord, i as DraftPage, E as EmbedFactResult, j as EmbedFailureKind, k as EmbeddingMarkerKind, l as EntityMaintenanceReport, m as EntityStatus, n as EraseReport, o as EraseStepError, p as ExtractedFact, q as ExtractedFactEdge, r as ExtractedFactWithOntology, s as ExtractedTask, t as ForgetParams, u as ForgetResult, v as GraphTraversalOptions, w as GroundingConfig, H as HEAL_BATCH_SIZE, x as HEAL_RECHECK_MS, y as HOOK_TIMEOUT_MARKER, z as HealResult, I as ImportDumpResult, A as IngestDocumentResult, L as LLMProvider, B as LibrarianConfig, J as LibrarianGateConfig, K as LockedMaintenanceJob, N as MaintenanceJob, P as MaintenanceStopReason, Q as MemoryDumpEntity, T as MigrationPolicy, U as ONTOLOGY_BACKFILL_BATCH_SIZE, V as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, X as ONTOLOGY_BACKFILL_RECHECK_MS, Y as OntologyBackfillResult, Z as OntologyConfig, _ as OntologyEdgeType, $ as OntologyManifest, a0 as OntologyNodeType, a1 as OntologyPromptContext, a2 as OntologyUpdates, a3 as PendingMaintenance, a4 as PendingMigrationWork, a5 as PendingSourceStatus, a6 as PromptOverrides, a7 as PromptService, a8 as PrunePartialFailureError, a9 as ReembedResult, aa as RememberInput, ab as RunPendingMaintenanceOptions, ac as RunPendingMaintenanceResult, ad as SourcePassage, ae as StoreSourceResult, af as StoredSource, ag as StoredSourceDump, ah as StoredSourceSummary, ai as SupersedeReplacement, aj as VectorRanker, ak as VectorRankerFallback, al as VectorRankerRankArgs, am as VectorRankerSemanticResult, an as WikiBusyError, ao as WikiBusyOperation, ap as WikiCheckpoint, aq as WikiConfig, ar as WikiDiagnostic, as as WikiDiagnosticCode, at as WikiDiagnosticDetail, au as WikiDiagnosticOperation, av as WikiDiagnosticSeverity, aw as WikiDiagnosticTrigger, ax as WikiDraftNotFound, ay as WikiDuplicateHashError, az as WikiEdge, aA as WikiEvent, aB as WikiExternalDeletionError, aC as WikiFact, aD as WikiGraphNodeOwnershipConflict, aE as WikiIngestEmptyError, aF as WikiInstructions, aG as WikiInvalidReadOptions, aH as WikiLintReport, aI as WikiMemoryTestAccess, aJ as WikiMigrationRequiredError, aK as WikiOutboxEvent, aL as WikiParseError, aM as WikiSearchUnavailableError, aN as WikiSourcePointer, aO as WikiSourceRefHashCollision, aP as WikiStrictOntologyViolation, aQ as WikiSupersedeError, aR as WikiSupersedeReason, aS as WikiTask, aT as WikiTransactionError, aU as isWikiSearchUnavailableError, aV as validateManifest } from './testing-BVY5P6BS.js';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, R as ReadOptions, S as SQLiteAdapter, W as WikiOptions, c as WikiMemory } from './testing-BZyrIoJp.js';
2
+ export { C as CheckpointIncompleteError, d as ChunkFailure, e as ClassifierAnswer, f as ClassifierQuestion, g as ClassifyRequest, h as ClassifyResponse, D as DegradedRecord, i as DraftPage, E as EmbedFactResult, j as EmbedFailureKind, k as EmbeddingMarkerKind, l as EntityMaintenanceReport, m as EntityStatus, n as EraseReport, o as EraseStepError, p as ExtractedFact, q as ExtractedFactEdge, r as ExtractedFactWithOntology, s as ExtractedTask, t as ForgetParams, u as ForgetResult, v as GraphTraversalOptions, w as GroundingConfig, H as HEAL_BATCH_SIZE, x as HEAL_RECHECK_MS, y as HOOK_TIMEOUT_MARKER, z as HealResult, I as ImportDumpResult, A as IngestDocumentResult, L as LLMProvider, B as LibrarianConfig, J as LibrarianGateConfig, K as LockedMaintenanceJob, N as MaintenanceJob, P as MaintenanceStopReason, Q as MemoryDumpEntity, T as MigrationPolicy, U as ONTOLOGY_BACKFILL_BATCH_SIZE, V as ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, X as ONTOLOGY_BACKFILL_RECHECK_MS, Y as OntologyBackfillResult, Z as OntologyConfig, _ as OntologyEdgeType, $ as OntologyManifest, a0 as OntologyNodeType, a1 as OntologyPromptContext, a2 as OntologyUpdates, a3 as PendingMaintenance, a4 as PendingMigrationWork, a5 as PendingSourceStatus, a6 as PromptOverrides, a7 as PromptService, a8 as PrunePartialFailureError, a9 as ReembedResult, aa as RememberInput, ab as RunPendingMaintenanceOptions, ac as RunPendingMaintenanceResult, ad as SourcePassage, ae as StoreSourceResult, af as StoredSource, ag as StoredSourceDump, ah as StoredSourceSummary, ai as SupersedeReplacement, aj as VectorRanker, ak as VectorRankerFallback, al as VectorRankerRankArgs, am as VectorRankerSemanticResult, an as WikiBusyError, ao as WikiBusyOperation, ap as WikiCheckpoint, aq as WikiConfig, ar as WikiDiagnostic, as as WikiDiagnosticCode, at as WikiDiagnosticDetail, au as WikiDiagnosticOperation, av as WikiDiagnosticSeverity, aw as WikiDiagnosticTrigger, ax as WikiDraftNotFound, ay as WikiDuplicateHashError, az as WikiEdge, aA as WikiEvent, aB as WikiExternalDeletionError, aC as WikiFact, aD as WikiGraphNodeOwnershipConflict, aE as WikiIngestEmptyError, aF as WikiInstructions, aG as WikiInvalidReadOptions, aH as WikiLintReport, aI as WikiMemoryTestAccess, aJ as WikiMigrationRequiredError, aK as WikiOutboxEvent, aL as WikiParseError, aM as WikiSearchUnavailableError, aN as WikiSourcePointer, aO as WikiSourceRefHashCollision, aP as WikiStrictOntologyViolation, aQ as WikiSupersedeError, aR as WikiSupersedeReason, aS as WikiTask, aT as WikiTransactionError, aU as isWikiSearchUnavailableError, aV as validateManifest } from './testing-BZyrIoJp.js';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
 
5
5
  /**
package/dist/index.js CHANGED
@@ -248,10 +248,9 @@ var SQLITE_RESULT_CODE_NAMES = {
248
248
  // 2067 = SQLITE_CONSTRAINT_UNIQUE — a UNIQUE index rejecting an INSERT/UPDATE.
249
249
  // better-sqlite3 / node:sqlite enable extended result codes and report it
250
250
  // directly. expo-sqlite never emits it (as of expo-sqlite 58.0.14, per
251
- // #403): it leaves extended result codes off
252
- // and surfaces the same failure as the primary code 19 with the
253
- // "UNIQUE constraint failed" message text, which `extractSqliteCode` below
254
- // refines back to this name (#403).
251
+ // #403): it leaves extended result codes off and surfaces the same failure
252
+ // as the primary code 19 with the "UNIQUE constraint failed" message text,
253
+ // which `extractSqliteCode` below refines back to this name (#403).
255
254
  2067: "SQLITE_CONSTRAINT_UNIQUE",
256
255
  // 267 = SQLITE_CORRUPT_VTAB — a corrupt FTS5 shadow table (ftsCorruptionClass).
257
256
  267: "SQLITE_CORRUPT_VTAB",
@@ -2527,6 +2526,59 @@ var _EntryRepository = class _EntryRepository extends BaseRepository {
2527
2526
  }
2528
2527
  return result.changes;
2529
2528
  }
2529
+ /**
2530
+ * IDs of the entity's entries whose source_pointer names the event id.
2531
+ * `includeDeleted = true` returns live + tombstoned rows (the forget
2532
+ * enumeration superset for index sync and the ledger backstop).
2533
+ */
2534
+ async findIdsByPointerEvent(entityId, eventId, tx, includeDeleted = false) {
2535
+ const executor = this.getExecutor(tx);
2536
+ let sql = `SELECT id FROM ${this.prefix}entries WHERE entity_id = ? AND ${_EntryRepository.POINTER_EVENT_MATCH_SQL}`;
2537
+ const args = [entityId, eventId];
2538
+ if (!includeDeleted) sql += ` AND deleted_at IS NULL`;
2539
+ const rows = await executor.getAllAsync(sql, args);
2540
+ return rows.map((r) => r.id);
2541
+ }
2542
+ /** Live-row count for the event id — dry-run only (a real call is idempotent over tombstones). */
2543
+ async countLiveByPointerEvent(entityId, eventId, tx) {
2544
+ const executor = this.getExecutor(tx);
2545
+ const row = await executor.getFirstAsync(
2546
+ `SELECT COUNT(*) AS n FROM ${this.prefix}entries WHERE entity_id = ? AND deleted_at IS NULL AND ${_EntryRepository.POINTER_EVENT_MATCH_SQL}`,
2547
+ [entityId, eventId]
2548
+ );
2549
+ return row?.n ?? 0;
2550
+ }
2551
+ /**
2552
+ * Soft-delete the entity's entries whose source_pointer names the event id,
2553
+ * within a transaction. Stages a DELETE outbox entry for each row that
2554
+ * changed, in the same transaction (parity with softDeleteBySource — synced
2555
+ * replicas learn of the tombstones through the outbox). The `deleted_at
2556
+ * IS NULL` guard makes the call idempotent: already-tombstoned rows are
2557
+ * no-op hits and are not counted. `tx` is REQUIRED.
2558
+ * Returns the number of rows deleted.
2559
+ */
2560
+ async softDeleteByPointerEvent(entityId, eventId, tx) {
2561
+ const executor = this.getExecutor(tx);
2562
+ const now = Date.now();
2563
+ const idsToDelete = await executor.getAllAsync(
2564
+ `SELECT id FROM ${this.prefix}entries WHERE entity_id = ? AND deleted_at IS NULL AND ${_EntryRepository.POINTER_EVENT_MATCH_SQL}`,
2565
+ [entityId, eventId]
2566
+ );
2567
+ const result = await executor.runAsync(
2568
+ `UPDATE ${this.prefix}entries SET deleted_at = ?, updated_at = ? WHERE entity_id = ? AND deleted_at IS NULL AND ${_EntryRepository.POINTER_EVENT_MATCH_SQL}`,
2569
+ [now, now, entityId, eventId]
2570
+ );
2571
+ for (const row of idsToDelete) {
2572
+ await this.outbox.push({
2573
+ entityId,
2574
+ tableName: "entries",
2575
+ recordId: row.id,
2576
+ operation: "DELETE",
2577
+ payload: { id: row.id, entity_id: entityId, deleted_at: now }
2578
+ }, tx);
2579
+ }
2580
+ return result.changes;
2581
+ }
2530
2582
  /**
2531
2583
  * Fetch IDs + entity_ids of soft-deleted rows older than cutoff for a given entity.
2532
2584
  * Used by runPrune().
@@ -3551,6 +3603,18 @@ var _EntryRepository = class _EntryRepository extends BaseRepository {
3551
3603
  */
3552
3604
  _EntryRepository.MINI_SEARCH_COLUMNS = "id, entity_id, title, body, tags";
3553
3605
  _EntryRepository.MINI_SEARCH_LIVE_WHERE = "WHERE deleted_at IS NULL";
3606
+ /**
3607
+ * Shared JSON match predicate for source_pointer event ids
3608
+ * (specs/forget-by-event-id §D1). Every JSON call sits under the single
3609
+ * `json_valid` guard: unguarded JSON functions RAISE on malformed text, and
3610
+ * three-valued logic forces evaluation of AND operands after a NULL-guarded
3611
+ * term — a two-term form is only as safe as the planner's term-splitting.
3612
+ * The tombstone guard (`deleted_at IS NULL`) is added per-method.
3613
+ */
3614
+ _EntryRepository.POINTER_EVENT_MATCH_SQL = `CASE WHEN json_valid(source_pointer)
3615
+ THEN json_type(source_pointer, '$.event_id') = 'text'
3616
+ AND json_extract(source_pointer, '$.event_id') = ?
3617
+ ELSE 0 END`;
3554
3618
  var EntryRepository = _EntryRepository;
3555
3619
 
3556
3620
  // src/utils/ids.ts
@@ -7393,6 +7457,47 @@ Return ONLY a valid JSON object matching this schema:
7393
7457
  }
7394
7458
  If no manifest type fits a fact, omit that fact from "classifications" entirely \u2014 do not guess.
7395
7459
  When echoing an existing fact's title verbatim into "target_title", preserve every JSON escape sequence (\\", \\n, \\\\, \\/) exactly as it appeared in the input body \u2014 do not strip backslashes, do not add unescaped quotes. Do not return markdown, just raw JSON.`;
7460
+ var TITLE_CATALOG_MAX_ENTRIES = 200;
7461
+ function buildTitleCatalogBlock(rows) {
7462
+ const byKey = /* @__PURE__ */ new Map();
7463
+ for (const r of rows) {
7464
+ if (typeof r.title !== "string" || r.title.length === 0) continue;
7465
+ if (typeof r.okf_type !== "string" || r.okf_type.length === 0) continue;
7466
+ byKey.set(normalizeTitleKey(r.title), { title: r.title, okf_type: r.okf_type });
7467
+ }
7468
+ const typed = [...byKey.values()].sort((a, b) => a.title < b.title ? -1 : a.title > b.title ? 1 : 0);
7469
+ const CHAR_BUDGET = 8e3;
7470
+ const listed = [];
7471
+ let used = 0;
7472
+ for (const r of typed) {
7473
+ const line = `- ${JSON.stringify(r.title)} (${r.okf_type})`;
7474
+ if (line.length + 1 > CHAR_BUDGET) continue;
7475
+ if (listed.length >= TITLE_CATALOG_MAX_ENTRIES) break;
7476
+ if (used + line.length + 1 > CHAR_BUDGET) continue;
7477
+ listed.push(r);
7478
+ used += line.length + 1;
7479
+ }
7480
+ const truncated = typed.length > listed.length;
7481
+ if (typed.length === 0) {
7482
+ return [
7483
+ "TITLE CATALOG: this memory contains no typed nodes yet.",
7484
+ 'A fact classified in this same response is a valid "target_title" once typed. Otherwise omit "edges" rather than invent a target_title.'
7485
+ ].join("\n");
7486
+ }
7487
+ if (listed.length === 0) {
7488
+ return [
7489
+ "TITLE CATALOG: existing typed nodes exist in this memory, but none fit the catalog budget.",
7490
+ 'A fact classified in this same response is a valid "target_title" once typed. Otherwise omit "edges" rather than invent a target_title.'
7491
+ ].join("\n");
7492
+ }
7493
+ const catalog = listed.map((r) => `- ${JSON.stringify(r.title)} (${r.okf_type})`).join("\n");
7494
+ return [
7495
+ "TITLE CATALOG: existing typed nodes in this memory include:",
7496
+ catalog,
7497
+ ...truncated ? ["(This list is truncated; more typed nodes exist than are shown here.)"] : [],
7498
+ 'A "target_title" may be copied verbatim from this catalog, or be another fact classified in this same response. If no valid target exists, omit "edges" rather than invent a target_title.'
7499
+ ].join("\n");
7500
+ }
7396
7501
  var GROUNDING_SOURCE = {
7397
7502
  ingest: { key: "facts", source: "the document chunk" },
7398
7503
  librarian: { key: "facts", source: 'the "summary" text of the events' },
@@ -7669,7 +7774,7 @@ The following document anchors are provided for contradiction detection only. Do
7669
7774
  ...corpusField
7670
7775
  };
7671
7776
  }
7672
- buildOntologyBackfillPrompt(facts, runtimeOverride, ontologyContext) {
7777
+ buildOntologyBackfillPrompt(facts, runtimeOverride, ontologyContext, titleCatalog) {
7673
7778
  const template = runtimeOverride ?? this.globalOverrides?.ontologyBackfillSystemPrompt ?? ONTOLOGY_BACKFILL_SYSTEM_PROMPT;
7674
7779
  const hasFacts = /\{\{\s*facts\s*\}\}/.test(template);
7675
7780
  if (hasFacts || this.hasOntologyPlaceholders(template)) {
@@ -7679,8 +7784,11 @@ The following document anchors are provided for contradiction detection only. Do
7679
7784
  ${JSON.stringify(facts, null, 2)}`
7680
7785
  };
7681
7786
  }
7787
+ const effective = titleCatalog !== void 0 ? `${template}
7788
+
7789
+ ${titleCatalog}` : template;
7682
7790
  return {
7683
- systemPrompt: this.appendOntology(template, ontologyContext),
7791
+ systemPrompt: this.appendOntology(effective, ontologyContext),
7684
7792
  userPrompt: `Facts:
7685
7793
  ${JSON.stringify(facts, null, 2)}`
7686
7794
  };
@@ -10894,15 +11002,21 @@ DROP TRIGGER IF EXISTS ${ad};`);
10894
11002
  }
10895
11003
  }
10896
11004
  async forget(entityId, params, opts) {
10897
- if (params.clearAll && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
10898
- throw new Error("forget() clearAll is mutually exclusive with entryId, taskId, sourceRef, and sourceHash");
11005
+ if (params.clearAll && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0 || params.eventId !== void 0)) {
11006
+ throw new Error("forget() clearAll is mutually exclusive with entryId, taskId, sourceRef, sourceHash, and eventId");
10899
11007
  }
10900
11008
  if (params.includeEvents && !params.clearAll) {
10901
11009
  throw new Error("forget() includeEvents requires clearAll: true");
10902
11010
  }
10903
- if (params.includeChain && (params.entryId === void 0 || params.clearAll || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
11011
+ if (params.includeChain && (params.entryId === void 0 || params.clearAll || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0 || params.eventId !== void 0)) {
10904
11012
  throw new Error("forget() includeChain composes only with entryId");
10905
11013
  }
11014
+ if (params.eventId !== void 0 && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
11015
+ throw new Error("forget() eventId is mutually exclusive with entryId, taskId, sourceRef, and sourceHash");
11016
+ }
11017
+ if (params.eventId !== void 0 && (typeof params.eventId !== "string" || params.eventId === "")) {
11018
+ throw new Error("Invalid eventId");
11019
+ }
10906
11020
  if (opts?.dryRun === true) {
10907
11021
  return this.forgetDryRun(entityId, params);
10908
11022
  }
@@ -10970,14 +11084,19 @@ DROP TRIGGER IF EXISTS ${ad};`);
10970
11084
  if (sourceRef || sourceHash) {
10971
11085
  for (const id of await this.entryRepo.findIdsBySource(entityId, sourceRef, sourceHash, tx, true)) deletedEntryIds.push(id);
10972
11086
  }
11087
+ if (params.eventId !== void 0) {
11088
+ for (const id of await this.entryRepo.findIdsByPointerEvent(entityId, params.eventId, tx, true)) deletedEntryIds.push(id);
11089
+ }
10973
11090
  const entryPromise = params.entryId ? this.entryRepo.softDelete(params.entryId, entityId, tx).then((r) => r.changes > 0) : null;
10974
11091
  const taskDeletedPromise = params.taskId ? this.taskRepo.softDeleteById(params.taskId, entityId, tx).then((r) => r.changes > 0) : null;
10975
11092
  const refPromise = sourceRef || sourceHash ? this.entryRepo.softDeleteBySource(entityId, tx, sourceRef, sourceHash) : null;
11093
+ const pointerPromise = params.eventId !== void 0 ? this.entryRepo.softDeleteByPointerEvent(entityId, params.eventId, tx) : null;
10976
11094
  const sourceRefIndexPromise = touchSourceRefIndex && sourceRef ? this.sourceRefIndexRepo.softDeleteByEntityAndSourceRef(entityId, sourceRef, tx).then(() => void 0) : null;
10977
- const [entryResult, taskResult, refResult] = await Promise.all([
11095
+ const [entryResult, taskResult, refResult, pointerResult] = await Promise.all([
10978
11096
  entryPromise ?? Promise.resolve(false),
10979
11097
  taskDeletedPromise ?? Promise.resolve(false),
10980
11098
  refPromise ?? Promise.resolve(0),
11099
+ pointerPromise ?? Promise.resolve(0),
10981
11100
  sourceRefIndexPromise ?? Promise.resolve(void 0)
10982
11101
  ]);
10983
11102
  if (entryResult) deletedEntries++;
@@ -10986,6 +11105,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
10986
11105
  }
10987
11106
  if (taskResult) deletedTasks++;
10988
11107
  deletedEntries += refResult;
11108
+ deletedEntries += pointerResult;
10989
11109
  }
10990
11110
  if (ledgerOn && this.vectorRemoval?.gate() === "hook" && deletedEntryIds.length > 0) {
10991
11111
  await this.vectorRemovalRepo?.backstopEnqueue(entityId, Array.from(new Set(deletedEntryIds)), now, tx);
@@ -11131,7 +11251,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
11131
11251
  return out;
11132
11252
  }
11133
11253
  if (params.entryId !== void 0 || params.taskId !== void 0) {
11134
- throw new Error("forget({ dryRun: true }) does not support entryId/taskId selectors (entryId is accepted only with includeChain); use sourceRef/sourceHash or clearAll");
11254
+ throw new Error("forget({ dryRun: true }) does not support entryId/taskId selectors (entryId is accepted only with includeChain); use sourceRef/sourceHash, eventId, or clearAll");
11135
11255
  }
11136
11256
  if (params.clearAll) {
11137
11257
  const entries2 = await this.entryRepo.countLiveByEntityId(entityId);
@@ -11142,6 +11262,10 @@ DROP TRIGGER IF EXISTS ${ad};`);
11142
11262
  }
11143
11263
  return { deleted: { entries: entries2, tasks }, metadataReset: true };
11144
11264
  }
11265
+ if (params.eventId !== void 0) {
11266
+ const entries2 = await this.entryRepo.countLiveByPointerEvent(entityId, params.eventId);
11267
+ return { deleted: { entries: entries2, tasks: 0 } };
11268
+ }
11145
11269
  const sourceRef = params.sourceRef !== void 0 ? normalizeSourceRef(params.sourceRef) : null;
11146
11270
  if (params.sourceRef !== void 0 && !sourceRef) throw new Error("Invalid sourceRef");
11147
11271
  const sourceHash = params.sourceHash !== void 0 ? normalizeSourceHash(params.sourceHash) : null;
@@ -11548,11 +11672,14 @@ DROP TRIGGER IF EXISTS ${ad};`);
11548
11672
  }
11549
11673
  }
11550
11674
  const ontologyContext = await ontologyService.buildPromptContext(entityId);
11675
+ const titleRows = await this.entryRepo.findTitleIndexByEntityId(entityId);
11676
+ const titleCatalog = buildTitleCatalogBlock(titleRows);
11551
11677
  const toPromptShape = (f) => ({ id: f.id, title: f.title, body: f.body, tags: f.tags });
11552
11678
  const buildPrompt = (facts) => this.promptService.buildOntologyBackfillPrompt(
11553
11679
  facts.map(toPromptShape),
11554
11680
  options?.promptOverride,
11555
- ontologyContext
11681
+ ontologyContext,
11682
+ titleCatalog
11556
11683
  );
11557
11684
  const outcome = await runBatched({
11558
11685
  items: candidates,
@@ -15687,7 +15814,8 @@ var WikiMemory = class {
15687
15814
  }
15688
15815
  }
15689
15816
  /**
15690
- * Soft-delete facts and tasks by id, by source, or all of them (`clearAll`).
15817
+ * Soft-delete facts and tasks by id, by source, by source-pointer event id,
15818
+ * or all of them (`clearAll`).
15691
15819
  * `clearAll` also deletes the entity's edges and its source-ref index rows.
15692
15820
  * Add `includeEvents: true` to `clearAll` to hard-delete every event too,
15693
15821
  * read or not, and reset the librarian's position: without it a later