@equationalapplications/core-llm-wiki 9.4.2 → 9.5.0

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.
@@ -1300,12 +1300,21 @@ interface ForgetParams {
1300
1300
  * predecessor and successor reached by walking `superseded_by` links, capped
1301
1301
  * at 100 per direction). The walk is NOT the connected component: with
1302
1302
  * fan-in A→C←B, forgetting A reaches C but not B. The forward walk deletes
1303
- * the live current fact. Does not compose with other selectors.
1303
+ * the live current fact. Does not compose with other selectors (including
1304
+ * `eventId`).
1304
1305
  */
1305
1306
  includeChain?: boolean;
1306
1307
  taskId?: string;
1307
1308
  sourceRef?: string;
1308
1309
  sourceHash?: string;
1310
+ /**
1311
+ * Soft-delete every librarian fact whose `source_pointer` names this event
1312
+ * id (entity-scoped; exact match, no normalization — event ids are
1313
+ * engine-generated). Mutually exclusive with every other selector;
1314
+ * `clearAll` excludes it. Removal reports through the return value and the
1315
+ * per-row outbox DELETE events. See `specs/forget-by-event-id/` (issue #386).
1316
+ */
1317
+ eventId?: string;
1309
1318
  /** Soft-delete every fact and task of the entity, delete its edges, and delete its source-ref index rows. */
1310
1319
  clearAll?: boolean;
1311
1320
  /**
@@ -1835,6 +1844,33 @@ declare class EntryRepository extends BaseRepository {
1835
1844
  * Returns the number of rows deleted.
1836
1845
  */
1837
1846
  softDeleteBySource(entityId: string, tx: SQLiteAdapter, sourceRef?: string | null, sourceHash?: string | null): Promise<number>;
1847
+ /**
1848
+ * Shared JSON match predicate for source_pointer event ids
1849
+ * (specs/forget-by-event-id §D1). Every JSON call sits under the single
1850
+ * `json_valid` guard: unguarded JSON functions RAISE on malformed text, and
1851
+ * three-valued logic forces evaluation of AND operands after a NULL-guarded
1852
+ * term — a two-term form is only as safe as the planner's term-splitting.
1853
+ * The tombstone guard (`deleted_at IS NULL`) is added per-method.
1854
+ */
1855
+ static readonly POINTER_EVENT_MATCH_SQL = "CASE WHEN json_valid(source_pointer)\n THEN json_type(source_pointer, '$.event_id') = 'text'\n AND json_extract(source_pointer, '$.event_id') = ?\n ELSE 0 END";
1856
+ /**
1857
+ * IDs of the entity's entries whose source_pointer names the event id.
1858
+ * `includeDeleted = true` returns live + tombstoned rows (the forget
1859
+ * enumeration superset for index sync and the ledger backstop).
1860
+ */
1861
+ findIdsByPointerEvent(entityId: string, eventId: string, tx?: SQLiteAdapter, includeDeleted?: boolean): Promise<string[]>;
1862
+ /** Live-row count for the event id — dry-run only (a real call is idempotent over tombstones). */
1863
+ countLiveByPointerEvent(entityId: string, eventId: string, tx?: SQLiteAdapter): Promise<number>;
1864
+ /**
1865
+ * Soft-delete the entity's entries whose source_pointer names the event id,
1866
+ * within a transaction. Stages a DELETE outbox entry for each row that
1867
+ * changed, in the same transaction (parity with softDeleteBySource — synced
1868
+ * replicas learn of the tombstones through the outbox). The `deleted_at
1869
+ * IS NULL` guard makes the call idempotent: already-tombstoned rows are
1870
+ * no-op hits and are not counted. `tx` is REQUIRED.
1871
+ * Returns the number of rows deleted.
1872
+ */
1873
+ softDeleteByPointerEvent(entityId: string, eventId: string, tx: SQLiteAdapter): Promise<number>;
1838
1874
  /**
1839
1875
  * Fetch IDs + entity_ids of soft-deleted rows older than cutoff for a given entity.
1840
1876
  * Used by runPrune().
@@ -4732,7 +4768,8 @@ declare class WikiMemory {
4732
4768
  merge?: boolean;
4733
4769
  }): Promise<ImportDumpResult>;
4734
4770
  /**
4735
- * Soft-delete facts and tasks by id, by source, or all of them (`clearAll`).
4771
+ * Soft-delete facts and tasks by id, by source, by source-pointer event id,
4772
+ * or all of them (`clearAll`).
4736
4773
  * `clearAll` also deletes the entity's edges and its source-ref index rows.
4737
4774
  * Add `includeEvents: true` to `clearAll` to hard-delete every event too,
4738
4775
  * read or not, and reset the librarian's position: without it a later
@@ -1300,12 +1300,21 @@ interface ForgetParams {
1300
1300
  * predecessor and successor reached by walking `superseded_by` links, capped
1301
1301
  * at 100 per direction). The walk is NOT the connected component: with
1302
1302
  * fan-in A→C←B, forgetting A reaches C but not B. The forward walk deletes
1303
- * the live current fact. Does not compose with other selectors.
1303
+ * the live current fact. Does not compose with other selectors (including
1304
+ * `eventId`).
1304
1305
  */
1305
1306
  includeChain?: boolean;
1306
1307
  taskId?: string;
1307
1308
  sourceRef?: string;
1308
1309
  sourceHash?: string;
1310
+ /**
1311
+ * Soft-delete every librarian fact whose `source_pointer` names this event
1312
+ * id (entity-scoped; exact match, no normalization — event ids are
1313
+ * engine-generated). Mutually exclusive with every other selector;
1314
+ * `clearAll` excludes it. Removal reports through the return value and the
1315
+ * per-row outbox DELETE events. See `specs/forget-by-event-id/` (issue #386).
1316
+ */
1317
+ eventId?: string;
1309
1318
  /** Soft-delete every fact and task of the entity, delete its edges, and delete its source-ref index rows. */
1310
1319
  clearAll?: boolean;
1311
1320
  /**
@@ -1835,6 +1844,33 @@ declare class EntryRepository extends BaseRepository {
1835
1844
  * Returns the number of rows deleted.
1836
1845
  */
1837
1846
  softDeleteBySource(entityId: string, tx: SQLiteAdapter, sourceRef?: string | null, sourceHash?: string | null): Promise<number>;
1847
+ /**
1848
+ * Shared JSON match predicate for source_pointer event ids
1849
+ * (specs/forget-by-event-id §D1). Every JSON call sits under the single
1850
+ * `json_valid` guard: unguarded JSON functions RAISE on malformed text, and
1851
+ * three-valued logic forces evaluation of AND operands after a NULL-guarded
1852
+ * term — a two-term form is only as safe as the planner's term-splitting.
1853
+ * The tombstone guard (`deleted_at IS NULL`) is added per-method.
1854
+ */
1855
+ static readonly POINTER_EVENT_MATCH_SQL = "CASE WHEN json_valid(source_pointer)\n THEN json_type(source_pointer, '$.event_id') = 'text'\n AND json_extract(source_pointer, '$.event_id') = ?\n ELSE 0 END";
1856
+ /**
1857
+ * IDs of the entity's entries whose source_pointer names the event id.
1858
+ * `includeDeleted = true` returns live + tombstoned rows (the forget
1859
+ * enumeration superset for index sync and the ledger backstop).
1860
+ */
1861
+ findIdsByPointerEvent(entityId: string, eventId: string, tx?: SQLiteAdapter, includeDeleted?: boolean): Promise<string[]>;
1862
+ /** Live-row count for the event id — dry-run only (a real call is idempotent over tombstones). */
1863
+ countLiveByPointerEvent(entityId: string, eventId: string, tx?: SQLiteAdapter): Promise<number>;
1864
+ /**
1865
+ * Soft-delete the entity's entries whose source_pointer names the event id,
1866
+ * within a transaction. Stages a DELETE outbox entry for each row that
1867
+ * changed, in the same transaction (parity with softDeleteBySource — synced
1868
+ * replicas learn of the tombstones through the outbox). The `deleted_at
1869
+ * IS NULL` guard makes the call idempotent: already-tombstoned rows are
1870
+ * no-op hits and are not counted. `tx` is REQUIRED.
1871
+ * Returns the number of rows deleted.
1872
+ */
1873
+ softDeleteByPointerEvent(entityId: string, eventId: string, tx: SQLiteAdapter): Promise<number>;
1838
1874
  /**
1839
1875
  * Fetch IDs + entity_ids of soft-deleted rows older than cutoff for a given entity.
1840
1876
  * Used by runPrune().
@@ -4732,7 +4768,8 @@ declare class WikiMemory {
4732
4768
  merge?: boolean;
4733
4769
  }): Promise<ImportDumpResult>;
4734
4770
  /**
4735
- * Soft-delete facts and tasks by id, by source, or all of them (`clearAll`).
4771
+ * Soft-delete facts and tasks by id, by source, by source-pointer event id,
4772
+ * or all of them (`clearAll`).
4736
4773
  * `clearAll` also deletes the entity's edges and its source-ref index rows.
4737
4774
  * Add `includeEvents: true` to `clearAll` to hard-delete every event too,
4738
4775
  * read or not, and reset the librarian's position: without it a later
@@ -1,2 +1,2 @@
1
- export { aW as EmbeddingService, aX as ImportExportService, aY as IngestionService, aZ as JobManager, aZ as JobManagerType, a_ as MaintenanceService, a$ as RetrievalService, b0 as SearchService, b0 as SearchServiceType, aI as WikiMemoryTestAccess, b1 as WriteService } from './testing-BVY5P6BS.mjs';
1
+ export { aW as EmbeddingService, aX as ImportExportService, aY as IngestionService, aZ as JobManager, aZ as JobManagerType, a_ as MaintenanceService, a$ as RetrievalService, b0 as SearchService, b0 as SearchServiceType, aI as WikiMemoryTestAccess, b1 as WriteService } from './testing-CTCRwhs0.mjs';
2
2
  import '@equationalapplications/core-okf';
package/dist/testing.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { aW as EmbeddingService, aX as ImportExportService, aY as IngestionService, aZ as JobManager, aZ as JobManagerType, a_ as MaintenanceService, a$ as RetrievalService, b0 as SearchService, b0 as SearchServiceType, aI as WikiMemoryTestAccess, b1 as WriteService } from './testing-BVY5P6BS.js';
1
+ export { aW as EmbeddingService, aX as ImportExportService, aY as IngestionService, aZ as JobManager, aZ as JobManagerType, a_ as MaintenanceService, a$ as RetrievalService, b0 as SearchService, b0 as SearchServiceType, aI as WikiMemoryTestAccess, b1 as WriteService } from './testing-CTCRwhs0.js';
2
2
  import '@equationalapplications/core-okf';
package/dist/testing.js CHANGED
@@ -33,10 +33,12 @@ var SQLITE_RESULT_CODE_NAMES = {
33
33
  27: "SQLITE_NOTICE",
34
34
  28: "SQLITE_WARNING",
35
35
  // Extended result codes (https://sqlite.org/rescode.html#extended_result_code_list).
36
- // 2067 = SQLITE_CONSTRAINT_UNIQUE — raised when a UNIQUE index/PRIMARY KEY
37
- // rejects an INSERT/UPDATE; expo-sqlite reports this as a numeric "Error code N:"
38
- // prefix and we normalize it back to the symbolic name so callers can branch on
39
- // the same string the rest of the ecosystem uses.
36
+ // 2067 = SQLITE_CONSTRAINT_UNIQUE — a UNIQUE index rejecting an INSERT/UPDATE.
37
+ // better-sqlite3 / node:sqlite enable extended result codes and report it
38
+ // directly. expo-sqlite never emits it (as of expo-sqlite 58.0.14, per
39
+ // #403): it leaves extended result codes off and surfaces the same failure
40
+ // as the primary code 19 with the "UNIQUE constraint failed" message text,
41
+ // which `extractSqliteCode` below refines back to this name (#403).
40
42
  2067: "SQLITE_CONSTRAINT_UNIQUE",
41
43
  // 267 = SQLITE_CORRUPT_VTAB — a corrupt FTS5 shadow table (ftsCorruptionClass).
42
44
  267: "SQLITE_CORRUPT_VTAB",
@@ -52,7 +54,13 @@ function extractSqliteCode(err) {
52
54
  if (typeof code === "string" && code.startsWith("SQLITE_")) return code;
53
55
  if (typeof message === "string") {
54
56
  const m = /^Error code (\d+):/.exec(message);
55
- if (m) return nameForSqliteResultCode(Number(m[1]));
57
+ if (m) {
58
+ const n = Number(m[1]);
59
+ if (n === 19 && message.includes("UNIQUE constraint failed")) {
60
+ return nameForSqliteResultCode(2067);
61
+ }
62
+ return nameForSqliteResultCode(n);
63
+ }
56
64
  }
57
65
  return void 0;
58
66
  }
@@ -6060,15 +6068,21 @@ DROP TRIGGER IF EXISTS ${ad};`);
6060
6068
  }
6061
6069
  }
6062
6070
  async forget(entityId, params, opts) {
6063
- if (params.clearAll && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
6064
- throw new Error("forget() clearAll is mutually exclusive with entryId, taskId, sourceRef, and sourceHash");
6071
+ if (params.clearAll && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0 || params.eventId !== void 0)) {
6072
+ throw new Error("forget() clearAll is mutually exclusive with entryId, taskId, sourceRef, sourceHash, and eventId");
6065
6073
  }
6066
6074
  if (params.includeEvents && !params.clearAll) {
6067
6075
  throw new Error("forget() includeEvents requires clearAll: true");
6068
6076
  }
6069
- if (params.includeChain && (params.entryId === void 0 || params.clearAll || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
6077
+ 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)) {
6070
6078
  throw new Error("forget() includeChain composes only with entryId");
6071
6079
  }
6080
+ if (params.eventId !== void 0 && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
6081
+ throw new Error("forget() eventId is mutually exclusive with entryId, taskId, sourceRef, and sourceHash");
6082
+ }
6083
+ if (params.eventId !== void 0 && (typeof params.eventId !== "string" || params.eventId === "")) {
6084
+ throw new Error("Invalid eventId");
6085
+ }
6072
6086
  if (opts?.dryRun === true) {
6073
6087
  return this.forgetDryRun(entityId, params);
6074
6088
  }
@@ -6136,14 +6150,19 @@ DROP TRIGGER IF EXISTS ${ad};`);
6136
6150
  if (sourceRef || sourceHash) {
6137
6151
  for (const id of await this.entryRepo.findIdsBySource(entityId, sourceRef, sourceHash, tx, true)) deletedEntryIds.push(id);
6138
6152
  }
6153
+ if (params.eventId !== void 0) {
6154
+ for (const id of await this.entryRepo.findIdsByPointerEvent(entityId, params.eventId, tx, true)) deletedEntryIds.push(id);
6155
+ }
6139
6156
  const entryPromise = params.entryId ? this.entryRepo.softDelete(params.entryId, entityId, tx).then((r) => r.changes > 0) : null;
6140
6157
  const taskDeletedPromise = params.taskId ? this.taskRepo.softDeleteById(params.taskId, entityId, tx).then((r) => r.changes > 0) : null;
6141
6158
  const refPromise = sourceRef || sourceHash ? this.entryRepo.softDeleteBySource(entityId, tx, sourceRef, sourceHash) : null;
6159
+ const pointerPromise = params.eventId !== void 0 ? this.entryRepo.softDeleteByPointerEvent(entityId, params.eventId, tx) : null;
6142
6160
  const sourceRefIndexPromise = touchSourceRefIndex && sourceRef ? this.sourceRefIndexRepo.softDeleteByEntityAndSourceRef(entityId, sourceRef, tx).then(() => void 0) : null;
6143
- const [entryResult, taskResult, refResult] = await Promise.all([
6161
+ const [entryResult, taskResult, refResult, pointerResult] = await Promise.all([
6144
6162
  entryPromise ?? Promise.resolve(false),
6145
6163
  taskDeletedPromise ?? Promise.resolve(false),
6146
6164
  refPromise ?? Promise.resolve(0),
6165
+ pointerPromise ?? Promise.resolve(0),
6147
6166
  sourceRefIndexPromise ?? Promise.resolve(void 0)
6148
6167
  ]);
6149
6168
  if (entryResult) deletedEntries++;
@@ -6152,6 +6171,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
6152
6171
  }
6153
6172
  if (taskResult) deletedTasks++;
6154
6173
  deletedEntries += refResult;
6174
+ deletedEntries += pointerResult;
6155
6175
  }
6156
6176
  if (ledgerOn && this.vectorRemoval?.gate() === "hook" && deletedEntryIds.length > 0) {
6157
6177
  await this.vectorRemovalRepo?.backstopEnqueue(entityId, Array.from(new Set(deletedEntryIds)), now, tx);
@@ -6297,7 +6317,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
6297
6317
  return out;
6298
6318
  }
6299
6319
  if (params.entryId !== void 0 || params.taskId !== void 0) {
6300
- throw new Error("forget({ dryRun: true }) does not support entryId/taskId selectors (entryId is accepted only with includeChain); use sourceRef/sourceHash or clearAll");
6320
+ throw new Error("forget({ dryRun: true }) does not support entryId/taskId selectors (entryId is accepted only with includeChain); use sourceRef/sourceHash, eventId, or clearAll");
6301
6321
  }
6302
6322
  if (params.clearAll) {
6303
6323
  const entries2 = await this.entryRepo.countLiveByEntityId(entityId);
@@ -6308,6 +6328,10 @@ DROP TRIGGER IF EXISTS ${ad};`);
6308
6328
  }
6309
6329
  return { deleted: { entries: entries2, tasks }, metadataReset: true };
6310
6330
  }
6331
+ if (params.eventId !== void 0) {
6332
+ const entries2 = await this.entryRepo.countLiveByPointerEvent(entityId, params.eventId);
6333
+ return { deleted: { entries: entries2, tasks: 0 } };
6334
+ }
6311
6335
  const sourceRef = params.sourceRef !== void 0 ? normalizeSourceRef(params.sourceRef) : null;
6312
6336
  if (params.sourceRef !== void 0 && !sourceRef) throw new Error("Invalid sourceRef");
6313
6337
  const sourceHash = params.sourceHash !== void 0 ? normalizeSourceHash(params.sourceHash) : null;