@equationalapplications/core-llm-wiki 9.15.0 → 9.16.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.
@@ -757,8 +757,19 @@ interface WikiFact {
757
757
  superseded_by?: string | null;
758
758
  /** Epoch ms the supersession was recorded (transaction time). Audit only. */
759
759
  superseded_at?: number | null;
760
+ /** The `valid_to` this fact carried immediately before its current supersession (a scheduled end `supersede()` overwrote). Restored by `reopen()`. Absent when the fact was open-ended or the supersession predates schema 18. */
761
+ prior_valid_to?: number | null;
760
762
  /** Structured provenance from this librarian fact to its source event, with the verified quote. Null for legacy/heal/ingest facts. */
761
763
  source_pointer?: WikiSourcePointer | null;
764
+ /**
765
+ * Ids of further events this fact's stored wording also rests on, beyond
766
+ * the one `source_pointer` names (specs/inplace-update-provenance). Written
767
+ * by the ops librarian when it merges event text into an existing fact. A
768
+ * contribution ledger, not a second pointer: no quote, no position. Present
769
+ * only when non-empty; absent for facts updated before schema v18.
770
+ * `forget({ eventId })` matches it.
771
+ */
772
+ derived_events?: string[];
762
773
  }
763
774
  interface WikiTask {
764
775
  id: string;
@@ -1034,7 +1045,7 @@ type WikiDiagnosticSeverity = 'info' | 'warn' | 'error';
1034
1045
  * Closed for this release series, but new codes are added in minor versions:
1035
1046
  * hosts must tolerate codes they do not recognize.
1036
1047
  */
1037
- type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'heal_deleted' | 'heal_downgraded' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'classification_abstained' | 'node_type_assigned' | 'context_overflow_skipped' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'librarian_rewritten' | 'librarian_superseded' | 'contradicts_document' | 'ontology_backfill_held' | 'resolve_failed' | 'read_budget' | 'event_retention_held' | 'prune_checkpoint_incomplete' | 'erase_secure_delete_off' | 'erase_entity_skipped' | 'erase_retired_vtab_undroppable' | 'erase_fts_orphan_cleared' | 'erase_retired_remaining' | 'erase_tombstones_remaining' | 'erase_retired_read_failed' | 'erase_registry_sweep_skipped' | 'import_tombstone_skipped' | 'event_created_at_clamped' | 'event_created_at_restamped' | 'external_deletion_pending' | 'external_deletion_discarded' | 'guidance_too_long' | 'guidance_resolver_failed' | 'source_pointer_unresolved' | 'source_pointer_invalid' | 'source_store_source_too_large' | 'source_store_budget_exceeded' | 'source_store_hash_mismatch' | 'source_store_duplicate_hash' | 'source_store_text_not_storable' | 'node_type_dropped' | 'node_type_folded' | 'ontology_update_rejected' | 'ingest_zero_facts';
1048
+ type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'heal_deleted' | 'heal_downgraded' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'classification_abstained' | 'node_type_assigned' | 'context_overflow_skipped' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'librarian_rewritten' | 'librarian_superseded' | 'contradicts_document' | 'ontology_backfill_held' | 'resolve_failed' | 'read_budget' | 'event_retention_held' | 'prune_checkpoint_incomplete' | 'erase_secure_delete_off' | 'erase_entity_skipped' | 'erase_retired_vtab_undroppable' | 'erase_fts_orphan_cleared' | 'erase_retired_remaining' | 'erase_tombstones_remaining' | 'erase_retired_read_failed' | 'erase_registry_sweep_skipped' | 'import_tombstone_skipped' | 'event_created_at_clamped' | 'event_created_at_restamped' | 'external_deletion_pending' | 'supersede_scheduled_end_replaced' | 'external_deletion_discarded' | 'guidance_too_long' | 'guidance_resolver_failed' | 'source_pointer_unresolved' | 'source_pointer_invalid' | 'source_event_gone' | 'derived_events_invalid' | 'source_store_source_too_large' | 'source_store_budget_exceeded' | 'source_store_hash_mismatch' | 'source_store_duplicate_hash' | 'source_store_text_not_storable' | 'node_type_dropped' | 'node_type_folded' | 'ontology_update_rejected' | 'ingest_zero_facts';
1038
1049
  /** The service run that emitted the diagnostic. */
1039
1050
  type WikiDiagnosticOperation = 'ingest' | 'upsertGraph' | 'librarian' | 'heal' | 'ontologyBackfill' | 'reembed' | 'importDump' | 'write' | 'supersede' | 'remember' | 'read' | 'prune' | 'externalDeletion' | 'sourceStore' | 'erase';
1040
1051
  /** `'auto'` when a write threshold started the run (auto-librarian / auto-heal); `'call'` when the host did. */
@@ -1081,6 +1092,8 @@ interface WikiDiagnosticDetail {
1081
1092
  oldestEnqueuedAt?: number;
1082
1093
  /** external_deletion_pending only: highest attempt count among pending rows. */
1083
1094
  maxAttempts?: number;
1095
+ /** supersede_scheduled_end_replaced only: epoch ms of the scheduled end the supersede overwrote (a timestamp, not content). */
1096
+ priorValidTo?: number;
1084
1097
  /** guidance_too_long only: length of the refused value in UTF-16 code units. */
1085
1098
  guidanceLength?: number;
1086
1099
  /** guidance_too_long only: which configured value was refused. */
@@ -1312,7 +1325,9 @@ interface MemoryDump {
1312
1325
  * Source-pointer parse report (specs/source-pointers §Export, import, and OKF).
1313
1326
  * Present ONLY when `parseOkfBundle` dropped a malformed `source_pointer`
1314
1327
  * value: entry ids and a reason slug — never raw pointer values, because a
1315
- * pointer can carry quote text. Export-only metadata; `importDump` ignores it.
1328
+ * pointer can carry quote text. Also carries `derived_events_malformed`
1329
+ * entries for a dropped OKF `derived_events` list. Export-only metadata;
1330
+ * `importDump` ignores it.
1316
1331
  */
1317
1332
  dropped_pointer_values?: Array<{
1318
1333
  factId: string;
@@ -1499,7 +1514,8 @@ interface ForgetParams {
1499
1514
  sourceHash?: string;
1500
1515
  /**
1501
1516
  * Soft-delete every librarian fact whose `source_pointer` names this event
1502
- * id (entity-scoped; exact match, no normalization — event ids are
1517
+ * id, or whose `derived_events` list contains it (a fact the librarian
1518
+ * merged this event's text into is deleted whole; entity-scoped; exact match, no normalization — event ids are
1503
1519
  * engine-generated). Mutually exclusive with every other selector;
1504
1520
  * `clearAll` excludes it. Removal reports through the return value and the
1505
1521
  * per-row outbox DELETE events. See `specs/forget-by-event-id/` (issue #386).
@@ -1647,8 +1663,8 @@ declare class WikiDraftNotFound extends Error {
1647
1663
  readonly code: "WIKI_DRAFT_NOT_FOUND";
1648
1664
  constructor();
1649
1665
  }
1650
- type WikiSupersedeReason = 'not_found' | 'already_superseded' | 'immutable_target' | 'cycle' | 'cross_entity' | 'already_expired' | 'invalid_interval';
1651
- /** Thrown by `supersede()` and `expire()` (spec §4.3). Contextless like {@link WikiDraftNotFound}. */
1666
+ type WikiSupersedeReason = 'not_found' | 'already_superseded' | 'immutable_target' | 'cycle' | 'cross_entity' | 'already_expired' | 'invalid_interval' | 'not_superseded' | 'successor_live';
1667
+ /** Thrown by `supersede()`, `expire()` and `reopen()` (spec §4.3). Contextless like {@link WikiDraftNotFound}. */
1652
1668
  declare class WikiSupersedeError extends Error {
1653
1669
  readonly code: "WIKI_SUPERSEDE_REJECTED";
1654
1670
  readonly reason: WikiSupersedeReason;
@@ -1924,6 +1940,7 @@ type TemporalFields = {
1924
1940
  valid_to?: number | null;
1925
1941
  superseded_by?: string | null;
1926
1942
  superseded_at?: number | null;
1943
+ prior_valid_to?: number | null;
1927
1944
  };
1928
1945
  /** Lightweight projection used by TemporalService for supersession chain walks. */
1929
1946
  type TemporalRow = {
@@ -1935,6 +1952,7 @@ type TemporalRow = {
1935
1952
  valid_from: number | null;
1936
1953
  valid_to: number | null;
1937
1954
  superseded_by: string | null;
1955
+ prior_valid_to: number | null;
1938
1956
  };
1939
1957
  type EntryRowMetadata = {
1940
1958
  id: string;
@@ -2043,7 +2061,7 @@ declare class EntryRepository extends BaseRepository {
2043
2061
  }>>;
2044
2062
  findIdById(id: string, entityId: string, tx?: SQLiteAdapter): Promise<string | null>;
2045
2063
  findIdsBySource(entityId: string, sourceRef: string | null, sourceHash: string | null, tx?: SQLiteAdapter, includeDeleted?: boolean): Promise<string[]>;
2046
- upsertForImport(fact: WikiFact, tx: SQLiteAdapter, sourcePointerPresent?: boolean): Promise<{
2064
+ upsertForImport(fact: WikiFact, tx: SQLiteAdapter, sourcePointerPresent?: boolean, derivedEventsPresent?: boolean): Promise<{
2047
2065
  changes: number;
2048
2066
  lastInsertRowId: number;
2049
2067
  }>;
@@ -2062,16 +2080,25 @@ declare class EntryRepository extends BaseRepository {
2062
2080
  */
2063
2081
  softDeleteBySource(entityId: string, tx: SQLiteAdapter, sourceRef?: string | null, sourceHash?: string | null): Promise<number>;
2064
2082
  /**
2065
- * Shared JSON match predicate for source_pointer event ids
2066
- * (specs/forget-by-event-id §D1). Every JSON call sits under the single
2083
+ * Shared JSON match predicate for an event id
2084
+ * (specs/forget-by-event-id §D1, widened by specs/inplace-update-provenance
2085
+ * §4): a row matches when its `source_pointer` names the event OR its
2086
+ * `derived_events` list contains it. Every JSON call sits under its own
2067
2087
  * `json_valid` guard: unguarded JSON functions RAISE on malformed text, and
2068
2088
  * three-valued logic forces evaluation of AND operands after a NULL-guarded
2069
2089
  * term — a two-term form is only as safe as the planner's term-splitting.
2090
+ * The `json_each` term additionally requires `json_type = 'array'` (a JSON
2091
+ * object or scalar would otherwise iterate its members). The event id binds
2092
+ * TWICE (pointer term, then derived_events term); use `eventMatchArgs`.
2070
2093
  * The tombstone guard (`deleted_at IS NULL`) is added per-method.
2071
2094
  */
2072
- 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";
2095
+ static readonly 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)\n OR\n (CASE WHEN json_valid(derived_events)\n THEN (CASE WHEN json_type(derived_events) = 'array'\n THEN EXISTS (SELECT 1 FROM json_each(derived_events) WHERE json_each.type = 'text' AND json_each.value = ?)\n ELSE 0 END)\n ELSE 0 END))";
2096
+ /** Bind values for `EVENT_MATCH_SQL` after an `entity_id = ?` term: the event id twice. */
2097
+ static eventMatchArgs(entityId: string, eventId: string): [string, string, string];
2098
+ /** Old name kept as an alias (tests and external references). */
2099
+ 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)\n OR\n (CASE WHEN json_valid(derived_events)\n THEN (CASE WHEN json_type(derived_events) = 'array'\n THEN EXISTS (SELECT 1 FROM json_each(derived_events) WHERE json_each.type = 'text' AND json_each.value = ?)\n ELSE 0 END)\n ELSE 0 END))";
2073
2100
  /**
2074
- * IDs of the entity's entries whose source_pointer names the event id.
2101
+ * IDs of the entity's entries whose source_pointer names the event id or whose derived_events list contains it.
2075
2102
  * `includeDeleted = true` returns live + tombstoned rows (the forget
2076
2103
  * enumeration superset for index sync and the ledger backstop).
2077
2104
  */
@@ -2199,7 +2226,7 @@ declare class EntryRepository extends BaseRepository {
2199
2226
  * Used by MaintenanceService.doRunHeal().
2200
2227
  */
2201
2228
  softDeleteByIds(ids: string[], entityId: string, tx: SQLiteAdapter): Promise<void>;
2202
- /** Spec §4: write any subset of the four temporal columns. Absent key = untouched; null = clear. */
2229
+ /** Spec §4: write any subset of the five temporal columns. Absent key = untouched; null = clear. */
2203
2230
  setTemporal(id: string, entityId: string, fields: TemporalFields, tx: SQLiteAdapter, opts?: {
2204
2231
  outbox?: boolean;
2205
2232
  }): Promise<number>;
@@ -3953,6 +3980,12 @@ declare class EventRepository extends BaseRepository {
3953
3980
  add(event: WikiEvent, tx?: SQLiteAdapter): Promise<void>;
3954
3981
  /** Insert unless the id already exists. Returns true when a row was inserted. */
3955
3982
  addIgnoreDuplicate(event: WikiEvent, tx?: SQLiteAdapter): Promise<boolean>;
3983
+ /**
3984
+ * The subset of `ids` that exist as events of `entityId` (specs/
3985
+ * inplace-update-provenance §3). Chunked so a large batch stays under the
3986
+ * bound-variable limit. Pass `tx` to read inside the caller's transaction.
3987
+ */
3988
+ findExistingIds(entityId: string, ids: readonly string[], tx?: SQLiteAdapter): Promise<Set<string>>;
3956
3989
  /**
3957
3990
  * Return the most recent events for an entity, newest first.
3958
3991
  * Defaults to a limit of 50.
@@ -4701,7 +4734,9 @@ declare class TemporalService {
4701
4734
  * already exist. Throws WikiSupersedeError on any rule violation; the
4702
4735
  * caller's transaction then rolls back.
4703
4736
  */
4704
- supersedeInTx(tx: SQLiteAdapter, entityId: string, oldId: string, newId: string, t: number, now: number): Promise<void>;
4737
+ supersedeInTx(tx: SQLiteAdapter, entityId: string, oldId: string, newId: string, t: number, now: number): Promise<{
4738
+ replacedScheduledEnd: number | null;
4739
+ }>;
4705
4740
  supersede(entityId: string, oldId: string, replacement: SupersedeReplacement, options?: {
4706
4741
  validFrom?: number;
4707
4742
  }): Promise<{
@@ -4714,6 +4749,14 @@ declare class TemporalService {
4714
4749
  expire(entityId: string, factId: string, options?: {
4715
4750
  at?: number;
4716
4751
  }): Promise<void>;
4752
+ /**
4753
+ * Return a superseded fact to live once its replacement is forgotten or gone
4754
+ * (INTENT rule 12, specs/supersede-future-valid-to D4). Restores `valid_to`
4755
+ * to `prior_valid_to` (null when none was recorded).
4756
+ */
4757
+ reopen(entityId: string, factId: string): Promise<{
4758
+ valid_to: number | null;
4759
+ }>;
4717
4760
  history(entityId: string, factId: string): Promise<WikiFact[]>;
4718
4761
  }
4719
4762
 
@@ -5164,7 +5207,10 @@ declare class WikiMemory {
5164
5207
  * End `oldId`'s validity and link it to its replacement (spec §4.3). One
5165
5208
  * transaction. Throws `WikiSupersedeError` for missing, foreign, already
5166
5209
  * superseded, already expired, immutable-document, or cyclic targets, and
5167
- * for an inverted or empty interval (`invalid_interval`).
5210
+ * for an inverted or empty interval (`invalid_interval`). When the old
5211
+ * fact carried a future `valid_to`, that scheduled end is overwritten but
5212
+ * kept in `prior_valid_to` (restored by `reopen()`) and reported as the
5213
+ * `supersede_scheduled_end_replaced` diagnostic.
5168
5214
  */
5169
5215
  supersede(entityId: string, oldId: string, replacement: SupersedeReplacement, options?: {
5170
5216
  validFrom?: number;
@@ -5183,6 +5229,20 @@ declare class WikiMemory {
5183
5229
  expire(entityId: string, factId: string, options?: {
5184
5230
  at?: number;
5185
5231
  }): Promise<void>;
5232
+ /**
5233
+ * Return a superseded fact to live once its replacement has been forgotten
5234
+ * or hard-deleted (INTENT rule 12). Clears `superseded_by`/`superseded_at`
5235
+ * and restores `valid_to` to the scheduled end `supersede()` overwrote
5236
+ * (`prior_valid_to`), or null when the fact was open-ended. Resolves with
5237
+ * the restored `valid_to`. Throws `WikiSupersedeError` for a missing or
5238
+ * foreign fact, one that is not superseded (an `expire()`-ended fact is
5239
+ * not reopened), an immutable-document fact, or `successor_live` while the
5240
+ * direct replacement is still live. A restored end that has already passed
5241
+ * leaves the fact expired.
5242
+ */
5243
+ reopen(entityId: string, factId: string): Promise<{
5244
+ valid_to: number | null;
5245
+ }>;
5186
5246
  /** The supersession chain containing `factId`, oldest first. [] when unknown. */
5187
5247
  history(entityId: string, factId: string): Promise<WikiFact[]>;
5188
5248
  /**
@@ -757,8 +757,19 @@ interface WikiFact {
757
757
  superseded_by?: string | null;
758
758
  /** Epoch ms the supersession was recorded (transaction time). Audit only. */
759
759
  superseded_at?: number | null;
760
+ /** The `valid_to` this fact carried immediately before its current supersession (a scheduled end `supersede()` overwrote). Restored by `reopen()`. Absent when the fact was open-ended or the supersession predates schema 18. */
761
+ prior_valid_to?: number | null;
760
762
  /** Structured provenance from this librarian fact to its source event, with the verified quote. Null for legacy/heal/ingest facts. */
761
763
  source_pointer?: WikiSourcePointer | null;
764
+ /**
765
+ * Ids of further events this fact's stored wording also rests on, beyond
766
+ * the one `source_pointer` names (specs/inplace-update-provenance). Written
767
+ * by the ops librarian when it merges event text into an existing fact. A
768
+ * contribution ledger, not a second pointer: no quote, no position. Present
769
+ * only when non-empty; absent for facts updated before schema v18.
770
+ * `forget({ eventId })` matches it.
771
+ */
772
+ derived_events?: string[];
762
773
  }
763
774
  interface WikiTask {
764
775
  id: string;
@@ -1034,7 +1045,7 @@ type WikiDiagnosticSeverity = 'info' | 'warn' | 'error';
1034
1045
  * Closed for this release series, but new codes are added in minor versions:
1035
1046
  * hosts must tolerate codes they do not recognize.
1036
1047
  */
1037
- type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'heal_deleted' | 'heal_downgraded' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'classification_abstained' | 'node_type_assigned' | 'context_overflow_skipped' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'librarian_rewritten' | 'librarian_superseded' | 'contradicts_document' | 'ontology_backfill_held' | 'resolve_failed' | 'read_budget' | 'event_retention_held' | 'prune_checkpoint_incomplete' | 'erase_secure_delete_off' | 'erase_entity_skipped' | 'erase_retired_vtab_undroppable' | 'erase_fts_orphan_cleared' | 'erase_retired_remaining' | 'erase_tombstones_remaining' | 'erase_retired_read_failed' | 'erase_registry_sweep_skipped' | 'import_tombstone_skipped' | 'event_created_at_clamped' | 'event_created_at_restamped' | 'external_deletion_pending' | 'external_deletion_discarded' | 'guidance_too_long' | 'guidance_resolver_failed' | 'source_pointer_unresolved' | 'source_pointer_invalid' | 'source_store_source_too_large' | 'source_store_budget_exceeded' | 'source_store_hash_mismatch' | 'source_store_duplicate_hash' | 'source_store_text_not_storable' | 'node_type_dropped' | 'node_type_folded' | 'ontology_update_rejected' | 'ingest_zero_facts';
1048
+ type WikiDiagnosticCode = 'ingest_chunk_failed' | 'fact_rejected' | 'task_rejected' | 'fact_deduplicated' | 'edge_dropped' | 'embedding_failed' | 'hook_failed' | 'background_job_failed' | 'heal_skipped' | 'heal_deleted' | 'heal_downgraded' | 'grounding_missing' | 'grounding_failed' | 'classification_low_confidence' | 'classification_invalid' | 'classification_abstained' | 'node_type_assigned' | 'context_overflow_skipped' | 'llm_usage' | 'librarian_gate' | 'librarian_op_rejected' | 'librarian_rewritten' | 'librarian_superseded' | 'contradicts_document' | 'ontology_backfill_held' | 'resolve_failed' | 'read_budget' | 'event_retention_held' | 'prune_checkpoint_incomplete' | 'erase_secure_delete_off' | 'erase_entity_skipped' | 'erase_retired_vtab_undroppable' | 'erase_fts_orphan_cleared' | 'erase_retired_remaining' | 'erase_tombstones_remaining' | 'erase_retired_read_failed' | 'erase_registry_sweep_skipped' | 'import_tombstone_skipped' | 'event_created_at_clamped' | 'event_created_at_restamped' | 'external_deletion_pending' | 'supersede_scheduled_end_replaced' | 'external_deletion_discarded' | 'guidance_too_long' | 'guidance_resolver_failed' | 'source_pointer_unresolved' | 'source_pointer_invalid' | 'source_event_gone' | 'derived_events_invalid' | 'source_store_source_too_large' | 'source_store_budget_exceeded' | 'source_store_hash_mismatch' | 'source_store_duplicate_hash' | 'source_store_text_not_storable' | 'node_type_dropped' | 'node_type_folded' | 'ontology_update_rejected' | 'ingest_zero_facts';
1038
1049
  /** The service run that emitted the diagnostic. */
1039
1050
  type WikiDiagnosticOperation = 'ingest' | 'upsertGraph' | 'librarian' | 'heal' | 'ontologyBackfill' | 'reembed' | 'importDump' | 'write' | 'supersede' | 'remember' | 'read' | 'prune' | 'externalDeletion' | 'sourceStore' | 'erase';
1040
1051
  /** `'auto'` when a write threshold started the run (auto-librarian / auto-heal); `'call'` when the host did. */
@@ -1081,6 +1092,8 @@ interface WikiDiagnosticDetail {
1081
1092
  oldestEnqueuedAt?: number;
1082
1093
  /** external_deletion_pending only: highest attempt count among pending rows. */
1083
1094
  maxAttempts?: number;
1095
+ /** supersede_scheduled_end_replaced only: epoch ms of the scheduled end the supersede overwrote (a timestamp, not content). */
1096
+ priorValidTo?: number;
1084
1097
  /** guidance_too_long only: length of the refused value in UTF-16 code units. */
1085
1098
  guidanceLength?: number;
1086
1099
  /** guidance_too_long only: which configured value was refused. */
@@ -1312,7 +1325,9 @@ interface MemoryDump {
1312
1325
  * Source-pointer parse report (specs/source-pointers §Export, import, and OKF).
1313
1326
  * Present ONLY when `parseOkfBundle` dropped a malformed `source_pointer`
1314
1327
  * value: entry ids and a reason slug — never raw pointer values, because a
1315
- * pointer can carry quote text. Export-only metadata; `importDump` ignores it.
1328
+ * pointer can carry quote text. Also carries `derived_events_malformed`
1329
+ * entries for a dropped OKF `derived_events` list. Export-only metadata;
1330
+ * `importDump` ignores it.
1316
1331
  */
1317
1332
  dropped_pointer_values?: Array<{
1318
1333
  factId: string;
@@ -1499,7 +1514,8 @@ interface ForgetParams {
1499
1514
  sourceHash?: string;
1500
1515
  /**
1501
1516
  * Soft-delete every librarian fact whose `source_pointer` names this event
1502
- * id (entity-scoped; exact match, no normalization — event ids are
1517
+ * id, or whose `derived_events` list contains it (a fact the librarian
1518
+ * merged this event's text into is deleted whole; entity-scoped; exact match, no normalization — event ids are
1503
1519
  * engine-generated). Mutually exclusive with every other selector;
1504
1520
  * `clearAll` excludes it. Removal reports through the return value and the
1505
1521
  * per-row outbox DELETE events. See `specs/forget-by-event-id/` (issue #386).
@@ -1647,8 +1663,8 @@ declare class WikiDraftNotFound extends Error {
1647
1663
  readonly code: "WIKI_DRAFT_NOT_FOUND";
1648
1664
  constructor();
1649
1665
  }
1650
- type WikiSupersedeReason = 'not_found' | 'already_superseded' | 'immutable_target' | 'cycle' | 'cross_entity' | 'already_expired' | 'invalid_interval';
1651
- /** Thrown by `supersede()` and `expire()` (spec §4.3). Contextless like {@link WikiDraftNotFound}. */
1666
+ type WikiSupersedeReason = 'not_found' | 'already_superseded' | 'immutable_target' | 'cycle' | 'cross_entity' | 'already_expired' | 'invalid_interval' | 'not_superseded' | 'successor_live';
1667
+ /** Thrown by `supersede()`, `expire()` and `reopen()` (spec §4.3). Contextless like {@link WikiDraftNotFound}. */
1652
1668
  declare class WikiSupersedeError extends Error {
1653
1669
  readonly code: "WIKI_SUPERSEDE_REJECTED";
1654
1670
  readonly reason: WikiSupersedeReason;
@@ -1924,6 +1940,7 @@ type TemporalFields = {
1924
1940
  valid_to?: number | null;
1925
1941
  superseded_by?: string | null;
1926
1942
  superseded_at?: number | null;
1943
+ prior_valid_to?: number | null;
1927
1944
  };
1928
1945
  /** Lightweight projection used by TemporalService for supersession chain walks. */
1929
1946
  type TemporalRow = {
@@ -1935,6 +1952,7 @@ type TemporalRow = {
1935
1952
  valid_from: number | null;
1936
1953
  valid_to: number | null;
1937
1954
  superseded_by: string | null;
1955
+ prior_valid_to: number | null;
1938
1956
  };
1939
1957
  type EntryRowMetadata = {
1940
1958
  id: string;
@@ -2043,7 +2061,7 @@ declare class EntryRepository extends BaseRepository {
2043
2061
  }>>;
2044
2062
  findIdById(id: string, entityId: string, tx?: SQLiteAdapter): Promise<string | null>;
2045
2063
  findIdsBySource(entityId: string, sourceRef: string | null, sourceHash: string | null, tx?: SQLiteAdapter, includeDeleted?: boolean): Promise<string[]>;
2046
- upsertForImport(fact: WikiFact, tx: SQLiteAdapter, sourcePointerPresent?: boolean): Promise<{
2064
+ upsertForImport(fact: WikiFact, tx: SQLiteAdapter, sourcePointerPresent?: boolean, derivedEventsPresent?: boolean): Promise<{
2047
2065
  changes: number;
2048
2066
  lastInsertRowId: number;
2049
2067
  }>;
@@ -2062,16 +2080,25 @@ declare class EntryRepository extends BaseRepository {
2062
2080
  */
2063
2081
  softDeleteBySource(entityId: string, tx: SQLiteAdapter, sourceRef?: string | null, sourceHash?: string | null): Promise<number>;
2064
2082
  /**
2065
- * Shared JSON match predicate for source_pointer event ids
2066
- * (specs/forget-by-event-id §D1). Every JSON call sits under the single
2083
+ * Shared JSON match predicate for an event id
2084
+ * (specs/forget-by-event-id §D1, widened by specs/inplace-update-provenance
2085
+ * §4): a row matches when its `source_pointer` names the event OR its
2086
+ * `derived_events` list contains it. Every JSON call sits under its own
2067
2087
  * `json_valid` guard: unguarded JSON functions RAISE on malformed text, and
2068
2088
  * three-valued logic forces evaluation of AND operands after a NULL-guarded
2069
2089
  * term — a two-term form is only as safe as the planner's term-splitting.
2090
+ * The `json_each` term additionally requires `json_type = 'array'` (a JSON
2091
+ * object or scalar would otherwise iterate its members). The event id binds
2092
+ * TWICE (pointer term, then derived_events term); use `eventMatchArgs`.
2070
2093
  * The tombstone guard (`deleted_at IS NULL`) is added per-method.
2071
2094
  */
2072
- 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";
2095
+ static readonly 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)\n OR\n (CASE WHEN json_valid(derived_events)\n THEN (CASE WHEN json_type(derived_events) = 'array'\n THEN EXISTS (SELECT 1 FROM json_each(derived_events) WHERE json_each.type = 'text' AND json_each.value = ?)\n ELSE 0 END)\n ELSE 0 END))";
2096
+ /** Bind values for `EVENT_MATCH_SQL` after an `entity_id = ?` term: the event id twice. */
2097
+ static eventMatchArgs(entityId: string, eventId: string): [string, string, string];
2098
+ /** Old name kept as an alias (tests and external references). */
2099
+ 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)\n OR\n (CASE WHEN json_valid(derived_events)\n THEN (CASE WHEN json_type(derived_events) = 'array'\n THEN EXISTS (SELECT 1 FROM json_each(derived_events) WHERE json_each.type = 'text' AND json_each.value = ?)\n ELSE 0 END)\n ELSE 0 END))";
2073
2100
  /**
2074
- * IDs of the entity's entries whose source_pointer names the event id.
2101
+ * IDs of the entity's entries whose source_pointer names the event id or whose derived_events list contains it.
2075
2102
  * `includeDeleted = true` returns live + tombstoned rows (the forget
2076
2103
  * enumeration superset for index sync and the ledger backstop).
2077
2104
  */
@@ -2199,7 +2226,7 @@ declare class EntryRepository extends BaseRepository {
2199
2226
  * Used by MaintenanceService.doRunHeal().
2200
2227
  */
2201
2228
  softDeleteByIds(ids: string[], entityId: string, tx: SQLiteAdapter): Promise<void>;
2202
- /** Spec §4: write any subset of the four temporal columns. Absent key = untouched; null = clear. */
2229
+ /** Spec §4: write any subset of the five temporal columns. Absent key = untouched; null = clear. */
2203
2230
  setTemporal(id: string, entityId: string, fields: TemporalFields, tx: SQLiteAdapter, opts?: {
2204
2231
  outbox?: boolean;
2205
2232
  }): Promise<number>;
@@ -3953,6 +3980,12 @@ declare class EventRepository extends BaseRepository {
3953
3980
  add(event: WikiEvent, tx?: SQLiteAdapter): Promise<void>;
3954
3981
  /** Insert unless the id already exists. Returns true when a row was inserted. */
3955
3982
  addIgnoreDuplicate(event: WikiEvent, tx?: SQLiteAdapter): Promise<boolean>;
3983
+ /**
3984
+ * The subset of `ids` that exist as events of `entityId` (specs/
3985
+ * inplace-update-provenance §3). Chunked so a large batch stays under the
3986
+ * bound-variable limit. Pass `tx` to read inside the caller's transaction.
3987
+ */
3988
+ findExistingIds(entityId: string, ids: readonly string[], tx?: SQLiteAdapter): Promise<Set<string>>;
3956
3989
  /**
3957
3990
  * Return the most recent events for an entity, newest first.
3958
3991
  * Defaults to a limit of 50.
@@ -4701,7 +4734,9 @@ declare class TemporalService {
4701
4734
  * already exist. Throws WikiSupersedeError on any rule violation; the
4702
4735
  * caller's transaction then rolls back.
4703
4736
  */
4704
- supersedeInTx(tx: SQLiteAdapter, entityId: string, oldId: string, newId: string, t: number, now: number): Promise<void>;
4737
+ supersedeInTx(tx: SQLiteAdapter, entityId: string, oldId: string, newId: string, t: number, now: number): Promise<{
4738
+ replacedScheduledEnd: number | null;
4739
+ }>;
4705
4740
  supersede(entityId: string, oldId: string, replacement: SupersedeReplacement, options?: {
4706
4741
  validFrom?: number;
4707
4742
  }): Promise<{
@@ -4714,6 +4749,14 @@ declare class TemporalService {
4714
4749
  expire(entityId: string, factId: string, options?: {
4715
4750
  at?: number;
4716
4751
  }): Promise<void>;
4752
+ /**
4753
+ * Return a superseded fact to live once its replacement is forgotten or gone
4754
+ * (INTENT rule 12, specs/supersede-future-valid-to D4). Restores `valid_to`
4755
+ * to `prior_valid_to` (null when none was recorded).
4756
+ */
4757
+ reopen(entityId: string, factId: string): Promise<{
4758
+ valid_to: number | null;
4759
+ }>;
4717
4760
  history(entityId: string, factId: string): Promise<WikiFact[]>;
4718
4761
  }
4719
4762
 
@@ -5164,7 +5207,10 @@ declare class WikiMemory {
5164
5207
  * End `oldId`'s validity and link it to its replacement (spec §4.3). One
5165
5208
  * transaction. Throws `WikiSupersedeError` for missing, foreign, already
5166
5209
  * superseded, already expired, immutable-document, or cyclic targets, and
5167
- * for an inverted or empty interval (`invalid_interval`).
5210
+ * for an inverted or empty interval (`invalid_interval`). When the old
5211
+ * fact carried a future `valid_to`, that scheduled end is overwritten but
5212
+ * kept in `prior_valid_to` (restored by `reopen()`) and reported as the
5213
+ * `supersede_scheduled_end_replaced` diagnostic.
5168
5214
  */
5169
5215
  supersede(entityId: string, oldId: string, replacement: SupersedeReplacement, options?: {
5170
5216
  validFrom?: number;
@@ -5183,6 +5229,20 @@ declare class WikiMemory {
5183
5229
  expire(entityId: string, factId: string, options?: {
5184
5230
  at?: number;
5185
5231
  }): Promise<void>;
5232
+ /**
5233
+ * Return a superseded fact to live once its replacement has been forgotten
5234
+ * or hard-deleted (INTENT rule 12). Clears `superseded_by`/`superseded_at`
5235
+ * and restores `valid_to` to the scheduled end `supersede()` overwrote
5236
+ * (`prior_valid_to`), or null when the fact was open-ended. Resolves with
5237
+ * the restored `valid_to`. Throws `WikiSupersedeError` for a missing or
5238
+ * foreign fact, one that is not superseded (an `expire()`-ended fact is
5239
+ * not reopened), an immutable-document fact, or `successor_live` while the
5240
+ * direct replacement is still live. A restored end that has already passed
5241
+ * leaves the fact expired.
5242
+ */
5243
+ reopen(entityId: string, factId: string): Promise<{
5244
+ valid_to: number | null;
5245
+ }>;
5186
5246
  /** The supersession chain containing `factId`, oldest first. [] when unknown. */
5187
5247
  history(entityId: string, factId: string): Promise<WikiFact[]>;
5188
5248
  /**
@@ -1,2 +1,2 @@
1
- export { a$ as EmbeddingService, b0 as ImportExportService, b1 as IngestionService, b2 as JobManager, b2 as JobManagerType, b3 as MaintenanceService, b4 as RetrievalService, b5 as SearchService, b5 as SearchServiceType, aL as WikiMemoryTestAccess, b6 as WriteService } from './testing-ziEQOLjo.mjs';
1
+ export { a$ as EmbeddingService, b0 as ImportExportService, b1 as IngestionService, b2 as JobManager, b2 as JobManagerType, b3 as MaintenanceService, b4 as RetrievalService, b5 as SearchService, b5 as SearchServiceType, aL as WikiMemoryTestAccess, b6 as WriteService } from './testing-C8sYdo2S.mjs';
2
2
  import '@equationalapplications/core-okf';
package/dist/testing.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { a$ as EmbeddingService, b0 as ImportExportService, b1 as IngestionService, b2 as JobManager, b2 as JobManagerType, b3 as MaintenanceService, b4 as RetrievalService, b5 as SearchService, b5 as SearchServiceType, aL as WikiMemoryTestAccess, b6 as WriteService } from './testing-ziEQOLjo.js';
1
+ export { a$ as EmbeddingService, b0 as ImportExportService, b1 as IngestionService, b2 as JobManager, b2 as JobManagerType, b3 as MaintenanceService, b4 as RetrievalService, b5 as SearchService, b5 as SearchServiceType, aL as WikiMemoryTestAccess, b6 as WriteService } from './testing-C8sYdo2S.js';
2
2
  import '@equationalapplications/core-okf';