@equationalapplications/core-llm-wiki 8.0.4 → 8.1.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.
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { BaseRepository, WikiGraphNodeOwnershipConflict, parseJsonObject, parseJsonArray, liveAtSql, reanchorRebuildFingerprint, __privateAdd, warnChangedDefaultsOnce, MetadataRepository, EmbeddingService, SearchService, TemporalService, JobManager, PromptService, resolveGrounding, IngestionService, MaintenanceService, ImportExportService, RetrievalService, WriteService, __privateGet, __privateSet, createLegacySourceTypeIndex, writeNormalizeStamp, CURRENT_SCHEMA_VERSION, detectSchemaVersion, MIGRATIONS, runSourceRefNormalize, normalizeSourceRef, normalizeSourceHash, resolveLibrarianStrategy, entitySummaryMetaKey, WikiSourceRefHashCollision, DiagnosticBuffer, validateManifest, WikiDraftNotFound, generateId, emptyManifest, resolveNodeType, WikiStrictOntologyViolation, validateInlineEdges, resolveEdgeDefinitions, typeSatisfies, normalizeTitleKey, edgeTripleAllowed, MAX_EMBED_ATTEMPTS, UsageMeter, isWikiSearchUnavailableError, WikiBusyError, WikiInvalidReadOptions, isLiveAt, packFactsByBudget, factTokenCost, probePendingWork, WikiMigrationRequiredError, setupDatabase, UnavailableIndexStrategy, assertEntityId, assertEpochMs, FTS5_STATE_KEY, fts5LedgerDropSql, fts5TablesDdl, fts5PendingIndexesDdl, fts5TriggersDdl, writeRebuildStart, FTS5_RETIRED_COUNTER_KEY, retiredTableName, FTS5_RETIRED_TABLES_KEY, isRetiredTableName, idReindexChunkSql, readRebuildProgress, FTS5_DRAIN_CHUNK, FTS5_RECLAIM_MERGE_PAGES, windowHiSql, windowChunkSql, FTS5_REBUILD_WM_KEY, sweepHiSql, sweepChunkSql, FTS5_SWEEP_CURSOR_KEY, drainHiSql, drainChunkSql, FTS5_REBUILD_SNAPSHOT_KEY, idDrainChunkSql, entityDrainHiSql, entityDrainChunkSql, fts5TriggerNames, extractSqliteCode, WikiTransactionError } from './chunk-2N5SNDS3.mjs';
2
- export { DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, EMBED_CHARS_CEILING, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, chunkText, configureRandomSource, isWikiSearchUnavailableError, parseEmbedding, safeSlice, validateManifest } from './chunk-2N5SNDS3.mjs';
1
+ import { BaseRepository, WikiGraphNodeOwnershipConflict, parseJsonObject, parseJsonArray, liveAtSql, reanchorRebuildFingerprint, __privateAdd, warnChangedDefaultsOnce, MetadataRepository, EmbeddingService, SearchService, TemporalService, JobManager, PromptService, resolveGrounding, IngestionService, MaintenanceService, ImportExportService, RetrievalService, WriteService, __privateGet, __privateSet, createLegacySourceTypeIndex, writeNormalizeStamp, CURRENT_SCHEMA_VERSION, detectSchemaVersion, MIGRATIONS, runSourceRefNormalize, normalizeSourceRef, normalizeSourceHash, resolveLibrarianStrategy, entitySummaryMetaKey, WikiSourceRefHashCollision, DiagnosticBuffer, validateManifest, WikiDraftNotFound, generateId, emptyManifest, resolveNodeType, WikiStrictOntologyViolation, validateInlineEdges, resolveEdgeDefinitions, typeSatisfies, normalizeTitleKey, edgeTripleAllowed, MAX_EMBED_ATTEMPTS, UsageMeter, isWikiSearchUnavailableError, WikiBusyError, WikiInvalidReadOptions, isLiveAt, packFactsByBudget, factTokenCost, probePendingWork, WikiMigrationRequiredError, setupDatabase, UnavailableIndexStrategy, assertEntityId, assertEpochMs, FTS5_STATE_KEY, fts5LedgerDropSql, fts5TablesDdl, fts5PendingIndexesDdl, fts5TriggersDdl, writeRebuildStart, FTS5_RETIRED_COUNTER_KEY, retiredTableName, FTS5_RETIRED_TABLES_KEY, isRetiredTableName, idReindexChunkSql, readRebuildProgress, FTS5_DRAIN_CHUNK, FTS5_RECLAIM_MERGE_PAGES, windowHiSql, windowChunkSql, FTS5_REBUILD_WM_KEY, sweepHiSql, sweepChunkSql, FTS5_SWEEP_CURSOR_KEY, drainHiSql, drainChunkSql, FTS5_REBUILD_SNAPSHOT_KEY, idDrainChunkSql, entityDrainHiSql, entityDrainChunkSql, fts5TriggerNames, extractSqliteCode, WikiTransactionError } from './chunk-UJSUPVPH.mjs';
2
+ export { DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, EMBED_CHARS_CEILING, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, chunkText, configureRandomSource, isWikiSearchUnavailableError, parseEmbedding, safeSlice, validateManifest } from './chunk-UJSUPVPH.mjs';
3
3
  import { deriveTrustTier, isStaleAfter, appendRelatedSection, buildConceptDocument, buildLogMd, buildEntityIndexMd, buildRootIndexMd, isAllowedOkfPath, parseRootIndexMd, parseEntityIndexMd, parseConcept, splitRelatedSection, extractMarkdownLinks, parseLogMd, parseEventIdComment, latestVerified, formatSourcesJson, appendEventIdComment, parseVerifiedFlexible, parseCitationsList } from '@equationalapplications/core-okf';
4
4
  import MiniSearch from 'minisearch';
5
5
 
@@ -1973,9 +1973,10 @@ var EventRepository = class extends BaseRepository {
1973
1973
  ]
1974
1974
  );
1975
1975
  }
1976
+ /** Insert unless the id already exists. Returns true when a row was inserted. */
1976
1977
  async addIgnoreDuplicate(event, tx) {
1977
1978
  const executor = this.getExecutor(tx);
1978
- await executor.runAsync(
1979
+ const result = await executor.runAsync(
1979
1980
  `INSERT OR IGNORE INTO ${this.prefix}events (id, entity_id, event_type, summary, related_entry_id, created_at, occurred_at)
1980
1981
  VALUES (?, ?, ?, ?, ?, ?, ?)`,
1981
1982
  [
@@ -1988,6 +1989,7 @@ var EventRepository = class extends BaseRepository {
1988
1989
  event.occurred_at ?? null
1989
1990
  ]
1990
1991
  );
1992
+ return result.changes > 0;
1991
1993
  }
1992
1994
  /**
1993
1995
  * Return the most recent events for an entity, newest first.
@@ -2017,8 +2019,8 @@ var EventRepository = class extends BaseRepository {
2017
2019
  * Delete events for an entity that were created at or before the given cutoff timestamp.
2018
2020
  * Returns the number of deleted rows.
2019
2021
  */
2020
- async prune(entityId, cutoff) {
2021
- return this.db.runAsync(
2022
+ async prune(entityId, cutoff, tx) {
2023
+ return (tx ?? this.db).runAsync(
2022
2024
  `DELETE FROM ${this.prefix}events WHERE entity_id = ? AND created_at <= ?`,
2023
2025
  [entityId, cutoff]
2024
2026
  );
@@ -2030,9 +2032,9 @@ var EventRepository = class extends BaseRepository {
2030
2032
  * deleted. `wm = null` (no watermark yet) deletes nothing.
2031
2033
  * Used by runPrune under the deferred/ops strategies.
2032
2034
  */
2033
- async pruneThrough(entityId, cutoff, wm) {
2035
+ async pruneThrough(entityId, cutoff, wm, tx) {
2034
2036
  if (!wm) return { changes: 0 };
2035
- return this.db.runAsync(
2037
+ return (tx ?? this.db).runAsync(
2036
2038
  `DELETE FROM ${this.prefix}events WHERE entity_id = ? AND created_at <= ? AND NOT ${AFTER_SQL}`,
2037
2039
  [entityId, cutoff, ...afterArgs(wm)]
2038
2040
  );
@@ -2050,6 +2052,18 @@ var EventRepository = class extends BaseRepository {
2050
2052
  );
2051
2053
  return Number(row?.n ?? 0);
2052
2054
  }
2055
+ /**
2056
+ * The newest `created_at` stored for an entity, or null when it has no
2057
+ * events. `write()` reads it inside its transaction to keep `created_at`
2058
+ * strictly increasing per entity (spec ops-auto-first-batch §5).
2059
+ */
2060
+ async latestCreatedAt(entityId, tx) {
2061
+ const row = await (tx ?? this.db).getFirstAsync(
2062
+ `SELECT MAX(created_at) AS at FROM ${this.prefix}events WHERE entity_id = ?`,
2063
+ [entityId]
2064
+ );
2065
+ return row?.at ?? null;
2066
+ }
2053
2067
  /**
2054
2068
  * Return the total number of events stored for an entity.
2055
2069
  * `tx` is optional — pass an active transaction handle for atomic reads.
@@ -3248,6 +3262,9 @@ var MaintenanceScheduler = class {
3248
3262
  let h;
3249
3263
  try {
3250
3264
  h = await this.maintenanceService.doRunHeal(entityId, { trigger: "call", meter });
3265
+ if (h.remaining === 0 && !(h.budgetStop && h.scanned === 0)) {
3266
+ await this.metadataRepo.updateCheckpoint(entityId, { heal: await this.eventRepo.count(entityId) }, this.db);
3267
+ }
3251
3268
  } finally {
3252
3269
  this.jobManager.releaseLock("heal", entityId);
3253
3270
  }
@@ -3266,10 +3283,7 @@ var MaintenanceScheduler = class {
3266
3283
  }
3267
3284
  st.report.healPasses++;
3268
3285
  progressed = true;
3269
- if (h.remaining === 0) {
3270
- st.heal = false;
3271
- await this.metadataRepo.updateCheckpoint(entityId, { heal: await this.eventRepo.count(entityId) }, this.db);
3272
- }
3286
+ if (h.remaining === 0) st.heal = false;
3273
3287
  if (h.budgetStop) {
3274
3288
  stopped = exhaustedStop();
3275
3289
  break rounds;
@@ -4004,7 +4018,8 @@ var WikiMemory = class {
4004
4018
  this.metadataRepo,
4005
4019
  this.searchService,
4006
4020
  this.jobManager,
4007
- this.embeddingService
4021
+ this.embeddingService,
4022
+ this.options
4008
4023
  );
4009
4024
  this.retrievalService = new RetrievalService(
4010
4025
  this.options,