@equationalapplications/core-llm-wiki 9.17.0 → 9.18.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/{chunk-QRGFHMFR.mjs → chunk-FX4J6MLA.mjs} +92 -19
- package/dist/chunk-FX4J6MLA.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +179 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -23
- package/dist/index.mjs.map +1 -1
- package/dist/{testing-BDYXXgaJ.d.mts → testing-CI0n5qQk.d.mts} +65 -4
- package/dist/{testing-BDYXXgaJ.d.ts → testing-CI0n5qQk.d.ts} +65 -4
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +71 -13
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-QRGFHMFR.mjs.map +0 -1
|
@@ -847,6 +847,14 @@ interface WikiEvent {
|
|
|
847
847
|
created_at: number;
|
|
848
848
|
/** Real-world time of the event (epoch ms). `created_at` stays ingestion time and remains the ordering key. */
|
|
849
849
|
occurred_at?: number | null;
|
|
850
|
+
/**
|
|
851
|
+
* Epoch ms the host forgot this event with `forget({ eventId })`; absent
|
|
852
|
+
* (never null on a read) while the event is live. A forgotten event is no
|
|
853
|
+
* longer raw material: no librarian pass, heal prompt, `read()` bundle or
|
|
854
|
+
* non-backup export carries it, and prune then `erase()` hard-delete it
|
|
855
|
+
* (specs/forget-event-exclusion).
|
|
856
|
+
*/
|
|
857
|
+
forgotten_at?: number | null;
|
|
850
858
|
}
|
|
851
859
|
interface WikiEdge {
|
|
852
860
|
id: string;
|
|
@@ -1551,7 +1559,11 @@ interface ForgetParams {
|
|
|
1551
1559
|
* merged this event's text into is deleted whole; entity-scoped; exact match, no normalization — event ids are
|
|
1552
1560
|
* engine-generated). Mutually exclusive with every other selector;
|
|
1553
1561
|
* `clearAll` excludes it. Removal reports through the return value and the
|
|
1554
|
-
* per-row outbox DELETE events.
|
|
1562
|
+
* per-row outbox DELETE events. The event row itself is also marked
|
|
1563
|
+
* forgotten (`forgotten_at`), so no librarian pass, heal prompt, `read()`
|
|
1564
|
+
* bundle or non-backup export carries its text again; prune then `erase()`
|
|
1565
|
+
* hard-delete it. See `specs/forget-by-event-id/` (issue #386) and
|
|
1566
|
+
* `specs/forget-event-exclusion/` (issue #472).
|
|
1555
1567
|
*/
|
|
1556
1568
|
eventId?: string;
|
|
1557
1569
|
/** Soft-delete every fact and task of the entity, delete its edges, and delete its source-ref index rows. */
|
|
@@ -1563,7 +1575,11 @@ interface ForgetParams {
|
|
|
1563
1575
|
*/
|
|
1564
1576
|
includeEvents?: boolean;
|
|
1565
1577
|
}
|
|
1566
|
-
/**
|
|
1578
|
+
/**
|
|
1579
|
+
* Result of {@link WikiMemory.forget}. `deleted.events` is present with
|
|
1580
|
+
* `includeEvents` (rows hard-deleted) and with the `eventId` selector (`0 | 1`:
|
|
1581
|
+
* whether the event row itself was marked forgotten).
|
|
1582
|
+
*/
|
|
1567
1583
|
interface ForgetResult {
|
|
1568
1584
|
deleted: {
|
|
1569
1585
|
entries: number;
|
|
@@ -2633,6 +2649,12 @@ declare class MetadataRepository extends BaseRepository {
|
|
|
2633
2649
|
*/
|
|
2634
2650
|
checkpointTruncateVerified(): Promise<void>;
|
|
2635
2651
|
vacuum(): Promise<void>;
|
|
2652
|
+
/**
|
|
2653
|
+
* True when `table` has `column`. A never-set-up or not-yet-migrated store
|
|
2654
|
+
* (the #316 recovery path) lacks columns later migrations add; callers that
|
|
2655
|
+
* must run there probe first.
|
|
2656
|
+
*/
|
|
2657
|
+
columnExists(table: string, column: string, tx?: SQLiteAdapter): Promise<boolean>;
|
|
2636
2658
|
/**
|
|
2637
2659
|
* Returns the set of distinct `entity_id` values across entries/tasks/events.
|
|
2638
2660
|
*
|
|
@@ -2643,7 +2665,7 @@ declare class MetadataRepository extends BaseRepository {
|
|
|
2643
2665
|
* is `entity_id COLLATE BINARY` for stable, locale-independent ordering.
|
|
2644
2666
|
*
|
|
2645
2667
|
* With `opts.softDeletedAtOrBefore` the walk is narrowed to entities holding
|
|
2646
|
-
* at least one soft-deleted entry or
|
|
2668
|
+
* at least one soft-deleted entry, task or forgotten event with `deleted_at` at or before
|
|
2647
2669
|
* that cutoff (erase's hard-delete walk, forget-erasure spec §2). Without
|
|
2648
2670
|
* the option the host-facing semantics above are unchanged.
|
|
2649
2671
|
*/
|
|
@@ -4026,8 +4048,13 @@ declare class EventRepository extends BaseRepository {
|
|
|
4026
4048
|
* The subset of `ids` that exist as events of `entityId` (specs/
|
|
4027
4049
|
* inplace-update-provenance §3). Chunked so a large batch stays under the
|
|
4028
4050
|
* bound-variable limit. Pass `tx` to read inside the caller's transaction.
|
|
4051
|
+
* `liveOnly` (default false) also requires `forgotten_at IS NULL`.
|
|
4029
4052
|
*/
|
|
4053
|
+
private findIds;
|
|
4054
|
+
/** Events that exist as rows, forgotten or not (apply re-check's gone-vs-forgotten probe, specs/forget-event-exclusion §4). */
|
|
4030
4055
|
findExistingIds(entityId: string, ids: readonly string[], tx?: SQLiteAdapter): Promise<Set<string>>;
|
|
4056
|
+
/** Events that exist and are not forgotten (specs/forget-event-exclusion §4). */
|
|
4057
|
+
findLiveIds(entityId: string, ids: readonly string[], tx?: SQLiteAdapter): Promise<Set<string>>;
|
|
4031
4058
|
/**
|
|
4032
4059
|
* Return the most recent events for an entity, newest first.
|
|
4033
4060
|
* Defaults to a limit of 50.
|
|
@@ -4080,7 +4107,9 @@ declare class EventRepository extends BaseRepository {
|
|
|
4080
4107
|
* Return all events for an entity in chronological (ASC) order.
|
|
4081
4108
|
* When limit is provided, fetches newest-first then reverses to preserve chronological order.
|
|
4082
4109
|
*/
|
|
4083
|
-
getByEntityId(entityId: string, limit?: number
|
|
4110
|
+
getByEntityId(entityId: string, limit?: number, opts?: {
|
|
4111
|
+
includeDeleted?: boolean;
|
|
4112
|
+
}): Promise<WikiEvent[]>;
|
|
4084
4113
|
/**
|
|
4085
4114
|
* Return events for `entityId` strictly after the watermark `(at, id)` in
|
|
4086
4115
|
* chronological (ASC, id-ASC tie-break) order. Pass `wm = null` to read
|
|
@@ -4112,6 +4141,38 @@ declare class EventRepository extends BaseRepository {
|
|
|
4112
4141
|
* (PR-C). SQLite's `LENGTH` returns character count for UTF-8 text input.
|
|
4113
4142
|
*/
|
|
4114
4143
|
sumSummaryCharsAfter(entityId: string, wm: LibrarianWatermark | null, tx?: SQLiteAdapter): Promise<number>;
|
|
4144
|
+
/**
|
|
4145
|
+
* Mark one event forgotten (specs/forget-event-exclusion §2). Entity scoped
|
|
4146
|
+
* (rule 3) and idempotent: an unknown id, another entity's id or an already
|
|
4147
|
+
* forgotten row changes nothing and reports 0.
|
|
4148
|
+
*/
|
|
4149
|
+
markForgotten(entityId: string, eventId: string, now: number, tx?: SQLiteAdapter): Promise<0 | 1>;
|
|
4150
|
+
/** 1 when the event exists for the entity and is not yet forgotten, else 0 (the forget dry run). */
|
|
4151
|
+
countForgettable(entityId: string, eventId: string): Promise<0 | 1>;
|
|
4152
|
+
/** True when `deleteForgotten` with the same arguments would delete at least one row. */
|
|
4153
|
+
hasDeletableForgotten(entityId: string, cutoff: number, tx: SQLiteAdapter, opts?: {
|
|
4154
|
+
noCutoff?: boolean;
|
|
4155
|
+
}): Promise<boolean>;
|
|
4156
|
+
/**
|
|
4157
|
+
* How many of the entity's first `n` events, in `(created_at, id)` order,
|
|
4158
|
+
* `deleteForgotten` with the same arguments would delete. The memory and
|
|
4159
|
+
* heal checkpoints count rows in that order, so this is exactly how far a
|
|
4160
|
+
* checkpoint must drop (specs/forget-event-exclusion §5). Call before the delete.
|
|
4161
|
+
*/
|
|
4162
|
+
countForgottenInPrefix(entityId: string, n: number, cutoff: number, tx: SQLiteAdapter, opts?: {
|
|
4163
|
+
noCutoff?: boolean;
|
|
4164
|
+
}): Promise<number>;
|
|
4165
|
+
/**
|
|
4166
|
+
* Hard-delete the entity's forgotten events (specs/forget-event-exclusion
|
|
4167
|
+
* §5). No watermark guard and no `retainEventsFor`: a forgotten row is never
|
|
4168
|
+
* read. `noCutoff` drops the age predicate (erase) so a non-numeric or
|
|
4169
|
+
* future `forgotten_at` cannot escape.
|
|
4170
|
+
*/
|
|
4171
|
+
deleteForgotten(entityId: string, cutoff: number, tx: SQLiteAdapter, opts?: {
|
|
4172
|
+
noCutoff?: boolean;
|
|
4173
|
+
}): Promise<{
|
|
4174
|
+
changes: number;
|
|
4175
|
+
}>;
|
|
4115
4176
|
}
|
|
4116
4177
|
|
|
4117
4178
|
interface UsageRecord {
|
|
@@ -847,6 +847,14 @@ interface WikiEvent {
|
|
|
847
847
|
created_at: number;
|
|
848
848
|
/** Real-world time of the event (epoch ms). `created_at` stays ingestion time and remains the ordering key. */
|
|
849
849
|
occurred_at?: number | null;
|
|
850
|
+
/**
|
|
851
|
+
* Epoch ms the host forgot this event with `forget({ eventId })`; absent
|
|
852
|
+
* (never null on a read) while the event is live. A forgotten event is no
|
|
853
|
+
* longer raw material: no librarian pass, heal prompt, `read()` bundle or
|
|
854
|
+
* non-backup export carries it, and prune then `erase()` hard-delete it
|
|
855
|
+
* (specs/forget-event-exclusion).
|
|
856
|
+
*/
|
|
857
|
+
forgotten_at?: number | null;
|
|
850
858
|
}
|
|
851
859
|
interface WikiEdge {
|
|
852
860
|
id: string;
|
|
@@ -1551,7 +1559,11 @@ interface ForgetParams {
|
|
|
1551
1559
|
* merged this event's text into is deleted whole; entity-scoped; exact match, no normalization — event ids are
|
|
1552
1560
|
* engine-generated). Mutually exclusive with every other selector;
|
|
1553
1561
|
* `clearAll` excludes it. Removal reports through the return value and the
|
|
1554
|
-
* per-row outbox DELETE events.
|
|
1562
|
+
* per-row outbox DELETE events. The event row itself is also marked
|
|
1563
|
+
* forgotten (`forgotten_at`), so no librarian pass, heal prompt, `read()`
|
|
1564
|
+
* bundle or non-backup export carries its text again; prune then `erase()`
|
|
1565
|
+
* hard-delete it. See `specs/forget-by-event-id/` (issue #386) and
|
|
1566
|
+
* `specs/forget-event-exclusion/` (issue #472).
|
|
1555
1567
|
*/
|
|
1556
1568
|
eventId?: string;
|
|
1557
1569
|
/** Soft-delete every fact and task of the entity, delete its edges, and delete its source-ref index rows. */
|
|
@@ -1563,7 +1575,11 @@ interface ForgetParams {
|
|
|
1563
1575
|
*/
|
|
1564
1576
|
includeEvents?: boolean;
|
|
1565
1577
|
}
|
|
1566
|
-
/**
|
|
1578
|
+
/**
|
|
1579
|
+
* Result of {@link WikiMemory.forget}. `deleted.events` is present with
|
|
1580
|
+
* `includeEvents` (rows hard-deleted) and with the `eventId` selector (`0 | 1`:
|
|
1581
|
+
* whether the event row itself was marked forgotten).
|
|
1582
|
+
*/
|
|
1567
1583
|
interface ForgetResult {
|
|
1568
1584
|
deleted: {
|
|
1569
1585
|
entries: number;
|
|
@@ -2633,6 +2649,12 @@ declare class MetadataRepository extends BaseRepository {
|
|
|
2633
2649
|
*/
|
|
2634
2650
|
checkpointTruncateVerified(): Promise<void>;
|
|
2635
2651
|
vacuum(): Promise<void>;
|
|
2652
|
+
/**
|
|
2653
|
+
* True when `table` has `column`. A never-set-up or not-yet-migrated store
|
|
2654
|
+
* (the #316 recovery path) lacks columns later migrations add; callers that
|
|
2655
|
+
* must run there probe first.
|
|
2656
|
+
*/
|
|
2657
|
+
columnExists(table: string, column: string, tx?: SQLiteAdapter): Promise<boolean>;
|
|
2636
2658
|
/**
|
|
2637
2659
|
* Returns the set of distinct `entity_id` values across entries/tasks/events.
|
|
2638
2660
|
*
|
|
@@ -2643,7 +2665,7 @@ declare class MetadataRepository extends BaseRepository {
|
|
|
2643
2665
|
* is `entity_id COLLATE BINARY` for stable, locale-independent ordering.
|
|
2644
2666
|
*
|
|
2645
2667
|
* With `opts.softDeletedAtOrBefore` the walk is narrowed to entities holding
|
|
2646
|
-
* at least one soft-deleted entry or
|
|
2668
|
+
* at least one soft-deleted entry, task or forgotten event with `deleted_at` at or before
|
|
2647
2669
|
* that cutoff (erase's hard-delete walk, forget-erasure spec §2). Without
|
|
2648
2670
|
* the option the host-facing semantics above are unchanged.
|
|
2649
2671
|
*/
|
|
@@ -4026,8 +4048,13 @@ declare class EventRepository extends BaseRepository {
|
|
|
4026
4048
|
* The subset of `ids` that exist as events of `entityId` (specs/
|
|
4027
4049
|
* inplace-update-provenance §3). Chunked so a large batch stays under the
|
|
4028
4050
|
* bound-variable limit. Pass `tx` to read inside the caller's transaction.
|
|
4051
|
+
* `liveOnly` (default false) also requires `forgotten_at IS NULL`.
|
|
4029
4052
|
*/
|
|
4053
|
+
private findIds;
|
|
4054
|
+
/** Events that exist as rows, forgotten or not (apply re-check's gone-vs-forgotten probe, specs/forget-event-exclusion §4). */
|
|
4030
4055
|
findExistingIds(entityId: string, ids: readonly string[], tx?: SQLiteAdapter): Promise<Set<string>>;
|
|
4056
|
+
/** Events that exist and are not forgotten (specs/forget-event-exclusion §4). */
|
|
4057
|
+
findLiveIds(entityId: string, ids: readonly string[], tx?: SQLiteAdapter): Promise<Set<string>>;
|
|
4031
4058
|
/**
|
|
4032
4059
|
* Return the most recent events for an entity, newest first.
|
|
4033
4060
|
* Defaults to a limit of 50.
|
|
@@ -4080,7 +4107,9 @@ declare class EventRepository extends BaseRepository {
|
|
|
4080
4107
|
* Return all events for an entity in chronological (ASC) order.
|
|
4081
4108
|
* When limit is provided, fetches newest-first then reverses to preserve chronological order.
|
|
4082
4109
|
*/
|
|
4083
|
-
getByEntityId(entityId: string, limit?: number
|
|
4110
|
+
getByEntityId(entityId: string, limit?: number, opts?: {
|
|
4111
|
+
includeDeleted?: boolean;
|
|
4112
|
+
}): Promise<WikiEvent[]>;
|
|
4084
4113
|
/**
|
|
4085
4114
|
* Return events for `entityId` strictly after the watermark `(at, id)` in
|
|
4086
4115
|
* chronological (ASC, id-ASC tie-break) order. Pass `wm = null` to read
|
|
@@ -4112,6 +4141,38 @@ declare class EventRepository extends BaseRepository {
|
|
|
4112
4141
|
* (PR-C). SQLite's `LENGTH` returns character count for UTF-8 text input.
|
|
4113
4142
|
*/
|
|
4114
4143
|
sumSummaryCharsAfter(entityId: string, wm: LibrarianWatermark | null, tx?: SQLiteAdapter): Promise<number>;
|
|
4144
|
+
/**
|
|
4145
|
+
* Mark one event forgotten (specs/forget-event-exclusion §2). Entity scoped
|
|
4146
|
+
* (rule 3) and idempotent: an unknown id, another entity's id or an already
|
|
4147
|
+
* forgotten row changes nothing and reports 0.
|
|
4148
|
+
*/
|
|
4149
|
+
markForgotten(entityId: string, eventId: string, now: number, tx?: SQLiteAdapter): Promise<0 | 1>;
|
|
4150
|
+
/** 1 when the event exists for the entity and is not yet forgotten, else 0 (the forget dry run). */
|
|
4151
|
+
countForgettable(entityId: string, eventId: string): Promise<0 | 1>;
|
|
4152
|
+
/** True when `deleteForgotten` with the same arguments would delete at least one row. */
|
|
4153
|
+
hasDeletableForgotten(entityId: string, cutoff: number, tx: SQLiteAdapter, opts?: {
|
|
4154
|
+
noCutoff?: boolean;
|
|
4155
|
+
}): Promise<boolean>;
|
|
4156
|
+
/**
|
|
4157
|
+
* How many of the entity's first `n` events, in `(created_at, id)` order,
|
|
4158
|
+
* `deleteForgotten` with the same arguments would delete. The memory and
|
|
4159
|
+
* heal checkpoints count rows in that order, so this is exactly how far a
|
|
4160
|
+
* checkpoint must drop (specs/forget-event-exclusion §5). Call before the delete.
|
|
4161
|
+
*/
|
|
4162
|
+
countForgottenInPrefix(entityId: string, n: number, cutoff: number, tx: SQLiteAdapter, opts?: {
|
|
4163
|
+
noCutoff?: boolean;
|
|
4164
|
+
}): Promise<number>;
|
|
4165
|
+
/**
|
|
4166
|
+
* Hard-delete the entity's forgotten events (specs/forget-event-exclusion
|
|
4167
|
+
* §5). No watermark guard and no `retainEventsFor`: a forgotten row is never
|
|
4168
|
+
* read. `noCutoff` drops the age predicate (erase) so a non-numeric or
|
|
4169
|
+
* future `forgotten_at` cannot escape.
|
|
4170
|
+
*/
|
|
4171
|
+
deleteForgotten(entityId: string, cutoff: number, tx: SQLiteAdapter, opts?: {
|
|
4172
|
+
noCutoff?: boolean;
|
|
4173
|
+
}): Promise<{
|
|
4174
|
+
changes: number;
|
|
4175
|
+
}>;
|
|
4115
4176
|
}
|
|
4116
4177
|
|
|
4117
4178
|
interface UsageRecord {
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { b0 as EmbeddingService, b1 as ImportExportService, b2 as IngestionService, b3 as JobManager, b3 as JobManagerType, b4 as MaintenanceService, b5 as RetrievalService, b6 as SearchService, b6 as SearchServiceType, aM as WikiMemoryTestAccess, b7 as WriteService } from './testing-
|
|
1
|
+
export { b0 as EmbeddingService, b1 as ImportExportService, b2 as IngestionService, b3 as JobManager, b3 as JobManagerType, b4 as MaintenanceService, b5 as RetrievalService, b6 as SearchService, b6 as SearchServiceType, aM as WikiMemoryTestAccess, b7 as WriteService } from './testing-CI0n5qQk.mjs';
|
|
2
2
|
import '@equationalapplications/core-okf';
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { b0 as EmbeddingService, b1 as ImportExportService, b2 as IngestionService, b3 as JobManager, b3 as JobManagerType, b4 as MaintenanceService, b5 as RetrievalService, b6 as SearchService, b6 as SearchServiceType, aM as WikiMemoryTestAccess, b7 as WriteService } from './testing-
|
|
1
|
+
export { b0 as EmbeddingService, b1 as ImportExportService, b2 as IngestionService, b3 as JobManager, b3 as JobManagerType, b4 as MaintenanceService, b5 as RetrievalService, b6 as SearchService, b6 as SearchServiceType, aM as WikiMemoryTestAccess, b7 as WriteService } from './testing-CI0n5qQk.js';
|
|
2
2
|
import '@equationalapplications/core-okf';
|
package/dist/testing.js
CHANGED
|
@@ -819,7 +819,7 @@ var MESSAGE = {
|
|
|
819
819
|
guidance_resolver_failed: "The per-entity guidance resolver failed; its value was not used for this pass.",
|
|
820
820
|
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).",
|
|
821
821
|
source_pointer_invalid: "Import met a malformed source pointer value and stored a null pointer.",
|
|
822
|
-
source_event_gone: "A librarian candidate was dropped at apply time because the event it came from no longer
|
|
822
|
+
source_event_gone: "A librarian candidate was dropped at apply time because the event it came from was no longer available: deleted (detail.reason gone) or forgotten with forget({ eventId }) (detail.reason forgotten) outside this instance while the pass ran.",
|
|
823
823
|
derived_events_invalid: "Import met a malformed derived_events value and stored null.",
|
|
824
824
|
source_store_source_too_large: "A source document exceeded the per-document size cap and was not stored.",
|
|
825
825
|
source_store_budget_exceeded: "Storing a source document would exceed the store UTF-16 code-unit budget and it was not stored.",
|
|
@@ -1942,7 +1942,7 @@ var ImportExportService = class {
|
|
|
1942
1942
|
const [factsRaw, tasks, events, edges, summaryValue] = await Promise.all([
|
|
1943
1943
|
opts?.includeBlobs ? this.entryRepo.findAllByEntityIdWithBlobs(entityId, void 0, incl) : this.entryRepo.findAllByEntityId(entityId, void 0, incl),
|
|
1944
1944
|
this.taskRepo.findAllByEntityId(entityId, void 0, incl),
|
|
1945
|
-
this.eventRepo.getByEntityId(entityId, opts?.maxEvents),
|
|
1945
|
+
this.eventRepo.getByEntityId(entityId, opts?.maxEvents, incl),
|
|
1946
1946
|
this.edgeRepo.getByEntityId(entityId),
|
|
1947
1947
|
this.metadataRepo.getMeta(entitySummaryMetaKey(entityId))
|
|
1948
1948
|
]);
|
|
@@ -2273,10 +2273,14 @@ var ImportExportService = class {
|
|
|
2273
2273
|
summary: event.summary,
|
|
2274
2274
|
related_entry_id: event.related_entry_id ?? null,
|
|
2275
2275
|
created_at: stamp.createdAt,
|
|
2276
|
-
occurred_at: stamp.occurredAt
|
|
2276
|
+
occurred_at: stamp.occurredAt,
|
|
2277
|
+
forgotten_at: event.forgotten_at ?? null
|
|
2277
2278
|
},
|
|
2278
2279
|
tx
|
|
2279
2280
|
);
|
|
2281
|
+
if (!inserted && event.forgotten_at != null) {
|
|
2282
|
+
await this.eventRepo.markForgotten(entityId, event.id, event.forgotten_at, tx);
|
|
2283
|
+
}
|
|
2280
2284
|
if (!inserted || stamp.reason === null) continue;
|
|
2281
2285
|
if (stamp.reason === "future") clampedEvents++;
|
|
2282
2286
|
else restamped[stamp.reason]++;
|
|
@@ -5415,8 +5419,27 @@ var MIGRATIONS = [
|
|
|
5415
5419
|
await addPriorValidToColumn(db, prefix);
|
|
5416
5420
|
await addDerivedEventsColumn(db, prefix);
|
|
5417
5421
|
}
|
|
5422
|
+
},
|
|
5423
|
+
{
|
|
5424
|
+
version: 19,
|
|
5425
|
+
description: "Nullable events.forgotten_at column and partial index marking events the host forgot with forget({ eventId }) (specs/forget-event-exclusion)",
|
|
5426
|
+
run: async (db, prefix) => {
|
|
5427
|
+
await addEventsForgottenAtColumn(db, prefix);
|
|
5428
|
+
await createEventsForgottenIndex(db, prefix);
|
|
5429
|
+
}
|
|
5418
5430
|
}
|
|
5419
5431
|
];
|
|
5432
|
+
async function addEventsForgottenAtColumn(db, prefix) {
|
|
5433
|
+
const cols = await db.getAllAsync(`PRAGMA table_info(${prefix}events)`);
|
|
5434
|
+
if (!cols.some((c) => c.name === "forgotten_at")) {
|
|
5435
|
+
await db.execAsync(`ALTER TABLE ${prefix}events ADD COLUMN forgotten_at INTEGER`);
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
async function createEventsForgottenIndex(db, prefix) {
|
|
5439
|
+
await db.execAsync(
|
|
5440
|
+
`CREATE INDEX IF NOT EXISTS ${prefix}events_forgotten_idx ON ${prefix}events(entity_id, forgotten_at) WHERE forgotten_at IS NOT NULL`
|
|
5441
|
+
);
|
|
5442
|
+
}
|
|
5420
5443
|
async function addPriorValidToColumn(db, prefix) {
|
|
5421
5444
|
const cols = await db.getAllAsync(`PRAGMA table_info(${prefix}entries)`);
|
|
5422
5445
|
if (!cols.some((c) => c.name === "prior_valid_to")) {
|
|
@@ -5480,6 +5503,9 @@ var runLegacyLibrarianPass = async (deps, ctx) => {
|
|
|
5480
5503
|
const { entityId, trigger } = ctx;
|
|
5481
5504
|
const promptOverride = ctx.promptOverride;
|
|
5482
5505
|
const events = await deps.eventRepo.getRecent(entityId, 50);
|
|
5506
|
+
if (events.length === 0 && await deps.eventRepo.count(entityId) > 0) {
|
|
5507
|
+
return { processedThrough: null, factsWritten: 0 };
|
|
5508
|
+
}
|
|
5483
5509
|
const currentFactsRows = await deps.entryRepo.findRecentByEntityId(entityId, 100);
|
|
5484
5510
|
const currentFacts = currentFactsRows.map((f) => {
|
|
5485
5511
|
const { embedding: _embedding, embedding_blob: _blob, ...rest } = f;
|
|
@@ -6310,12 +6336,18 @@ async function applyOps(deps, ctx, input) {
|
|
|
6310
6336
|
return id;
|
|
6311
6337
|
};
|
|
6312
6338
|
const sourceIds = [...new Set(input.gated.map((g) => g.candidate.sourceEventId).filter((x) => x !== null))];
|
|
6313
|
-
const presentIds = sourceIds.length > 0 ? await deps.eventRepo.
|
|
6339
|
+
const presentIds = sourceIds.length > 0 ? await deps.eventRepo.findLiveIds(entityId, sourceIds, tx) : /* @__PURE__ */ new Set();
|
|
6340
|
+
const failedIds = sourceIds.filter((id) => !presentIds.has(id));
|
|
6341
|
+
const stillExist = failedIds.length > 0 ? await deps.eventRepo.findExistingIds(entityId, failedIds, tx) : /* @__PURE__ */ new Set();
|
|
6314
6342
|
const gatedLive = [];
|
|
6315
6343
|
for (const g of input.gated) {
|
|
6316
6344
|
const ev = g.candidate.sourceEventId;
|
|
6317
6345
|
if (ev !== null && !presentIds.has(ev)) {
|
|
6318
|
-
input.diagnostics.push({
|
|
6346
|
+
input.diagnostics.push({
|
|
6347
|
+
...diagBase,
|
|
6348
|
+
code: "source_event_gone",
|
|
6349
|
+
detail: { itemIndex: g.candidate.index, sourceRef: ev, reason: stillExist.has(ev) ? "forgotten" : "gone" }
|
|
6350
|
+
});
|
|
6319
6351
|
continue;
|
|
6320
6352
|
}
|
|
6321
6353
|
gatedLive.push(g);
|
|
@@ -6757,6 +6789,21 @@ var _MaintenanceService = class _MaintenanceService {
|
|
|
6757
6789
|
}
|
|
6758
6790
|
}
|
|
6759
6791
|
deletedTasks = await this.taskRepo.bulkDeletePruned(entityId, cutoff, tx, { noCutoff: softDeletedAll });
|
|
6792
|
+
const delOpts = { noCutoff: softDeletedAll };
|
|
6793
|
+
const hasForgottenCol = await this.metadataRepo.columnExists(`${this.prefix}events`, "forgotten_at", tx) && await this.eventRepo.hasDeletableForgotten(entityId, cutoff, tx, delOpts);
|
|
6794
|
+
const cpBefore = hasForgottenCol ? await this.metadataRepo.getCheckpoint(entityId, tx) : null;
|
|
6795
|
+
const memDrop = cpBefore && (cpBefore.memory ?? 0) > 0 ? await this.eventRepo.countForgottenInPrefix(entityId, cpBefore.memory, cutoff, tx, delOpts) : 0;
|
|
6796
|
+
const healDrop = cpBefore && (cpBefore.heal ?? 0) > 0 ? await this.eventRepo.countForgottenInPrefix(entityId, cpBefore.heal, cutoff, tx, delOpts) : 0;
|
|
6797
|
+
const forgottenGone = hasForgottenCol ? (await this.eventRepo.deleteForgotten(entityId, cutoff, tx, delOpts)).changes : 0;
|
|
6798
|
+
if (forgottenGone > 0) {
|
|
6799
|
+
deletedEvents += forgottenGone;
|
|
6800
|
+
const updates = {};
|
|
6801
|
+
if (memDrop > 0) updates.memory = Math.max(0, cpBefore.memory - memDrop);
|
|
6802
|
+
if (healDrop > 0) updates.heal = Math.max(0, cpBefore.heal - healDrop);
|
|
6803
|
+
if (updates.memory !== void 0 || updates.heal !== void 0) {
|
|
6804
|
+
await this.metadataRepo.updateCheckpoint(entityId, updates, tx);
|
|
6805
|
+
}
|
|
6806
|
+
}
|
|
6760
6807
|
});
|
|
6761
6808
|
if (hookLedger) {
|
|
6762
6809
|
const keptSet = new Set(kept);
|
|
@@ -6777,18 +6824,20 @@ var _MaintenanceService = class _MaintenanceService {
|
|
|
6777
6824
|
const cutoff = now - retainEventsFor * 864e5;
|
|
6778
6825
|
const guarded = resolveMaintenanceMode(this.options.config) === "deferred" || resolveLibrarianStrategy(this.options.config) === "ops";
|
|
6779
6826
|
let wm = null;
|
|
6827
|
+
let retentionDeleted = 0;
|
|
6780
6828
|
await this.db.withTransactionAsync(async (tx) => {
|
|
6781
6829
|
if (guarded) {
|
|
6782
6830
|
wm = await this.metadataRepo.getLibrarianWatermark(entityId, tx);
|
|
6783
|
-
|
|
6831
|
+
retentionDeleted = (await this.eventRepo.pruneThrough(entityId, cutoff, wm, tx)).changes;
|
|
6784
6832
|
} else {
|
|
6785
|
-
|
|
6833
|
+
retentionDeleted = (await this.eventRepo.prune(entityId, cutoff, tx)).changes;
|
|
6786
6834
|
}
|
|
6787
|
-
|
|
6835
|
+
deletedEvents += retentionDeleted;
|
|
6836
|
+
if (retentionDeleted > 0) {
|
|
6788
6837
|
const cp = await this.metadataRepo.getCheckpoint(entityId, tx);
|
|
6789
6838
|
const updates = {};
|
|
6790
|
-
if ((cp.memory ?? 0) > 0) updates.memory = Math.max(0, cp.memory -
|
|
6791
|
-
if ((cp.heal ?? 0) > 0) updates.heal = Math.max(0, cp.heal -
|
|
6839
|
+
if ((cp.memory ?? 0) > 0) updates.memory = Math.max(0, cp.memory - retentionDeleted);
|
|
6840
|
+
if ((cp.heal ?? 0) > 0) updates.heal = Math.max(0, cp.heal - retentionDeleted);
|
|
6792
6841
|
if (updates.memory !== void 0 || updates.heal !== void 0) {
|
|
6793
6842
|
await this.metadataRepo.updateCheckpoint(entityId, updates, tx);
|
|
6794
6843
|
}
|
|
@@ -6996,9 +7045,11 @@ var _MaintenanceService = class _MaintenanceService {
|
|
|
6996
7045
|
if (report.skipped.length === 0 && report.holds.length === 0) {
|
|
6997
7046
|
let remainingTombstones;
|
|
6998
7047
|
try {
|
|
7048
|
+
const eventsTracked = await this.metadataRepo.columnExists(`${this.prefix}events`, "forgotten_at");
|
|
6999
7049
|
const row = await this.db.getFirstAsync(
|
|
7000
7050
|
`SELECT (SELECT COUNT(*) FROM ${this.prefix}entries WHERE deleted_at IS NOT NULL)
|
|
7001
|
-
+ (SELECT COUNT(*) FROM ${this.prefix}tasks WHERE deleted_at IS NOT NULL)
|
|
7051
|
+
+ (SELECT COUNT(*) FROM ${this.prefix}tasks WHERE deleted_at IS NOT NULL)
|
|
7052
|
+
${eventsTracked ? `+ (SELECT COUNT(*) FROM ${this.prefix}events WHERE forgotten_at IS NOT NULL)` : ""} AS n`
|
|
7002
7053
|
);
|
|
7003
7054
|
remainingTombstones = row?.n ?? 0;
|
|
7004
7055
|
} catch (err) {
|
|
@@ -7411,6 +7462,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7411
7462
|
let deletedEntries = 0;
|
|
7412
7463
|
let deletedTasks = 0;
|
|
7413
7464
|
let deletedEvents = 0;
|
|
7465
|
+
let eventMarked = 0;
|
|
7414
7466
|
let chainIds = [];
|
|
7415
7467
|
let chainTruncated = false;
|
|
7416
7468
|
const deletedEntryIds = [];
|
|
@@ -7491,6 +7543,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7491
7543
|
if (taskResult) deletedTasks++;
|
|
7492
7544
|
deletedEntries += refResult;
|
|
7493
7545
|
deletedEntries += pointerResult;
|
|
7546
|
+
if (params.eventId !== void 0) {
|
|
7547
|
+
eventMarked = await this.metadataRepo.columnExists(`${this.prefix}events`, "forgotten_at", tx) ? await this.eventRepo.markForgotten(entityId, params.eventId, now, tx) : 0;
|
|
7548
|
+
}
|
|
7494
7549
|
}
|
|
7495
7550
|
if (ledgerOn && this.vectorRemoval?.gate() === "hook" && deletedEntryIds.length > 0) {
|
|
7496
7551
|
await this.vectorRemovalRepo?.backstopEnqueue(entityId, Array.from(new Set(deletedEntryIds)), now, tx);
|
|
@@ -7543,7 +7598,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7543
7598
|
}
|
|
7544
7599
|
}
|
|
7545
7600
|
if (!params.clearAll) {
|
|
7546
|
-
const base = {
|
|
7601
|
+
const base = {
|
|
7602
|
+
deleted: params.eventId !== void 0 ? { entries: deletedEntries, tasks: deletedTasks, events: eventMarked } : { entries: deletedEntries, tasks: deletedTasks }
|
|
7603
|
+
};
|
|
7547
7604
|
if (params.includeChain) {
|
|
7548
7605
|
base.chainEntryIds = chainIds;
|
|
7549
7606
|
if (chainTruncated) {
|
|
@@ -7649,7 +7706,8 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7649
7706
|
}
|
|
7650
7707
|
if (params.eventId !== void 0) {
|
|
7651
7708
|
const entries2 = await this.entryRepo.countLiveByPointerEvent(entityId, params.eventId);
|
|
7652
|
-
|
|
7709
|
+
const events = await this.metadataRepo.columnExists(`${this.prefix}events`, "forgotten_at") ? await this.eventRepo.countForgettable(entityId, params.eventId) : 0;
|
|
7710
|
+
return { deleted: { entries: entries2, tasks: 0, events } };
|
|
7653
7711
|
}
|
|
7654
7712
|
const sourceRef = params.sourceRef !== void 0 ? normalizeSourceRef(params.sourceRef) : null;
|
|
7655
7713
|
if (params.sourceRef !== void 0 && !sourceRef) throw new Error("Invalid sourceRef");
|