@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/README.md CHANGED
@@ -60,7 +60,7 @@ The [Node.js quickstart](https://equationalapplications.github.io/expo-llm-wiki/
60
60
  | [@equationalapplications/core-okf](https://github.com/equationalapplications/expo-llm-wiki/blob/main/packages/okf/README.md) | Zero-dependency Open Knowledge Format (OKF) v0.1 + v0.2 primitives — parse and produce interoperable knowledge bundles. |
61
61
  | [@equationalapplications/schema-org-llm-wiki](https://github.com/equationalapplications/expo-llm-wiki/blob/main/packages/schema-org/README.md) | Curated schema.org warm-agent ontology manifest |
62
62
  | [@equationalapplications/schema-software-org](https://github.com/equationalapplications/expo-llm-wiki/blob/main/packages/schema-software-org/README.md) | Software-organization executive ontology manifest — 21 node types, 42 edges, warm-agent superset, data-only |
63
- | [@equationalapplications/mcp-server](https://github.com/equationalapplications/expo-llm-wiki/blob/main/packages/mcp-server/README.md) | MCP server exposing SynapseTree memory tools to coding agents |
63
+ | [@equationalapplications/mcp-server](https://github.com/equationalapplications/expo-llm-wiki/blob/main/packages/mcp-server/README.md) | MCP server exposing hosted cloud memory tools to coding agents |
64
64
 
65
65
  ## License
66
66
 
@@ -42,10 +42,9 @@ var SQLITE_RESULT_CODE_NAMES = {
42
42
  // 2067 = SQLITE_CONSTRAINT_UNIQUE — a UNIQUE index rejecting an INSERT/UPDATE.
43
43
  // better-sqlite3 / node:sqlite enable extended result codes and report it
44
44
  // directly. expo-sqlite never emits it (as of expo-sqlite 58.0.14, per
45
- // #403): it leaves extended result codes off
46
- // and surfaces the same failure as the primary code 19 with the
47
- // "UNIQUE constraint failed" message text, which `extractSqliteCode` below
48
- // refines back to this name (#403).
45
+ // #403): it leaves extended result codes off and surfaces the same failure
46
+ // as the primary code 19 with the "UNIQUE constraint failed" message text,
47
+ // which `extractSqliteCode` below refines back to this name (#403).
49
48
  2067: "SQLITE_CONSTRAINT_UNIQUE",
50
49
  // 267 = SQLITE_CORRUPT_VTAB — a corrupt FTS5 shadow table (ftsCorruptionClass).
51
50
  267: "SQLITE_CORRUPT_VTAB",
@@ -2252,6 +2251,47 @@ Return ONLY a valid JSON object matching this schema:
2252
2251
  }
2253
2252
  If no manifest type fits a fact, omit that fact from "classifications" entirely \u2014 do not guess.
2254
2253
  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.`;
2254
+ var TITLE_CATALOG_MAX_ENTRIES = 200;
2255
+ function buildTitleCatalogBlock(rows) {
2256
+ const byKey = /* @__PURE__ */ new Map();
2257
+ for (const r of rows) {
2258
+ if (typeof r.title !== "string" || r.title.length === 0) continue;
2259
+ if (typeof r.okf_type !== "string" || r.okf_type.length === 0) continue;
2260
+ byKey.set(normalizeTitleKey(r.title), { title: r.title, okf_type: r.okf_type });
2261
+ }
2262
+ const typed = [...byKey.values()].sort((a, b) => a.title < b.title ? -1 : a.title > b.title ? 1 : 0);
2263
+ const CHAR_BUDGET = 8e3;
2264
+ const listed = [];
2265
+ let used = 0;
2266
+ for (const r of typed) {
2267
+ const line = `- ${JSON.stringify(r.title)} (${r.okf_type})`;
2268
+ if (line.length + 1 > CHAR_BUDGET) continue;
2269
+ if (listed.length >= TITLE_CATALOG_MAX_ENTRIES) break;
2270
+ if (used + line.length + 1 > CHAR_BUDGET) continue;
2271
+ listed.push(r);
2272
+ used += line.length + 1;
2273
+ }
2274
+ const truncated = typed.length > listed.length;
2275
+ if (typed.length === 0) {
2276
+ return [
2277
+ "TITLE CATALOG: this memory contains no typed nodes yet.",
2278
+ 'A fact classified in this same response is a valid "target_title" once typed. Otherwise omit "edges" rather than invent a target_title.'
2279
+ ].join("\n");
2280
+ }
2281
+ if (listed.length === 0) {
2282
+ return [
2283
+ "TITLE CATALOG: existing typed nodes exist in this memory, but none fit the catalog budget.",
2284
+ 'A fact classified in this same response is a valid "target_title" once typed. Otherwise omit "edges" rather than invent a target_title.'
2285
+ ].join("\n");
2286
+ }
2287
+ const catalog = listed.map((r) => `- ${JSON.stringify(r.title)} (${r.okf_type})`).join("\n");
2288
+ return [
2289
+ "TITLE CATALOG: existing typed nodes in this memory include:",
2290
+ catalog,
2291
+ ...truncated ? ["(This list is truncated; more typed nodes exist than are shown here.)"] : [],
2292
+ '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.'
2293
+ ].join("\n");
2294
+ }
2255
2295
  var GROUNDING_SOURCE = {
2256
2296
  ingest: { key: "facts", source: "the document chunk" },
2257
2297
  librarian: { key: "facts", source: 'the "summary" text of the events' },
@@ -2582,7 +2622,7 @@ The following document anchors are provided for contradiction detection only. Do
2582
2622
  ...corpusField
2583
2623
  };
2584
2624
  }
2585
- buildOntologyBackfillPrompt(facts, runtimeOverride, ontologyContext) {
2625
+ buildOntologyBackfillPrompt(facts, runtimeOverride, ontologyContext, titleCatalog) {
2586
2626
  const template = runtimeOverride ?? this.globalOverrides?.ontologyBackfillSystemPrompt ?? ONTOLOGY_BACKFILL_SYSTEM_PROMPT;
2587
2627
  const hasFacts = /\{\{\s*facts\s*\}\}/.test(template);
2588
2628
  if (hasFacts || this.hasOntologyPlaceholders(template)) {
@@ -2592,8 +2632,11 @@ The following document anchors are provided for contradiction detection only. Do
2592
2632
  ${JSON.stringify(facts, null, 2)}`
2593
2633
  };
2594
2634
  }
2635
+ const effective = titleCatalog !== void 0 ? `${template}
2636
+
2637
+ ${titleCatalog}` : template;
2595
2638
  return {
2596
- systemPrompt: this.appendOntology(template, ontologyContext),
2639
+ systemPrompt: this.appendOntology(effective, ontologyContext),
2597
2640
  userPrompt: `Facts:
2598
2641
  ${JSON.stringify(facts, null, 2)}`
2599
2642
  };
@@ -7168,15 +7211,21 @@ DROP TRIGGER IF EXISTS ${ad};`);
7168
7211
  }
7169
7212
  }
7170
7213
  async forget(entityId, params, opts) {
7171
- if (params.clearAll && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
7172
- throw new Error("forget() clearAll is mutually exclusive with entryId, taskId, sourceRef, and sourceHash");
7214
+ if (params.clearAll && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0 || params.eventId !== void 0)) {
7215
+ throw new Error("forget() clearAll is mutually exclusive with entryId, taskId, sourceRef, sourceHash, and eventId");
7173
7216
  }
7174
7217
  if (params.includeEvents && !params.clearAll) {
7175
7218
  throw new Error("forget() includeEvents requires clearAll: true");
7176
7219
  }
7177
- if (params.includeChain && (params.entryId === void 0 || params.clearAll || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
7220
+ 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)) {
7178
7221
  throw new Error("forget() includeChain composes only with entryId");
7179
7222
  }
7223
+ if (params.eventId !== void 0 && (params.entryId !== void 0 || params.taskId !== void 0 || params.sourceRef !== void 0 || params.sourceHash !== void 0)) {
7224
+ throw new Error("forget() eventId is mutually exclusive with entryId, taskId, sourceRef, and sourceHash");
7225
+ }
7226
+ if (params.eventId !== void 0 && (typeof params.eventId !== "string" || params.eventId === "")) {
7227
+ throw new Error("Invalid eventId");
7228
+ }
7180
7229
  if (opts?.dryRun === true) {
7181
7230
  return this.forgetDryRun(entityId, params);
7182
7231
  }
@@ -7244,14 +7293,19 @@ DROP TRIGGER IF EXISTS ${ad};`);
7244
7293
  if (sourceRef || sourceHash) {
7245
7294
  for (const id of await this.entryRepo.findIdsBySource(entityId, sourceRef, sourceHash, tx, true)) deletedEntryIds.push(id);
7246
7295
  }
7296
+ if (params.eventId !== void 0) {
7297
+ for (const id of await this.entryRepo.findIdsByPointerEvent(entityId, params.eventId, tx, true)) deletedEntryIds.push(id);
7298
+ }
7247
7299
  const entryPromise = params.entryId ? this.entryRepo.softDelete(params.entryId, entityId, tx).then((r) => r.changes > 0) : null;
7248
7300
  const taskDeletedPromise = params.taskId ? this.taskRepo.softDeleteById(params.taskId, entityId, tx).then((r) => r.changes > 0) : null;
7249
7301
  const refPromise = sourceRef || sourceHash ? this.entryRepo.softDeleteBySource(entityId, tx, sourceRef, sourceHash) : null;
7302
+ const pointerPromise = params.eventId !== void 0 ? this.entryRepo.softDeleteByPointerEvent(entityId, params.eventId, tx) : null;
7250
7303
  const sourceRefIndexPromise = touchSourceRefIndex && sourceRef ? this.sourceRefIndexRepo.softDeleteByEntityAndSourceRef(entityId, sourceRef, tx).then(() => void 0) : null;
7251
- const [entryResult, taskResult, refResult] = await Promise.all([
7304
+ const [entryResult, taskResult, refResult, pointerResult] = await Promise.all([
7252
7305
  entryPromise ?? Promise.resolve(false),
7253
7306
  taskDeletedPromise ?? Promise.resolve(false),
7254
7307
  refPromise ?? Promise.resolve(0),
7308
+ pointerPromise ?? Promise.resolve(0),
7255
7309
  sourceRefIndexPromise ?? Promise.resolve(void 0)
7256
7310
  ]);
7257
7311
  if (entryResult) deletedEntries++;
@@ -7260,6 +7314,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
7260
7314
  }
7261
7315
  if (taskResult) deletedTasks++;
7262
7316
  deletedEntries += refResult;
7317
+ deletedEntries += pointerResult;
7263
7318
  }
7264
7319
  if (ledgerOn && this.vectorRemoval?.gate() === "hook" && deletedEntryIds.length > 0) {
7265
7320
  await this.vectorRemovalRepo?.backstopEnqueue(entityId, Array.from(new Set(deletedEntryIds)), now, tx);
@@ -7405,7 +7460,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
7405
7460
  return out;
7406
7461
  }
7407
7462
  if (params.entryId !== void 0 || params.taskId !== void 0) {
7408
- throw new Error("forget({ dryRun: true }) does not support entryId/taskId selectors (entryId is accepted only with includeChain); use sourceRef/sourceHash or clearAll");
7463
+ throw new Error("forget({ dryRun: true }) does not support entryId/taskId selectors (entryId is accepted only with includeChain); use sourceRef/sourceHash, eventId, or clearAll");
7409
7464
  }
7410
7465
  if (params.clearAll) {
7411
7466
  const entries2 = await this.entryRepo.countLiveByEntityId(entityId);
@@ -7416,6 +7471,10 @@ DROP TRIGGER IF EXISTS ${ad};`);
7416
7471
  }
7417
7472
  return { deleted: { entries: entries2, tasks }, metadataReset: true };
7418
7473
  }
7474
+ if (params.eventId !== void 0) {
7475
+ const entries2 = await this.entryRepo.countLiveByPointerEvent(entityId, params.eventId);
7476
+ return { deleted: { entries: entries2, tasks: 0 } };
7477
+ }
7419
7478
  const sourceRef = params.sourceRef !== void 0 ? normalizeSourceRef(params.sourceRef) : null;
7420
7479
  if (params.sourceRef !== void 0 && !sourceRef) throw new Error("Invalid sourceRef");
7421
7480
  const sourceHash = params.sourceHash !== void 0 ? normalizeSourceHash(params.sourceHash) : null;
@@ -7822,11 +7881,14 @@ DROP TRIGGER IF EXISTS ${ad};`);
7822
7881
  }
7823
7882
  }
7824
7883
  const ontologyContext = await ontologyService.buildPromptContext(entityId);
7884
+ const titleRows = await this.entryRepo.findTitleIndexByEntityId(entityId);
7885
+ const titleCatalog = buildTitleCatalogBlock(titleRows);
7825
7886
  const toPromptShape = (f) => ({ id: f.id, title: f.title, body: f.body, tags: f.tags });
7826
7887
  const buildPrompt = (facts) => this.promptService.buildOntologyBackfillPrompt(
7827
7888
  facts.map(toPromptShape),
7828
7889
  options?.promptOverride,
7829
- ontologyContext
7890
+ ontologyContext,
7891
+ titleCatalog
7830
7892
  );
7831
7893
  const outcome = await runBatched({
7832
7894
  items: candidates,
@@ -10706,5 +10768,5 @@ var WriteService = class {
10706
10768
  };
10707
10769
 
10708
10770
  export { BaseRepository, CURRENT_SCHEMA_VERSION, CheckpointIncompleteError, DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DiagnosticBuffer, EMBED_CHARS_CEILING, EdgeRepository, EmbeddingService, EraseStepError, FTS5_DRAIN_CHUNK, FTS5_REBUILD_SNAPSHOT_KEY, FTS5_REBUILD_WM_KEY, FTS5_RECLAIM_MERGE_PAGES, FTS5_RETIRED_COUNTER_KEY, FTS5_RETIRED_TABLES_KEY, FTS5_STATE_KEY, FTS5_SWEEP_CURSOR_KEY, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ImportExportService, IngestionService, JobManager, MAX_EMBED_ATTEMPTS, MIGRATIONS, MaintenanceService, MetadataRepository, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, RetrievalService, SearchService, SourceStoreService, TemporalService, UnavailableIndexStrategy, UsageMeter, VectorRemovalRepository, VectorRemovalService, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiExternalDeletionError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, WriteService, __privateAdd, __privateGet, __privateSet, assertEntityId, assertEpochMs, chunkText, configureRandomSource, createLegacySourceTypeIndex, createdAtValue, detectSchemaVersion, drainChunkSql, drainHiSql, edgeTripleAllowed, emitDiagnostic, emptyManifest, entityDrainChunkSql, entityDrainHiSql, entitySummaryMetaKey, extractSqliteCode, factTokenCost, fts5LedgerDropSql, fts5PendingIndexesDdl, fts5TablesDdl, fts5TriggerNames, fts5TriggersDdl, generateId, idDrainChunkSql, idReindexChunkSql, isLiveAt, isRetiredTableName, isUsableDate, isWikiSearchUnavailableError, liveAtSql, normalizeSourceHash, normalizeSourceRef, normalizeTitleKey, packFactsByBudget, parseEmbedding, parseJsonArray, parseJsonObject, parseStoredSourcePointer, passageFtsTablesDdl, passageFtsTriggerNames, passageFtsTriggersDdl, probePendingWork, readRebuildProgress, reanchorRebuildFingerprint, resolveEdgeDefinitions, resolveGrounding, resolveLibrarianStrategy, resolveNodeType, retiredTableName, runSourceRefNormalize, safeSlice, serializeSourcePointer, setupDatabase, sweepChunkSql, sweepHiSql, typeSatisfies, validateInlineEdges, validateManifest, validateSourcePointerValue, warnChangedDefaultsOnce, windowChunkSql, windowHiSql, writeNormalizeStamp, writeRebuildStart };
10709
- //# sourceMappingURL=chunk-TRLMWC5G.mjs.map
10710
- //# sourceMappingURL=chunk-TRLMWC5G.mjs.map
10771
+ //# sourceMappingURL=chunk-Q6ZS2RKS.mjs.map
10772
+ //# sourceMappingURL=chunk-Q6ZS2RKS.mjs.map