@equationalapplications/core-llm-wiki 9.17.0 → 9.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-QRGFHMFR.mjs → chunk-HH2BH2HS.mjs} +101 -28
- package/dist/chunk-HH2BH2HS.mjs.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +188 -46
- 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
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-
|
|
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-
|
|
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';
|
|
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-
|
|
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-
|
|
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';
|
|
3
3
|
import { OkfFile } from '@equationalapplications/core-okf';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/index.js
CHANGED
|
@@ -427,7 +427,7 @@ var MESSAGE = {
|
|
|
427
427
|
guidance_resolver_failed: "The per-entity guidance resolver failed; its value was not used for this pass.",
|
|
428
428
|
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).",
|
|
429
429
|
source_pointer_invalid: "Import met a malformed source pointer value and stored a null pointer.",
|
|
430
|
-
source_event_gone: "A librarian candidate was dropped at apply time because the event it came from no longer
|
|
430
|
+
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.",
|
|
431
431
|
derived_events_invalid: "Import met a malformed derived_events value and stored null.",
|
|
432
432
|
source_store_source_too_large: "A source document exceeded the per-document size cap and was not stored.",
|
|
433
433
|
source_store_budget_exceeded: "Storing a source document would exceed the store UTF-16 code-unit budget and it was not stored.",
|
|
@@ -2122,7 +2122,8 @@ async function setupDatabase(db, prefix) {
|
|
|
2122
2122
|
summary TEXT NOT NULL,
|
|
2123
2123
|
related_entry_id TEXT,
|
|
2124
2124
|
created_at INTEGER NOT NULL,
|
|
2125
|
-
occurred_at INTEGER
|
|
2125
|
+
occurred_at INTEGER,
|
|
2126
|
+
forgotten_at INTEGER
|
|
2126
2127
|
);
|
|
2127
2128
|
|
|
2128
2129
|
CREATE INDEX IF NOT EXISTS ${prefix}events_entity_idx ON ${prefix}events(entity_id, created_at DESC);
|
|
@@ -2824,8 +2825,27 @@ var MIGRATIONS = [
|
|
|
2824
2825
|
await addPriorValidToColumn(db, prefix);
|
|
2825
2826
|
await addDerivedEventsColumn(db, prefix);
|
|
2826
2827
|
}
|
|
2828
|
+
},
|
|
2829
|
+
{
|
|
2830
|
+
version: 19,
|
|
2831
|
+
description: "Nullable events.forgotten_at column and partial index marking events the host forgot with forget({ eventId }) (specs/forget-event-exclusion)",
|
|
2832
|
+
run: async (db, prefix) => {
|
|
2833
|
+
await addEventsForgottenAtColumn(db, prefix);
|
|
2834
|
+
await createEventsForgottenIndex(db, prefix);
|
|
2835
|
+
}
|
|
2827
2836
|
}
|
|
2828
2837
|
];
|
|
2838
|
+
async function addEventsForgottenAtColumn(db, prefix) {
|
|
2839
|
+
const cols = await db.getAllAsync(`PRAGMA table_info(${prefix}events)`);
|
|
2840
|
+
if (!cols.some((c) => c.name === "forgotten_at")) {
|
|
2841
|
+
await db.execAsync(`ALTER TABLE ${prefix}events ADD COLUMN forgotten_at INTEGER`);
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
async function createEventsForgottenIndex(db, prefix) {
|
|
2845
|
+
await db.execAsync(
|
|
2846
|
+
`CREATE INDEX IF NOT EXISTS ${prefix}events_forgotten_idx ON ${prefix}events(entity_id, forgotten_at) WHERE forgotten_at IS NOT NULL`
|
|
2847
|
+
);
|
|
2848
|
+
}
|
|
2829
2849
|
async function addPriorValidToColumn(db, prefix) {
|
|
2830
2850
|
const cols = await db.getAllAsync(`PRAGMA table_info(${prefix}entries)`);
|
|
2831
2851
|
if (!cols.some((c) => c.name === "prior_valid_to")) {
|
|
@@ -5268,12 +5288,13 @@ function afterArgs(wm) {
|
|
|
5268
5288
|
return [wm.at, wm.at, wm.id];
|
|
5269
5289
|
}
|
|
5270
5290
|
function mapEvent(row) {
|
|
5271
|
-
|
|
5272
|
-
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5291
|
+
const dropOccurred = row.occurred_at == null;
|
|
5292
|
+
const dropForgotten = row.forgotten_at == null;
|
|
5293
|
+
if (!dropOccurred && !dropForgotten) return row;
|
|
5294
|
+
const rest = { ...row };
|
|
5295
|
+
if (dropOccurred) delete rest.occurred_at;
|
|
5296
|
+
if (dropForgotten) delete rest.forgotten_at;
|
|
5297
|
+
return rest;
|
|
5277
5298
|
}
|
|
5278
5299
|
var EventRepository = class extends BaseRepository {
|
|
5279
5300
|
/**
|
|
@@ -5300,8 +5321,8 @@ var EventRepository = class extends BaseRepository {
|
|
|
5300
5321
|
async addIgnoreDuplicate(event, tx) {
|
|
5301
5322
|
const executor = this.getExecutor(tx);
|
|
5302
5323
|
const result = await executor.runAsync(
|
|
5303
|
-
`INSERT OR IGNORE INTO ${this.prefix}events (id, entity_id, event_type, summary, related_entry_id, created_at, occurred_at)
|
|
5304
|
-
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
|
5324
|
+
`INSERT OR IGNORE INTO ${this.prefix}events (id, entity_id, event_type, summary, related_entry_id, created_at, occurred_at, forgotten_at)
|
|
5325
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
5305
5326
|
[
|
|
5306
5327
|
event.id,
|
|
5307
5328
|
event.entity_id,
|
|
@@ -5309,7 +5330,8 @@ var EventRepository = class extends BaseRepository {
|
|
|
5309
5330
|
event.summary,
|
|
5310
5331
|
event.related_entry_id ?? null,
|
|
5311
5332
|
event.created_at,
|
|
5312
|
-
event.occurred_at ?? null
|
|
5333
|
+
event.occurred_at ?? null,
|
|
5334
|
+
event.forgotten_at ?? null
|
|
5313
5335
|
]
|
|
5314
5336
|
);
|
|
5315
5337
|
return result.changes > 0;
|
|
@@ -5318,27 +5340,37 @@ var EventRepository = class extends BaseRepository {
|
|
|
5318
5340
|
* The subset of `ids` that exist as events of `entityId` (specs/
|
|
5319
5341
|
* inplace-update-provenance §3). Chunked so a large batch stays under the
|
|
5320
5342
|
* bound-variable limit. Pass `tx` to read inside the caller's transaction.
|
|
5343
|
+
* `liveOnly` (default false) also requires `forgotten_at IS NULL`.
|
|
5321
5344
|
*/
|
|
5322
|
-
async
|
|
5345
|
+
async findIds(entityId, ids, liveOnly, tx) {
|
|
5323
5346
|
const executor = this.getExecutor(tx);
|
|
5324
5347
|
const found = /* @__PURE__ */ new Set();
|
|
5348
|
+
const live = liveOnly ? " AND forgotten_at IS NULL" : "";
|
|
5325
5349
|
for (let i = 0; i < ids.length; i += 500) {
|
|
5326
5350
|
const chunk = ids.slice(i, i + 500);
|
|
5327
5351
|
const rows = await executor.getAllAsync(
|
|
5328
|
-
`SELECT id FROM ${this.prefix}events WHERE entity_id = ? AND id IN (${chunk.map(() => "?").join(",")})`,
|
|
5352
|
+
`SELECT id FROM ${this.prefix}events WHERE entity_id = ? AND id IN (${chunk.map(() => "?").join(",")})${live}`,
|
|
5329
5353
|
[entityId, ...chunk]
|
|
5330
5354
|
);
|
|
5331
5355
|
for (const r of rows) found.add(r.id);
|
|
5332
5356
|
}
|
|
5333
5357
|
return found;
|
|
5334
5358
|
}
|
|
5359
|
+
/** Events that exist as rows, forgotten or not (apply re-check's gone-vs-forgotten probe, specs/forget-event-exclusion §4). */
|
|
5360
|
+
async findExistingIds(entityId, ids, tx) {
|
|
5361
|
+
return this.findIds(entityId, ids, false, tx);
|
|
5362
|
+
}
|
|
5363
|
+
/** Events that exist and are not forgotten (specs/forget-event-exclusion §4). */
|
|
5364
|
+
async findLiveIds(entityId, ids, tx) {
|
|
5365
|
+
return this.findIds(entityId, ids, true, tx);
|
|
5366
|
+
}
|
|
5335
5367
|
/**
|
|
5336
5368
|
* Return the most recent events for an entity, newest first.
|
|
5337
5369
|
* Defaults to a limit of 50.
|
|
5338
5370
|
*/
|
|
5339
5371
|
async getRecent(entityId, limit = 50) {
|
|
5340
5372
|
const rows = await this.db.getAllAsync(
|
|
5341
|
-
`SELECT * FROM ${this.prefix}events WHERE entity_id = ? ORDER BY created_at DESC LIMIT ?`,
|
|
5373
|
+
`SELECT * FROM ${this.prefix}events WHERE entity_id = ? AND forgotten_at IS NULL ORDER BY created_at DESC LIMIT ?`,
|
|
5342
5374
|
[entityId, limit]
|
|
5343
5375
|
);
|
|
5344
5376
|
return rows.map(mapEvent);
|
|
@@ -5351,7 +5383,7 @@ var EventRepository = class extends BaseRepository {
|
|
|
5351
5383
|
if (entityIds.length === 0) return [];
|
|
5352
5384
|
const placeholders = entityIds.map(() => "?").join(", ");
|
|
5353
5385
|
const rows = await this.db.getAllAsync(
|
|
5354
|
-
`SELECT * FROM ${this.prefix}events WHERE entity_id IN (${placeholders}) ORDER BY created_at DESC LIMIT ?`,
|
|
5386
|
+
`SELECT * FROM ${this.prefix}events WHERE entity_id IN (${placeholders}) AND forgotten_at IS NULL ORDER BY created_at DESC LIMIT ?`,
|
|
5355
5387
|
[...entityIds, limit]
|
|
5356
5388
|
);
|
|
5357
5389
|
return rows.map(mapEvent);
|
|
@@ -5392,7 +5424,7 @@ var EventRepository = class extends BaseRepository {
|
|
|
5392
5424
|
async countHeldBack(entityId, cutoff, wm) {
|
|
5393
5425
|
const where = wm ? ` AND ${AFTER_SQL}` : "";
|
|
5394
5426
|
const row = await this.db.getFirstAsync(
|
|
5395
|
-
`SELECT COUNT(*) AS n FROM ${this.prefix}events WHERE entity_id = ? AND created_at <=
|
|
5427
|
+
`SELECT COUNT(*) AS n FROM ${this.prefix}events WHERE entity_id = ? AND created_at <= ? AND forgotten_at IS NULL${where}`,
|
|
5396
5428
|
[entityId, cutoff, ...wm ? afterArgs(wm) : []]
|
|
5397
5429
|
);
|
|
5398
5430
|
return Number(row?.n ?? 0);
|
|
@@ -5425,16 +5457,17 @@ var EventRepository = class extends BaseRepository {
|
|
|
5425
5457
|
* Return all events for an entity in chronological (ASC) order.
|
|
5426
5458
|
* When limit is provided, fetches newest-first then reverses to preserve chronological order.
|
|
5427
5459
|
*/
|
|
5428
|
-
async getByEntityId(entityId, limit) {
|
|
5460
|
+
async getByEntityId(entityId, limit, opts) {
|
|
5461
|
+
const live = opts?.includeDeleted ? "" : " AND forgotten_at IS NULL";
|
|
5429
5462
|
if (limit != null) {
|
|
5430
5463
|
const rows2 = await this.db.getAllAsync(
|
|
5431
|
-
`SELECT * FROM ${this.prefix}events WHERE entity_id =
|
|
5464
|
+
`SELECT * FROM ${this.prefix}events WHERE entity_id = ?${live} ORDER BY created_at DESC LIMIT ?`,
|
|
5432
5465
|
[entityId, limit]
|
|
5433
5466
|
);
|
|
5434
5467
|
return rows2.map(mapEvent).slice().reverse();
|
|
5435
5468
|
}
|
|
5436
5469
|
const rows = await this.db.getAllAsync(
|
|
5437
|
-
`SELECT * FROM ${this.prefix}events WHERE entity_id =
|
|
5470
|
+
`SELECT * FROM ${this.prefix}events WHERE entity_id = ?${live} ORDER BY created_at ASC`,
|
|
5438
5471
|
[entityId]
|
|
5439
5472
|
);
|
|
5440
5473
|
return rows.map(mapEvent);
|
|
@@ -5449,7 +5482,7 @@ var EventRepository = class extends BaseRepository {
|
|
|
5449
5482
|
async getAfter(entityId, wm, limit) {
|
|
5450
5483
|
const limitClause = limit != null ? ` LIMIT ?` : "";
|
|
5451
5484
|
const params = wm ? [entityId, wm.at, wm.at, wm.id] : [entityId];
|
|
5452
|
-
const where = wm ? `entity_id = ? AND ${AFTER_SQL}` : `entity_id =
|
|
5485
|
+
const where = wm ? `entity_id = ? AND forgotten_at IS NULL AND ${AFTER_SQL}` : `entity_id = ? AND forgotten_at IS NULL`;
|
|
5453
5486
|
if (limit != null) params.push(limit);
|
|
5454
5487
|
const rows = await this.db.getAllAsync(
|
|
5455
5488
|
`SELECT * FROM ${this.prefix}events WHERE ${where} ORDER BY created_at ASC, id ASC${limitClause}`,
|
|
@@ -5465,7 +5498,7 @@ var EventRepository = class extends BaseRepository {
|
|
|
5465
5498
|
*/
|
|
5466
5499
|
async countAfter(entityId, wm) {
|
|
5467
5500
|
const params = wm ? [entityId, wm.at, wm.at, wm.id] : [entityId];
|
|
5468
|
-
const where = wm ? `entity_id = ? AND ${AFTER_SQL}` : `entity_id =
|
|
5501
|
+
const where = wm ? `entity_id = ? AND forgotten_at IS NULL AND ${AFTER_SQL}` : `entity_id = ? AND forgotten_at IS NULL`;
|
|
5469
5502
|
const row = await this.db.getFirstAsync(
|
|
5470
5503
|
`SELECT COUNT(*) as count FROM ${this.prefix}events WHERE ${where}`,
|
|
5471
5504
|
params
|
|
@@ -5497,13 +5530,68 @@ var EventRepository = class extends BaseRepository {
|
|
|
5497
5530
|
async sumSummaryCharsAfter(entityId, wm, tx) {
|
|
5498
5531
|
const executor = this.getExecutor(tx);
|
|
5499
5532
|
const params = wm ? [entityId, wm.at, wm.at, wm.id] : [entityId];
|
|
5500
|
-
const where = wm ? `entity_id = ? AND ${AFTER_SQL}` : `entity_id =
|
|
5533
|
+
const where = wm ? `entity_id = ? AND forgotten_at IS NULL AND ${AFTER_SQL}` : `entity_id = ? AND forgotten_at IS NULL`;
|
|
5501
5534
|
const row = await executor.getFirstAsync(
|
|
5502
5535
|
`SELECT SUM(LENGTH(summary)) as total FROM ${this.prefix}events WHERE ${where}`,
|
|
5503
5536
|
params
|
|
5504
5537
|
);
|
|
5505
5538
|
return row?.total ?? 0;
|
|
5506
5539
|
}
|
|
5540
|
+
/**
|
|
5541
|
+
* Mark one event forgotten (specs/forget-event-exclusion §2). Entity scoped
|
|
5542
|
+
* (rule 3) and idempotent: an unknown id, another entity's id or an already
|
|
5543
|
+
* forgotten row changes nothing and reports 0.
|
|
5544
|
+
*/
|
|
5545
|
+
async markForgotten(entityId, eventId, now, tx) {
|
|
5546
|
+
const r = await this.getExecutor(tx).runAsync(
|
|
5547
|
+
`UPDATE ${this.prefix}events SET forgotten_at = ? WHERE entity_id = ? AND id = ? AND forgotten_at IS NULL`,
|
|
5548
|
+
[now, entityId, eventId]
|
|
5549
|
+
);
|
|
5550
|
+
return r.changes > 0 ? 1 : 0;
|
|
5551
|
+
}
|
|
5552
|
+
/** 1 when the event exists for the entity and is not yet forgotten, else 0 (the forget dry run). */
|
|
5553
|
+
async countForgettable(entityId, eventId) {
|
|
5554
|
+
const row = await this.db.getFirstAsync(
|
|
5555
|
+
`SELECT COUNT(*) AS n FROM ${this.prefix}events WHERE entity_id = ? AND id = ? AND forgotten_at IS NULL`,
|
|
5556
|
+
[entityId, eventId]
|
|
5557
|
+
);
|
|
5558
|
+
return Number(row?.n ?? 0) > 0 ? 1 : 0;
|
|
5559
|
+
}
|
|
5560
|
+
/** True when `deleteForgotten` with the same arguments would delete at least one row. */
|
|
5561
|
+
async hasDeletableForgotten(entityId, cutoff, tx, opts) {
|
|
5562
|
+
const row = opts?.noCutoff ? await tx.getFirstAsync(`SELECT 1 AS x FROM ${this.prefix}events WHERE entity_id = ? AND forgotten_at IS NOT NULL LIMIT 1`, [entityId]) : await tx.getFirstAsync(`SELECT 1 AS x FROM ${this.prefix}events WHERE entity_id = ? AND forgotten_at IS NOT NULL AND forgotten_at <= ? LIMIT 1`, [entityId, cutoff]);
|
|
5563
|
+
return !!row;
|
|
5564
|
+
}
|
|
5565
|
+
/**
|
|
5566
|
+
* How many of the entity's first `n` events, in `(created_at, id)` order,
|
|
5567
|
+
* `deleteForgotten` with the same arguments would delete. The memory and
|
|
5568
|
+
* heal checkpoints count rows in that order, so this is exactly how far a
|
|
5569
|
+
* checkpoint must drop (specs/forget-event-exclusion §5). Call before the delete.
|
|
5570
|
+
*/
|
|
5571
|
+
async countForgottenInPrefix(entityId, n, cutoff, tx, opts) {
|
|
5572
|
+
if (n <= 0) return 0;
|
|
5573
|
+
const pred = opts?.noCutoff ? "forgotten_at IS NOT NULL" : "forgotten_at IS NOT NULL AND forgotten_at <= ?";
|
|
5574
|
+
const row = await tx.getFirstAsync(
|
|
5575
|
+
`SELECT COUNT(*) AS n FROM (SELECT forgotten_at FROM ${this.prefix}events WHERE entity_id = ? ORDER BY created_at ASC, id ASC LIMIT ?) WHERE ${pred}`,
|
|
5576
|
+
opts?.noCutoff ? [entityId, Math.trunc(n)] : [entityId, Math.trunc(n), cutoff]
|
|
5577
|
+
);
|
|
5578
|
+
return Number(row?.n ?? 0);
|
|
5579
|
+
}
|
|
5580
|
+
/**
|
|
5581
|
+
* Hard-delete the entity's forgotten events (specs/forget-event-exclusion
|
|
5582
|
+
* §5). No watermark guard and no `retainEventsFor`: a forgotten row is never
|
|
5583
|
+
* read. `noCutoff` drops the age predicate (erase) so a non-numeric or
|
|
5584
|
+
* future `forgotten_at` cannot escape.
|
|
5585
|
+
*/
|
|
5586
|
+
async deleteForgotten(entityId, cutoff, tx, opts) {
|
|
5587
|
+
if (opts?.noCutoff) {
|
|
5588
|
+
return tx.runAsync(`DELETE FROM ${this.prefix}events WHERE entity_id = ? AND forgotten_at IS NOT NULL`, [entityId]);
|
|
5589
|
+
}
|
|
5590
|
+
return tx.runAsync(
|
|
5591
|
+
`DELETE FROM ${this.prefix}events WHERE entity_id = ? AND forgotten_at IS NOT NULL AND forgotten_at <= ?`,
|
|
5592
|
+
[entityId, cutoff]
|
|
5593
|
+
);
|
|
5594
|
+
}
|
|
5507
5595
|
};
|
|
5508
5596
|
|
|
5509
5597
|
// src/repositories/EdgeRepository.ts
|
|
@@ -5832,6 +5920,15 @@ var MetadataRepository = class extends BaseRepository {
|
|
|
5832
5920
|
await this.db.execAsync(`VACUUM`);
|
|
5833
5921
|
await this.checkpointTruncateVerified();
|
|
5834
5922
|
}
|
|
5923
|
+
/**
|
|
5924
|
+
* True when `table` has `column`. A never-set-up or not-yet-migrated store
|
|
5925
|
+
* (the #316 recovery path) lacks columns later migrations add; callers that
|
|
5926
|
+
* must run there probe first.
|
|
5927
|
+
*/
|
|
5928
|
+
async columnExists(table, column, tx) {
|
|
5929
|
+
const cols = await this.getExecutor(tx).getAllAsync(`PRAGMA table_info(${table})`);
|
|
5930
|
+
return cols.some((c) => c.name === column);
|
|
5931
|
+
}
|
|
5835
5932
|
/**
|
|
5836
5933
|
* Returns the set of distinct `entity_id` values across entries/tasks/events.
|
|
5837
5934
|
*
|
|
@@ -5842,18 +5939,21 @@ var MetadataRepository = class extends BaseRepository {
|
|
|
5842
5939
|
* is `entity_id COLLATE BINARY` for stable, locale-independent ordering.
|
|
5843
5940
|
*
|
|
5844
5941
|
* With `opts.softDeletedAtOrBefore` the walk is narrowed to entities holding
|
|
5845
|
-
* at least one soft-deleted entry or
|
|
5942
|
+
* at least one soft-deleted entry, task or forgotten event with `deleted_at` at or before
|
|
5846
5943
|
* that cutoff (erase's hard-delete walk, forget-erasure spec §2). Without
|
|
5847
5944
|
* the option the host-facing semantics above are unchanged.
|
|
5848
5945
|
*/
|
|
5849
5946
|
async getDistinctEntityIds(tx, opts) {
|
|
5850
5947
|
const executor = this.getExecutor(tx);
|
|
5948
|
+
const eventTombstones = (opts?.softDeletedAll || opts?.softDeletedAtOrBefore !== void 0) && await this.columnExists(`${this.prefix}events`, "forgotten_at", tx);
|
|
5851
5949
|
if (opts?.softDeletedAll) {
|
|
5852
5950
|
const rows2 = await executor.getAllAsync(
|
|
5853
5951
|
`SELECT DISTINCT entity_id FROM (
|
|
5854
5952
|
SELECT entity_id FROM ${this.prefix}entries WHERE deleted_at IS NOT NULL
|
|
5855
5953
|
UNION
|
|
5856
5954
|
SELECT entity_id FROM ${this.prefix}tasks WHERE deleted_at IS NOT NULL
|
|
5955
|
+
${eventTombstones ? `UNION
|
|
5956
|
+
SELECT entity_id FROM ${this.prefix}events WHERE forgotten_at IS NOT NULL` : ""}
|
|
5857
5957
|
) ORDER BY entity_id COLLATE BINARY`
|
|
5858
5958
|
);
|
|
5859
5959
|
return rows2.map((r) => r.entity_id);
|
|
@@ -5865,8 +5965,10 @@ var MetadataRepository = class extends BaseRepository {
|
|
|
5865
5965
|
SELECT entity_id FROM ${this.prefix}entries WHERE deleted_at IS NOT NULL AND deleted_at <= ?
|
|
5866
5966
|
UNION
|
|
5867
5967
|
SELECT entity_id FROM ${this.prefix}tasks WHERE deleted_at IS NOT NULL AND deleted_at <= ?
|
|
5968
|
+
${eventTombstones ? `UNION
|
|
5969
|
+
SELECT entity_id FROM ${this.prefix}events WHERE forgotten_at IS NOT NULL AND forgotten_at <= ?` : ""}
|
|
5868
5970
|
) ORDER BY entity_id COLLATE BINARY`,
|
|
5869
|
-
[cutoff, cutoff]
|
|
5971
|
+
eventTombstones ? [cutoff, cutoff, cutoff] : [cutoff, cutoff]
|
|
5870
5972
|
);
|
|
5871
5973
|
return rows2.map((r) => r.entity_id);
|
|
5872
5974
|
}
|
|
@@ -6708,6 +6810,14 @@ var DEFAULT_MAX_TOTAL_CHARS = 5e6;
|
|
|
6708
6810
|
function limitOr(value, fallback) {
|
|
6709
6811
|
return typeof value === "number" && Number.isFinite(value) && value >= 0 ? Math.floor(value) : fallback;
|
|
6710
6812
|
}
|
|
6813
|
+
function listStoredSourcesSql(prefix) {
|
|
6814
|
+
return `SELECT d.source_ref, d.source_hash, d.char_count, d.created_at,
|
|
6815
|
+
(SELECT COUNT(*) FROM ${prefix}source_passages p
|
|
6816
|
+
WHERE p.document_id = d.id AND +p.entity_id = d.entity_id) AS passage_count
|
|
6817
|
+
FROM ${prefix}source_documents d
|
|
6818
|
+
WHERE d.entity_id = ?
|
|
6819
|
+
ORDER BY d.source_ref COLLATE BINARY`;
|
|
6820
|
+
}
|
|
6711
6821
|
var SourceStoreService = class {
|
|
6712
6822
|
constructor(db, prefix, options, jobManager) {
|
|
6713
6823
|
this.db = db;
|
|
@@ -6786,15 +6896,7 @@ var SourceStoreService = class {
|
|
|
6786
6896
|
}
|
|
6787
6897
|
/** Spec §4/§7: full store listing, including sources stored with no ingest. */
|
|
6788
6898
|
async listStoredSources(entityId) {
|
|
6789
|
-
const rows = await this.db.getAllAsync(
|
|
6790
|
-
`SELECT d.source_ref, d.source_hash, d.char_count, d.created_at,
|
|
6791
|
-
(SELECT COUNT(*) FROM ${this.prefix}source_passages p
|
|
6792
|
-
WHERE p.entity_id = d.entity_id AND p.document_id = d.id) AS passage_count
|
|
6793
|
-
FROM ${this.prefix}source_documents d
|
|
6794
|
-
WHERE d.entity_id = ?
|
|
6795
|
-
ORDER BY d.source_ref COLLATE BINARY`,
|
|
6796
|
-
[entityId]
|
|
6797
|
-
);
|
|
6899
|
+
const rows = await this.db.getAllAsync(listStoredSourcesSql(this.prefix), [entityId]);
|
|
6798
6900
|
return rows.map((r) => ({
|
|
6799
6901
|
sourceRef: r.source_ref,
|
|
6800
6902
|
sourceHash: r.source_hash,
|
|
@@ -10449,6 +10551,9 @@ var runLegacyLibrarianPass = async (deps, ctx) => {
|
|
|
10449
10551
|
const { entityId, trigger } = ctx;
|
|
10450
10552
|
const promptOverride = ctx.promptOverride;
|
|
10451
10553
|
const events = await deps.eventRepo.getRecent(entityId, 50);
|
|
10554
|
+
if (events.length === 0 && await deps.eventRepo.count(entityId) > 0) {
|
|
10555
|
+
return { processedThrough: null, factsWritten: 0 };
|
|
10556
|
+
}
|
|
10452
10557
|
const currentFactsRows = await deps.entryRepo.findRecentByEntityId(entityId, 100);
|
|
10453
10558
|
const currentFacts = currentFactsRows.map((f) => {
|
|
10454
10559
|
const { embedding: _embedding, embedding_blob: _blob, ...rest } = f;
|
|
@@ -11266,12 +11371,18 @@ async function applyOps(deps, ctx, input) {
|
|
|
11266
11371
|
return id;
|
|
11267
11372
|
};
|
|
11268
11373
|
const sourceIds = [...new Set(input.gated.map((g) => g.candidate.sourceEventId).filter((x) => x !== null))];
|
|
11269
|
-
const presentIds = sourceIds.length > 0 ? await deps.eventRepo.
|
|
11374
|
+
const presentIds = sourceIds.length > 0 ? await deps.eventRepo.findLiveIds(entityId, sourceIds, tx) : /* @__PURE__ */ new Set();
|
|
11375
|
+
const failedIds = sourceIds.filter((id) => !presentIds.has(id));
|
|
11376
|
+
const stillExist = failedIds.length > 0 ? await deps.eventRepo.findExistingIds(entityId, failedIds, tx) : /* @__PURE__ */ new Set();
|
|
11270
11377
|
const gatedLive = [];
|
|
11271
11378
|
for (const g of input.gated) {
|
|
11272
11379
|
const ev = g.candidate.sourceEventId;
|
|
11273
11380
|
if (ev !== null && !presentIds.has(ev)) {
|
|
11274
|
-
input.diagnostics.push({
|
|
11381
|
+
input.diagnostics.push({
|
|
11382
|
+
...diagBase,
|
|
11383
|
+
code: "source_event_gone",
|
|
11384
|
+
detail: { itemIndex: g.candidate.index, sourceRef: ev, reason: stillExist.has(ev) ? "forgotten" : "gone" }
|
|
11385
|
+
});
|
|
11275
11386
|
continue;
|
|
11276
11387
|
}
|
|
11277
11388
|
gatedLive.push(g);
|
|
@@ -11713,6 +11824,21 @@ var _MaintenanceService = class _MaintenanceService {
|
|
|
11713
11824
|
}
|
|
11714
11825
|
}
|
|
11715
11826
|
deletedTasks = await this.taskRepo.bulkDeletePruned(entityId, cutoff, tx, { noCutoff: softDeletedAll });
|
|
11827
|
+
const delOpts = { noCutoff: softDeletedAll };
|
|
11828
|
+
const hasForgottenCol = await this.metadataRepo.columnExists(`${this.prefix}events`, "forgotten_at", tx) && await this.eventRepo.hasDeletableForgotten(entityId, cutoff, tx, delOpts);
|
|
11829
|
+
const cpBefore = hasForgottenCol ? await this.metadataRepo.getCheckpoint(entityId, tx) : null;
|
|
11830
|
+
const memDrop = cpBefore && (cpBefore.memory ?? 0) > 0 ? await this.eventRepo.countForgottenInPrefix(entityId, cpBefore.memory, cutoff, tx, delOpts) : 0;
|
|
11831
|
+
const healDrop = cpBefore && (cpBefore.heal ?? 0) > 0 ? await this.eventRepo.countForgottenInPrefix(entityId, cpBefore.heal, cutoff, tx, delOpts) : 0;
|
|
11832
|
+
const forgottenGone = hasForgottenCol ? (await this.eventRepo.deleteForgotten(entityId, cutoff, tx, delOpts)).changes : 0;
|
|
11833
|
+
if (forgottenGone > 0) {
|
|
11834
|
+
deletedEvents += forgottenGone;
|
|
11835
|
+
const updates = {};
|
|
11836
|
+
if (memDrop > 0) updates.memory = Math.max(0, cpBefore.memory - memDrop);
|
|
11837
|
+
if (healDrop > 0) updates.heal = Math.max(0, cpBefore.heal - healDrop);
|
|
11838
|
+
if (updates.memory !== void 0 || updates.heal !== void 0) {
|
|
11839
|
+
await this.metadataRepo.updateCheckpoint(entityId, updates, tx);
|
|
11840
|
+
}
|
|
11841
|
+
}
|
|
11716
11842
|
});
|
|
11717
11843
|
if (hookLedger) {
|
|
11718
11844
|
const keptSet = new Set(kept);
|
|
@@ -11733,18 +11859,20 @@ var _MaintenanceService = class _MaintenanceService {
|
|
|
11733
11859
|
const cutoff = now - retainEventsFor * 864e5;
|
|
11734
11860
|
const guarded = resolveMaintenanceMode(this.options.config) === "deferred" || resolveLibrarianStrategy(this.options.config) === "ops";
|
|
11735
11861
|
let wm = null;
|
|
11862
|
+
let retentionDeleted = 0;
|
|
11736
11863
|
await this.db.withTransactionAsync(async (tx) => {
|
|
11737
11864
|
if (guarded) {
|
|
11738
11865
|
wm = await this.metadataRepo.getLibrarianWatermark(entityId, tx);
|
|
11739
|
-
|
|
11866
|
+
retentionDeleted = (await this.eventRepo.pruneThrough(entityId, cutoff, wm, tx)).changes;
|
|
11740
11867
|
} else {
|
|
11741
|
-
|
|
11868
|
+
retentionDeleted = (await this.eventRepo.prune(entityId, cutoff, tx)).changes;
|
|
11742
11869
|
}
|
|
11743
|
-
|
|
11870
|
+
deletedEvents += retentionDeleted;
|
|
11871
|
+
if (retentionDeleted > 0) {
|
|
11744
11872
|
const cp = await this.metadataRepo.getCheckpoint(entityId, tx);
|
|
11745
11873
|
const updates = {};
|
|
11746
|
-
if ((cp.memory ?? 0) > 0) updates.memory = Math.max(0, cp.memory -
|
|
11747
|
-
if ((cp.heal ?? 0) > 0) updates.heal = Math.max(0, cp.heal -
|
|
11874
|
+
if ((cp.memory ?? 0) > 0) updates.memory = Math.max(0, cp.memory - retentionDeleted);
|
|
11875
|
+
if ((cp.heal ?? 0) > 0) updates.heal = Math.max(0, cp.heal - retentionDeleted);
|
|
11748
11876
|
if (updates.memory !== void 0 || updates.heal !== void 0) {
|
|
11749
11877
|
await this.metadataRepo.updateCheckpoint(entityId, updates, tx);
|
|
11750
11878
|
}
|
|
@@ -11952,9 +12080,11 @@ var _MaintenanceService = class _MaintenanceService {
|
|
|
11952
12080
|
if (report.skipped.length === 0 && report.holds.length === 0) {
|
|
11953
12081
|
let remainingTombstones;
|
|
11954
12082
|
try {
|
|
12083
|
+
const eventsTracked = await this.metadataRepo.columnExists(`${this.prefix}events`, "forgotten_at");
|
|
11955
12084
|
const row = await this.db.getFirstAsync(
|
|
11956
12085
|
`SELECT (SELECT COUNT(*) FROM ${this.prefix}entries WHERE deleted_at IS NOT NULL)
|
|
11957
|
-
+ (SELECT COUNT(*) FROM ${this.prefix}tasks WHERE deleted_at IS NOT NULL)
|
|
12086
|
+
+ (SELECT COUNT(*) FROM ${this.prefix}tasks WHERE deleted_at IS NOT NULL)
|
|
12087
|
+
${eventsTracked ? `+ (SELECT COUNT(*) FROM ${this.prefix}events WHERE forgotten_at IS NOT NULL)` : ""} AS n`
|
|
11958
12088
|
);
|
|
11959
12089
|
remainingTombstones = row?.n ?? 0;
|
|
11960
12090
|
} catch (err) {
|
|
@@ -12367,6 +12497,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12367
12497
|
let deletedEntries = 0;
|
|
12368
12498
|
let deletedTasks = 0;
|
|
12369
12499
|
let deletedEvents = 0;
|
|
12500
|
+
let eventMarked = 0;
|
|
12370
12501
|
let chainIds = [];
|
|
12371
12502
|
let chainTruncated = false;
|
|
12372
12503
|
const deletedEntryIds = [];
|
|
@@ -12447,6 +12578,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12447
12578
|
if (taskResult) deletedTasks++;
|
|
12448
12579
|
deletedEntries += refResult;
|
|
12449
12580
|
deletedEntries += pointerResult;
|
|
12581
|
+
if (params.eventId !== void 0) {
|
|
12582
|
+
eventMarked = await this.metadataRepo.columnExists(`${this.prefix}events`, "forgotten_at", tx) ? await this.eventRepo.markForgotten(entityId, params.eventId, now, tx) : 0;
|
|
12583
|
+
}
|
|
12450
12584
|
}
|
|
12451
12585
|
if (ledgerOn && this.vectorRemoval?.gate() === "hook" && deletedEntryIds.length > 0) {
|
|
12452
12586
|
await this.vectorRemovalRepo?.backstopEnqueue(entityId, Array.from(new Set(deletedEntryIds)), now, tx);
|
|
@@ -12499,7 +12633,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12499
12633
|
}
|
|
12500
12634
|
}
|
|
12501
12635
|
if (!params.clearAll) {
|
|
12502
|
-
const base = {
|
|
12636
|
+
const base = {
|
|
12637
|
+
deleted: params.eventId !== void 0 ? { entries: deletedEntries, tasks: deletedTasks, events: eventMarked } : { entries: deletedEntries, tasks: deletedTasks }
|
|
12638
|
+
};
|
|
12503
12639
|
if (params.includeChain) {
|
|
12504
12640
|
base.chainEntryIds = chainIds;
|
|
12505
12641
|
if (chainTruncated) {
|
|
@@ -12605,7 +12741,8 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12605
12741
|
}
|
|
12606
12742
|
if (params.eventId !== void 0) {
|
|
12607
12743
|
const entries2 = await this.entryRepo.countLiveByPointerEvent(entityId, params.eventId);
|
|
12608
|
-
|
|
12744
|
+
const events = await this.metadataRepo.columnExists(`${this.prefix}events`, "forgotten_at") ? await this.eventRepo.countForgettable(entityId, params.eventId) : 0;
|
|
12745
|
+
return { deleted: { entries: entries2, tasks: 0, events } };
|
|
12609
12746
|
}
|
|
12610
12747
|
const sourceRef = params.sourceRef !== void 0 ? normalizeSourceRef(params.sourceRef) : null;
|
|
12611
12748
|
if (params.sourceRef !== void 0 && !sourceRef) throw new Error("Invalid sourceRef");
|
|
@@ -14290,7 +14427,7 @@ var ImportExportService = class {
|
|
|
14290
14427
|
const [factsRaw, tasks, events, edges, summaryValue] = await Promise.all([
|
|
14291
14428
|
opts?.includeBlobs ? this.entryRepo.findAllByEntityIdWithBlobs(entityId, void 0, incl) : this.entryRepo.findAllByEntityId(entityId, void 0, incl),
|
|
14292
14429
|
this.taskRepo.findAllByEntityId(entityId, void 0, incl),
|
|
14293
|
-
this.eventRepo.getByEntityId(entityId, opts?.maxEvents),
|
|
14430
|
+
this.eventRepo.getByEntityId(entityId, opts?.maxEvents, incl),
|
|
14294
14431
|
this.edgeRepo.getByEntityId(entityId),
|
|
14295
14432
|
this.metadataRepo.getMeta(entitySummaryMetaKey(entityId))
|
|
14296
14433
|
]);
|
|
@@ -14621,10 +14758,14 @@ var ImportExportService = class {
|
|
|
14621
14758
|
summary: event.summary,
|
|
14622
14759
|
related_entry_id: event.related_entry_id ?? null,
|
|
14623
14760
|
created_at: stamp.createdAt,
|
|
14624
|
-
occurred_at: stamp.occurredAt
|
|
14761
|
+
occurred_at: stamp.occurredAt,
|
|
14762
|
+
forgotten_at: event.forgotten_at ?? null
|
|
14625
14763
|
},
|
|
14626
14764
|
tx
|
|
14627
14765
|
);
|
|
14766
|
+
if (!inserted && event.forgotten_at != null) {
|
|
14767
|
+
await this.eventRepo.markForgotten(entityId, event.id, event.forgotten_at, tx);
|
|
14768
|
+
}
|
|
14628
14769
|
if (!inserted || stamp.reason === null) continue;
|
|
14629
14770
|
if (stamp.reason === "future") clampedEvents++;
|
|
14630
14771
|
else restamped[stamp.reason]++;
|
|
@@ -17246,6 +17387,7 @@ var WikiMemory = class {
|
|
|
17246
17387
|
await this.db.withTransactionAsync(async (tx) => {
|
|
17247
17388
|
await createLegacySourceTypeIndex(tx, this.prefix);
|
|
17248
17389
|
await createEntriesDeletedIndex(tx, this.prefix);
|
|
17390
|
+
await createEventsForgottenIndex(tx, this.prefix);
|
|
17249
17391
|
await writeNormalizeStamp(this.metadataRepo, tx);
|
|
17250
17392
|
await this.metadataRepo.setMeta("schema_version", String(CURRENT_SCHEMA_VERSION), tx);
|
|
17251
17393
|
});
|
|
@@ -18631,7 +18773,7 @@ function conceptRelativePath(sourceFilePath, targetFilePath) {
|
|
|
18631
18773
|
return targetFilePath.replace(/^entities\/[^/]+\//, "");
|
|
18632
18774
|
}
|
|
18633
18775
|
function buildEventLogEntries(events, factIdToFilename) {
|
|
18634
|
-
return events.map((e) => {
|
|
18776
|
+
return events.filter((e) => e.forgotten_at == null).map((e) => {
|
|
18635
18777
|
const factFilename = e.related_entry_id ? factIdToFilename.get(e.related_entry_id) : void 0;
|
|
18636
18778
|
const summary = e.summary.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]").replace(/\r?\n/g, " ");
|
|
18637
18779
|
const text = factFilename ? `(${e.event_type}) [${summary}](./facts/${factFilename}.md)` : `(${e.event_type}) ${summary}`;
|