@equationalapplications/core-llm-wiki 9.18.1 → 9.20.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.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, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-CI0n5qQk.mjs';
2
- export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as IngestTypingCounters, N as LLMProvider, P as LibrarianConfig, Q as LibrarianGateConfig, T as LockedMaintenanceJob, U as MaintenanceJob, V as MaintenanceStopReason, X as MemoryDumpEntity, Y as MigrationPolicy, Z as ONTOLOGY_ABSTAIN_SENTINEL, _ as ONTOLOGY_BACKFILL_BATCH_SIZE, $ as ONTOLOGY_BACKFILL_RECHECK_MS, a0 as OntologyBackfillResult, a1 as OntologyEdgeType, a2 as OntologyManifest, a3 as OntologyNodeType, a4 as OntologyPromptContext, a5 as OntologyUpdates, a6 as PendingMaintenance, a7 as PendingMigrationWork, a8 as PendingSourceStatus, a9 as PromptOverrides, aa as PromptService, ab as PrunePartialFailureError, ac as ReembedResult, ad as RememberInput, ae as RunPendingMaintenanceOptions, af as RunPendingMaintenanceResult, ag as SourcePassage, ah as StoreSourceResult, ai as StoredSource, aj as StoredSourceDump, ak as StoredSourceSummary, al as SupersedeReplacement, am as SystemOneConfig, an as SystemOneThresholdSite, ao as VectorRanker, ap as VectorRankerFallback, aq as VectorRankerRankArgs, ar as VectorRankerSemanticResult, as as WikiBusyError, at as WikiBusyOperation, au as WikiCheckpoint, av as WikiDiagnostic, aw as WikiDiagnosticCode, ax as WikiDiagnosticDetail, ay as WikiDiagnosticOperation, az as WikiDiagnosticSeverity, aA as WikiDiagnosticTrigger, aB as WikiDraftNotFound, aC as WikiDuplicateHashError, aD as WikiEdge, aE as WikiEvent, aF as WikiExternalDeletionError, aG as WikiFact, aH as WikiGraphNodeOwnershipConflict, aI as WikiIngestEmptyError, aJ as WikiInstructions, aK as WikiInvalidReadOptions, aL as WikiLintReport, aM as WikiMemoryTestAccess, aN as WikiMigrationRequiredError, aO as WikiOutboxEvent, aP as WikiParseError, aQ as WikiSearchUnavailableError, aR as WikiSourcePointer, aS as WikiSourceRefHashCollision, aT as WikiStrictOntologyViolation, aU as WikiSupersedeError, aV as WikiSupersedeReason, aW as WikiTask, aX as WikiTransactionError, aY as WriteOntologyPromptContext, aZ as isReservedAbstainSlug, a_ as isWikiSearchUnavailableError, a$ as validateManifest } from './testing-CI0n5qQk.mjs';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-CnXg2aRj.mjs';
2
+ export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as IngestTypingCounters, N as LLMProvider, P as LibrarianConfig, Q as LibrarianGateConfig, T as ListStoredSourcesOptions, U as LockedMaintenanceJob, V as MaintenanceJob, X as MaintenanceStopReason, Y as MemoryDumpEntity, Z as MigrationPolicy, _ as ONTOLOGY_ABSTAIN_SENTINEL, $ as ONTOLOGY_BACKFILL_BATCH_SIZE, a0 as ONTOLOGY_BACKFILL_RECHECK_MS, a1 as OntologyBackfillResult, a2 as OntologyEdgeType, a3 as OntologyManifest, a4 as OntologyNodeType, a5 as OntologyPromptContext, a6 as OntologyUpdates, a7 as PendingMaintenance, a8 as PendingMigrationWork, a9 as PendingSourceStatus, aa as PromptOverrides, ab as PromptService, ac as PrunePartialFailureError, ad as ReembedResult, ae as RememberInput, af as RunPendingMaintenanceOptions, ag as RunPendingMaintenanceResult, ah as SourcePassage, ai as StoreSourceResult, aj as StoredSource, ak as StoredSourceDump, al as StoredSourceSummary, am as SupersedeReplacement, an as SystemOneConfig, ao as SystemOneThresholdSite, ap as VectorRanker, aq as VectorRankerFallback, ar as VectorRankerRankArgs, as as VectorRankerSemanticResult, at as WikiBusyError, au as WikiBusyOperation, av as WikiCheckpoint, aw as WikiDiagnostic, ax as WikiDiagnosticCode, ay as WikiDiagnosticDetail, az as WikiDiagnosticOperation, aA as WikiDiagnosticSeverity, aB as WikiDiagnosticTrigger, aC as WikiDraftNotFound, aD as WikiDuplicateHashError, aE as WikiEdge, aF as WikiEvent, aG as WikiExternalDeletionError, aH as WikiFact, aI as WikiGraphNodeOwnershipConflict, aJ as WikiIngestEmptyError, aK as WikiInstructions, aL as WikiInvalidReadOptions, aM as WikiLintReport, aN as WikiMemoryTestAccess, aO as WikiMigrationRequiredError, aP as WikiOutboxEvent, aQ as WikiParseError, aR as WikiSearchUnavailableError, aS as WikiSourcePointer, aT as WikiSourceRefHashCollision, aU as WikiStrictOntologyViolation, aV as WikiSupersedeError, aW as WikiSupersedeReason, aX as WikiTask, aY as WikiTransactionError, aZ as WriteOntologyPromptContext, a_ as isReservedAbstainSlug, a$ as isWikiSearchUnavailableError, b0 as validateManifest } from './testing-CnXg2aRj.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, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-CI0n5qQk.js';
2
- export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as IngestTypingCounters, N as LLMProvider, P as LibrarianConfig, Q as LibrarianGateConfig, T as LockedMaintenanceJob, U as MaintenanceJob, V as MaintenanceStopReason, X as MemoryDumpEntity, Y as MigrationPolicy, Z as ONTOLOGY_ABSTAIN_SENTINEL, _ as ONTOLOGY_BACKFILL_BATCH_SIZE, $ as ONTOLOGY_BACKFILL_RECHECK_MS, a0 as OntologyBackfillResult, a1 as OntologyEdgeType, a2 as OntologyManifest, a3 as OntologyNodeType, a4 as OntologyPromptContext, a5 as OntologyUpdates, a6 as PendingMaintenance, a7 as PendingMigrationWork, a8 as PendingSourceStatus, a9 as PromptOverrides, aa as PromptService, ab as PrunePartialFailureError, ac as ReembedResult, ad as RememberInput, ae as RunPendingMaintenanceOptions, af as RunPendingMaintenanceResult, ag as SourcePassage, ah as StoreSourceResult, ai as StoredSource, aj as StoredSourceDump, ak as StoredSourceSummary, al as SupersedeReplacement, am as SystemOneConfig, an as SystemOneThresholdSite, ao as VectorRanker, ap as VectorRankerFallback, aq as VectorRankerRankArgs, ar as VectorRankerSemanticResult, as as WikiBusyError, at as WikiBusyOperation, au as WikiCheckpoint, av as WikiDiagnostic, aw as WikiDiagnosticCode, ax as WikiDiagnosticDetail, ay as WikiDiagnosticOperation, az as WikiDiagnosticSeverity, aA as WikiDiagnosticTrigger, aB as WikiDraftNotFound, aC as WikiDuplicateHashError, aD as WikiEdge, aE as WikiEvent, aF as WikiExternalDeletionError, aG as WikiFact, aH as WikiGraphNodeOwnershipConflict, aI as WikiIngestEmptyError, aJ as WikiInstructions, aK as WikiInvalidReadOptions, aL as WikiLintReport, aM as WikiMemoryTestAccess, aN as WikiMigrationRequiredError, aO as WikiOutboxEvent, aP as WikiParseError, aQ as WikiSearchUnavailableError, aR as WikiSourcePointer, aS as WikiSourceRefHashCollision, aT as WikiStrictOntologyViolation, aU as WikiSupersedeError, aV as WikiSupersedeReason, aW as WikiTask, aX as WikiTransactionError, aY as WriteOntologyPromptContext, aZ as isReservedAbstainSlug, a_ as isWikiSearchUnavailableError, a$ as validateManifest } from './testing-CI0n5qQk.js';
1
+ import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-CnXg2aRj.js';
2
+ export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as IngestTypingCounters, N as LLMProvider, P as LibrarianConfig, Q as LibrarianGateConfig, T as ListStoredSourcesOptions, U as LockedMaintenanceJob, V as MaintenanceJob, X as MaintenanceStopReason, Y as MemoryDumpEntity, Z as MigrationPolicy, _ as ONTOLOGY_ABSTAIN_SENTINEL, $ as ONTOLOGY_BACKFILL_BATCH_SIZE, a0 as ONTOLOGY_BACKFILL_RECHECK_MS, a1 as OntologyBackfillResult, a2 as OntologyEdgeType, a3 as OntologyManifest, a4 as OntologyNodeType, a5 as OntologyPromptContext, a6 as OntologyUpdates, a7 as PendingMaintenance, a8 as PendingMigrationWork, a9 as PendingSourceStatus, aa as PromptOverrides, ab as PromptService, ac as PrunePartialFailureError, ad as ReembedResult, ae as RememberInput, af as RunPendingMaintenanceOptions, ag as RunPendingMaintenanceResult, ah as SourcePassage, ai as StoreSourceResult, aj as StoredSource, ak as StoredSourceDump, al as StoredSourceSummary, am as SupersedeReplacement, an as SystemOneConfig, ao as SystemOneThresholdSite, ap as VectorRanker, aq as VectorRankerFallback, ar as VectorRankerRankArgs, as as VectorRankerSemanticResult, at as WikiBusyError, au as WikiBusyOperation, av as WikiCheckpoint, aw as WikiDiagnostic, ax as WikiDiagnosticCode, ay as WikiDiagnosticDetail, az as WikiDiagnosticOperation, aA as WikiDiagnosticSeverity, aB as WikiDiagnosticTrigger, aC as WikiDraftNotFound, aD as WikiDuplicateHashError, aE as WikiEdge, aF as WikiEvent, aG as WikiExternalDeletionError, aH as WikiFact, aI as WikiGraphNodeOwnershipConflict, aJ as WikiIngestEmptyError, aK as WikiInstructions, aL as WikiInvalidReadOptions, aM as WikiLintReport, aN as WikiMemoryTestAccess, aO as WikiMigrationRequiredError, aP as WikiOutboxEvent, aQ as WikiParseError, aR as WikiSearchUnavailableError, aS as WikiSourcePointer, aT as WikiSourceRefHashCollision, aU as WikiStrictOntologyViolation, aV as WikiSupersedeError, aW as WikiSupersedeReason, aX as WikiTask, aY as WikiTransactionError, aZ as WriteOntologyPromptContext, a_ as isReservedAbstainSlug, a$ as isWikiSearchUnavailableError, b0 as validateManifest } from './testing-CnXg2aRj.js';
3
3
  import { OkfFile } from '@equationalapplications/core-okf';
4
4
 
5
5
  /**
package/dist/index.js CHANGED
@@ -363,6 +363,8 @@ var SEVERITY = {
363
363
  external_deletion_pending: "warn",
364
364
  supersede_scheduled_end_replaced: "info",
365
365
  external_deletion_discarded: "warn",
366
+ vector_removals_backlog: "warn",
367
+ vector_removals_trim_failed: "warn",
366
368
  guidance_too_long: "warn",
367
369
  guidance_resolver_failed: "warn",
368
370
  source_pointer_unresolved: "warn",
@@ -423,6 +425,8 @@ var MESSAGE = {
423
425
  supersede_scheduled_end_replaced: "A supersede replaced a scheduled end date on the old fact; the prior end is kept in prior_valid_to and reopen() can restore it.",
424
426
  external_deletion_pending: "Removals owed to the external vector index are still pending.",
425
427
  external_deletion_discarded: "Pending external vector removals were discarded because forceDeleteIgnoreRankerHook is set.",
428
+ vector_removals_backlog: "Pending external vector removals are accumulating faster than the host drains them.",
429
+ vector_removals_trim_failed: "The prune-time check of pending external vector removals failed; it will retry on the next prune pass.",
426
430
  guidance_too_long: "The configured guidance exceeded the length cap and was not sent for this pass.",
427
431
  guidance_resolver_failed: "The per-entity guidance resolver failed; its value was not used for this pass.",
428
432
  source_pointer_unresolved: "A stored librarian fact carries no source pointer because the model answer could not yield one, or the librarian merged such an unattributed candidate into this fact in place (its derived_events list was not extended).",
@@ -6810,14 +6814,17 @@ var DEFAULT_MAX_TOTAL_CHARS = 5e6;
6810
6814
  function limitOr(value, fallback) {
6811
6815
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
6812
6816
  }
6813
- function listStoredSourcesSql(prefix) {
6817
+ function listStoredSourcesSql(prefix, paging) {
6818
+ const cursorPredicate = paging?.hasCursor ? "\n AND d.source_ref > ?" : "";
6819
+ const limitClause = paging ? "\n LIMIT ?" : "";
6814
6820
  return `SELECT d.source_ref, d.source_hash, d.char_count, d.created_at,
6815
6821
  (SELECT COUNT(*) FROM ${prefix}source_passages p
6816
6822
  WHERE p.document_id = d.id AND +p.entity_id = d.entity_id) AS passage_count
6817
6823
  FROM ${prefix}source_documents d
6818
- WHERE d.entity_id = ?
6819
- ORDER BY d.source_ref COLLATE BINARY`;
6824
+ WHERE d.entity_id = ?${cursorPredicate}
6825
+ ORDER BY d.source_ref COLLATE BINARY${limitClause}`;
6820
6826
  }
6827
+ var DEFAULT_LIST_PAGE_LIMIT = 200;
6821
6828
  var SourceStoreService = class {
6822
6829
  constructor(db, prefix, options, jobManager) {
6823
6830
  this.db = db;
@@ -6894,9 +6901,48 @@ var SourceStoreService = class {
6894
6901
  storedAt: Number(row.created_at)
6895
6902
  };
6896
6903
  }
6897
- /** Spec §4/§7: full store listing, including sources stored with no ingest. */
6898
- async listStoredSources(entityId) {
6899
- const rows = await this.db.getAllAsync(listStoredSourcesSql(this.prefix), [entityId]);
6904
+ /** Spec source-store-paging §2: point probe — true iff the document row exists for the
6905
+ * normalized ref. Plain read, no write lock, hash-blind: the UNIQUE index on
6906
+ * (entity_id, source_ref) makes one row per pair the only possible state, so a
6907
+ * re-stored changed copy is still stored. Blank/non-string refs return false (no throw). */
6908
+ async hasStoredSource(entityId, sourceRef) {
6909
+ const ref = normalizeSourceRef(sourceRef);
6910
+ if (!ref) return false;
6911
+ const row = await this.db.getFirstAsync(
6912
+ `SELECT id FROM ${this.prefix}source_documents WHERE entity_id = ? AND source_ref = ?`,
6913
+ [entityId, ref]
6914
+ );
6915
+ return row !== void 0 && row !== null;
6916
+ }
6917
+ /** Spec §4/§7: full store listing, including sources stored with no ingest.
6918
+ * With `opts` (spec source-store §7): keyset paging in source_ref
6919
+ * COLLATE BINARY order; validation order opts shape → afterSourceRef →
6920
+ * limit, each a named throw before any query. `Number.isSafeInteger`
6921
+ * subsumes 0/negative/NaN/Infinity/non-number limits. */
6922
+ async listStoredSources(entityId, opts) {
6923
+ let cursor;
6924
+ let limit;
6925
+ if (opts !== void 0) {
6926
+ if (opts === null || typeof opts !== "object" || Array.isArray(opts)) {
6927
+ throw new Error("Invalid opts");
6928
+ }
6929
+ if (opts.afterSourceRef !== void 0) {
6930
+ const normalized = normalizeSourceRef(opts.afterSourceRef);
6931
+ if (!normalized) throw new Error("Invalid afterSourceRef");
6932
+ cursor = normalized;
6933
+ }
6934
+ if (opts.limit !== void 0) {
6935
+ const raw = opts.limit;
6936
+ if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw < 1) {
6937
+ throw new Error("Invalid limit");
6938
+ }
6939
+ limit = raw;
6940
+ }
6941
+ }
6942
+ const paging = cursor !== void 0 || limit !== void 0;
6943
+ const sql = listStoredSourcesSql(this.prefix, paging ? { hasCursor: cursor !== void 0 } : void 0);
6944
+ const bindings = paging ? cursor !== void 0 ? [entityId, cursor, limit ?? DEFAULT_LIST_PAGE_LIMIT] : [entityId, limit ?? DEFAULT_LIST_PAGE_LIMIT] : [entityId];
6945
+ const rows = await this.db.getAllAsync(sql, bindings);
6900
6946
  return rows.map((r) => ({
6901
6947
  sourceRef: r.source_ref,
6902
6948
  sourceHash: r.source_hash,
@@ -10178,6 +10224,40 @@ var VectorRemovalRepository = class extends BaseRepository {
10178
10224
  );
10179
10225
  return { count: row?.c ?? 0, oldestEnqueuedAt: row?.o ?? null, maxAttempts: row?.m ?? 0 };
10180
10226
  }
10227
+ /**
10228
+ * Trim an entity's pending rows down toward `cap`, deleting at most `chunk`
10229
+ * of the oldest per call. Uses the lower of the two cutoffs (cap overflow,
10230
+ * chunk bound); a no-op when at or under cap or when the external-index
10231
+ * marker is set. Without `tx` it opens its own single short transaction.
10232
+ * Returns the number of rows deleted.
10233
+ */
10234
+ async trimPendingOverflow(entityId, cap, chunk, tx) {
10235
+ if (chunk > cap) throw new Error(`trimPendingOverflow: chunk (${chunk}) must be <= cap (${cap})`);
10236
+ const run = async (ex) => {
10237
+ const t = `${this.prefix}vector_removals`;
10238
+ const capRow = await ex.getFirstAsync(
10239
+ `SELECT seq FROM ${t} WHERE entity_id = ? AND confirmed_at IS NULL
10240
+ ORDER BY seq DESC LIMIT 1 OFFSET ?`,
10241
+ [entityId, cap]
10242
+ );
10243
+ if (!capRow) return 0;
10244
+ const chunkRow = await ex.getFirstAsync(
10245
+ `SELECT seq FROM ${t} WHERE entity_id = ? AND confirmed_at IS NULL
10246
+ ORDER BY seq ASC LIMIT 1 OFFSET ?`,
10247
+ [entityId, chunk - 1]
10248
+ );
10249
+ const cuts = [capRow.seq, chunkRow?.seq].filter((x) => x != null);
10250
+ const cutoff = Math.min(...cuts);
10251
+ const r = await ex.runAsync(
10252
+ `DELETE FROM ${t}
10253
+ WHERE entity_id = ? AND confirmed_at IS NULL AND seq <= ?
10254
+ AND NOT EXISTS (SELECT 1 FROM ${this.prefix}meta WHERE key = 'external_index_in_use' AND value = '1')`,
10255
+ [entityId, cutoff]
10256
+ );
10257
+ return r.changes;
10258
+ };
10259
+ return tx ? run(tx) : this.db.withTransactionAsync(run);
10260
+ }
10181
10261
  async entitiesWithPending() {
10182
10262
  const rows = await this.db.getAllAsync(
10183
10263
  `SELECT DISTINCT entity_id FROM ${this.prefix}vector_removals
@@ -11641,6 +11721,9 @@ async function runLibrarianStrategy(deps, ctx) {
11641
11721
 
11642
11722
  // src/services/MaintenanceService.ts
11643
11723
  var CHAIN_TRUNCATED_NOTICE = `includeChain walk stopped at the depth cap (${HISTORY_MAX_DEPTH} links per direction); the chain is longer than the ids listed. Run forget again on a remaining chain id to continue.`;
11724
+ var MAX_PENDING_LEDGER_ROWS = 1e4;
11725
+ var WARN_PENDING_LEDGER_ROWS = 500;
11726
+ var TRIM_CHUNK_ROWS = 5e3;
11644
11727
  var ONTOLOGY_BACKFILL_BATCH_SIZE = 25;
11645
11728
  var ONTOLOGY_BACKFILL_RECHECK_MS = 7 * 24 * 60 * 60 * 1e3;
11646
11729
  var HEAL_ANCHOR_SEARCH_OVERFETCH = 4;
@@ -11885,6 +11968,33 @@ var _MaintenanceService = class _MaintenanceService {
11885
11968
  }
11886
11969
  }
11887
11970
  }
11971
+ if (gate === "none" && this.vectorRemoval && this.vectorRemovalRepo) {
11972
+ try {
11973
+ if (await this.vectorRemoval.ledgerPresent()) {
11974
+ if (!await this.vectorRemoval.externalIndexInUse()) {
11975
+ await this.vectorRemovalRepo.trimPendingOverflow(entityId, MAX_PENDING_LEDGER_ROWS, TRIM_CHUNK_ROWS);
11976
+ } else if (owner === "host") {
11977
+ const st = await this.vectorRemovalRepo.pendingStats(entityId);
11978
+ if (st.count > WARN_PENDING_LEDGER_ROWS) {
11979
+ emitDiagnostic(this.options, {
11980
+ code: "vector_removals_backlog",
11981
+ operation: "prune",
11982
+ trigger: "call",
11983
+ entityId,
11984
+ detail: {
11985
+ count: st.count,
11986
+ ...st.oldestEnqueuedAt !== null ? { oldestEnqueuedAt: st.oldestEnqueuedAt } : {},
11987
+ maxAttempts: st.maxAttempts
11988
+ }
11989
+ });
11990
+ }
11991
+ }
11992
+ }
11993
+ } catch (err) {
11994
+ const reason = err instanceof Error ? typeof err.code === "string" ? err.code : err.name : "unknown";
11995
+ emitDiagnostic(this.options, { code: "vector_removals_trim_failed", operation: "prune", trigger: "call", entityId, detail: { reason } });
11996
+ }
11997
+ }
11888
11998
  let vacuumCheckpointErr;
11889
11999
  if (vacuum) {
11890
12000
  try {
@@ -17961,9 +18071,14 @@ var WikiMemory = class {
17961
18071
  assertEntityId2(entityId);
17962
18072
  return this.sourceStoreService.getStoredSource(entityId, sourceRef);
17963
18073
  }
17964
- async listStoredSources(entityId) {
18074
+ async listStoredSources(entityId, opts) {
18075
+ assertEntityId2(entityId);
18076
+ return this.sourceStoreService.listStoredSources(entityId, opts);
18077
+ }
18078
+ /** Spec source-store-paging §2: point probe passthrough; a bad entityId throws here, never a silent false. */
18079
+ async hasStoredSource(entityId, sourceRef) {
17965
18080
  assertEntityId2(entityId);
17966
- return this.sourceStoreService.listStoredSources(entityId);
18081
+ return this.sourceStoreService.hasStoredSource(entityId, sourceRef);
17967
18082
  }
17968
18083
  /**
17969
18084
  * End `oldId`'s validity and link it to its replacement (spec §4.3). One