@mnemo-ai/types 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,997 @@
1
+ import { MnemoFact, MnemoDecision, MnemoEpisode, MnemoEntity, MnemoStrategy, MnemoWorkflow, MnemoSkill, MnemoTask, MnemoEvent, MnemoReasoning, MnemoHyperedge, MnemoCompositionRule, MnemoInferenceLogEntry, MnemoFactHash, LshBandValue, MnemoRelation, HealthSnapshot, MnemoCitation, MnemoAgentProfile, OutboxEntry, AuditLogEntry, RecallLogEntry, ReplayFailureReview, ActiveLearningReviewRow, MnemoWebhookEndpoint, MnemoWebhookDelivery, MnemoReminder, ManagedSessionProvenance, HarnessEventAck, ManagedCollapseCommitResult, ManagedPostCommitEffectKind, RecallRequestObservation, RecallHitObservation, StorageAdapter, HarnessIngestionPort, ManagedSessionLifecyclePort, StorageCapabilities, HarnessEvent, ManagedCollapsePort, CreateSessionInput, CreateFactInput, UpdateFactInput, MergeFactByTopicKeyInput, ReplaceFactInput, ReplaceFactResult, FindLiveFactByStatementInput, FactFilter, FactPageFilter, FactPage, WorkspaceVitals, AuditFeedFilter, AuditFeedEntry, GetHealthSnapshotInput, HealthSnapshotDay, AuditFeedStats, ApplyConsolidationMergeInput, ConsolidationMergeSnapshot, FindContradictingFactsInput, ContradictingFact, PurgeFactsFilter, PurgeFactsResult, CreateDecisionInput, MergeDecisionByTopicKeyInput, UpdateDecisionInput, SupersedeDecisionInput, DecisionFilter, CreateEpisodeInput, UpdateEpisodeInput, EpisodeFilter, RememberKind, SimilarEpisode, CreateEntityInput, UpdateEntityInput, SupersedeEntityInput, EntityFilter, SimilarEntity, CreateStrategyInput, UpdateStrategyInput, StrategyFilter, CreateWorkflowInput, UpdateWorkflowInput, WorkflowFilter, CreateSkillInput, UpdateSkillInput, SkillFilter, CreateTaskInput, UpdateTaskInput, TaskFilter, CreateEventInput, EventFilter, CreateReasoningInput, UpdateReasoningInput, ReasoningFilter, CreateHyperedgeInput, UpdateHyperedgeInput, HyperedgeFilter, CreateCompositionRuleInput, UpdateCompositionRuleInput, CompositionRuleFilter, AppendInferenceInput, MaterialiseInferenceInput, InferenceLogFilter, UpsertFactHashInput, UpsertFactLshInput, RecallPrimitiveRef, RecallPrimitiveRecord, RecallStructures, PointerCandidateQuery, PointerCandidate, FtsCandidate, PrimitiveCandidateQuery, PrimitiveCandidate, ConfidenceMapRow, KnowledgeGapRow, MetacognitionTrends, SequentialPatternRow, PeriodicPatternRow, ConditionalPatternRow, CoOccurrencePatternRow, CreateRelationInput, RelationFilter, CitationFilter, GraphSnapshotFilter, GraphSnapshot, ApplyRelationJudgmentInput, ResolveConflictInput, ResolveConflictResult, PrimitiveKind, RecallPrecisionReport, RecallMetrics, SessionStats, FactStats, ActiveLearningReviewFilter, EnqueueActiveLearningReviewInput, EnqueueActiveLearningReviewResult, ResolveActiveLearningReviewInput, ResolveActiveLearningReviewResult, AuditActivity, CreateWebhookEndpointInput, UpdateWebhookEndpointInput, CreateWebhookDeliveryInput, CreateReminderInput, RecallLogRecord, LookupQueryCacheInput, InsertQueryCacheInput, EmbeddableTable, HotTierSnapshotRow, AccessPolicyStore, AccessPolicyRecord, ApprovalStore, ApprovalRequestInput, ApprovalRequest, BreakGlassStore, BreakGlassRequestInput, BreakGlassRequestRecord } from '../index.cjs';
2
+ import { MnemoSession, SessionTurn, Sensitivity, ActorType, ManagedSessionClaim, ManagedCollapseRetry, ManagedArchiveReason, ManagedLifecycleQuiesceResult, PaginatedResult, WorthDelta, HealthStatus } from '../index.cjs';
3
+ import 'zod';
4
+
5
+ interface InMemoryHarnessSession {
6
+ id: string;
7
+ logicalSource: string;
8
+ workspaceId: string;
9
+ host: string;
10
+ clientInstanceId: string;
11
+ hostSessionId: string;
12
+ generation: number;
13
+ predecessorSessionId: string | null;
14
+ status: "active" | "collapse_pending" | "collapsed" | "archived";
15
+ closeKind: "authoritative" | "provisional" | null;
16
+ terminalDigestVersion: number | null;
17
+ terminalMaxEnqueueSequence: number | null;
18
+ terminalMessageSetDigest: string | null;
19
+ closeGraceDeadline: Date | null;
20
+ closeRequestedAt: Date | null;
21
+ sensitivity: "public" | "internal";
22
+ provenance: ManagedSessionProvenance;
23
+ startSequence: number;
24
+ turnCount: number;
25
+ tokenCount: number;
26
+ lastActivityAt: Date;
27
+ captureIncomplete: boolean;
28
+ captureIncompleteReasons: string[];
29
+ leased: boolean;
30
+ leaseOwner: string | null;
31
+ leaseExpiresAt: Date | null;
32
+ collapseAttempts: number;
33
+ collapseNextAttemptAt: Date | null;
34
+ collapseOperationId: string | null;
35
+ archiveReason: string | null;
36
+ archivedAt: Date | null;
37
+ collapsedAt: Date | null;
38
+ }
39
+ interface InMemoryHarnessTurn {
40
+ turnOrigin?: SessionTurn["turnOrigin"];
41
+ turnOriginEvidence?: string;
42
+ sessionId: string;
43
+ workspaceId: string;
44
+ turnIndex: number;
45
+ sourceMessageId: string;
46
+ supersedesSourceMessageId: string | null;
47
+ role: "user" | "assistant";
48
+ content: string;
49
+ contentHash: string;
50
+ retracted: boolean;
51
+ retractedAt: Date | null;
52
+ retractionReason: string | null;
53
+ pinned: boolean;
54
+ tokenCount: number;
55
+ ingestionEventId: string;
56
+ createdAt: Date;
57
+ }
58
+ interface InMemoryHarnessLedger {
59
+ id: string;
60
+ workspaceId: string;
61
+ eventId: string;
62
+ logicalSource: string;
63
+ enqueueSequence: number;
64
+ payloadHash: string;
65
+ provenance: ManagedSessionProvenance;
66
+ state: "retryable" | "accepted" | "rejected" | "cancelled";
67
+ acknowledgement: HarnessEventAck;
68
+ }
69
+ interface InMemoryStorageState {
70
+ sessions: Map<string, MnemoSession>;
71
+ turns: SessionTurn[];
72
+ facts: Map<string, MnemoFact>;
73
+ decisions: Map<string, MnemoDecision>;
74
+ episodes: Map<string, MnemoEpisode>;
75
+ entities: Map<string, MnemoEntity>;
76
+ strategies: Map<string, MnemoStrategy>;
77
+ workflows: Map<string, MnemoWorkflow>;
78
+ skills: Map<string, MnemoSkill>;
79
+ tasks: Map<string, MnemoTask>;
80
+ events: Map<string, MnemoEvent>;
81
+ reasonings: Map<string, MnemoReasoning>;
82
+ hyperedges: Map<string, MnemoHyperedge>;
83
+ compositionRules: Map<string, MnemoCompositionRule>;
84
+ inferences: MnemoInferenceLogEntry[];
85
+ factHashes: Map<string, MnemoFactHash>;
86
+ factLsh: Map<string, LshBandValue[]>;
87
+ embeddings: Map<string, number[]>;
88
+ relations: Map<string, MnemoRelation>;
89
+ healthSnapshots: Map<string, HealthSnapshot[]>;
90
+ citations: MnemoCitation[];
91
+ semanticNeighbors: Map<string, {
92
+ workspaceId: string;
93
+ sourceFactId: string;
94
+ targetFactId: string;
95
+ cosine: number;
96
+ }>;
97
+ agentProfiles: Map<string, MnemoAgentProfile>;
98
+ workspaceModes: Map<string, {
99
+ mode: "learning" | "production";
100
+ sessionCount: number;
101
+ promoteAt: number | null;
102
+ startedAt: Date;
103
+ factCount: number;
104
+ entityCount: number;
105
+ }>;
106
+ queryCache: Array<{
107
+ workspaceId: string;
108
+ embedding: Float32Array;
109
+ resultIds: string[];
110
+ resultKinds: string[];
111
+ topK: number;
112
+ createdAt: number;
113
+ }>;
114
+ embeddingCache: Map<string, {
115
+ embedding: Float32Array;
116
+ model: string;
117
+ }>;
118
+ outbox: OutboxEntry[];
119
+ auditLog: AuditLogEntry[];
120
+ /**
121
+ * P111 — `mnemo_review_item` rows. This used to be a no-op in the in-memory
122
+ * adapter, so nothing a unit test could see recorded a review: the §33
123
+ * contradiction path, the §34.7 abuse flag, self-reflect's knowledge gaps and
124
+ * the Wave X anomaly flag all wrote into a discard. The test double had the
125
+ * same one-half-of-a-mechanism shape as the production code it stands in for.
126
+ */
127
+ reviewItems: Array<{
128
+ workspaceId: string;
129
+ primitiveId: string;
130
+ primitiveKind?: string;
131
+ reason: string;
132
+ detail?: Record<string, unknown>;
133
+ createdAt: Date;
134
+ }>;
135
+ recallLog: Array<RecallLogEntry & {
136
+ recalledAt?: Date;
137
+ }>;
138
+ consolidationReviews: Array<{
139
+ id: string;
140
+ workspaceId: string;
141
+ factId: string;
142
+ reason: string;
143
+ review: ReplayFailureReview;
144
+ }>;
145
+ activeLearningReviewQueue: ActiveLearningReviewRow[];
146
+ webhookEndpoints: MnemoWebhookEndpoint[];
147
+ webhookDeliveries: MnemoWebhookDelivery[];
148
+ reminders: MnemoReminder[];
149
+ mnemoRecallLog: Array<{
150
+ id: string;
151
+ workspaceId: string;
152
+ memoryId: string;
153
+ recalledAt: string;
154
+ recallScore: number;
155
+ }>;
156
+ harnessSessions: Map<string, InMemoryHarnessSession>;
157
+ harnessTurns: InMemoryHarnessTurn[];
158
+ harnessLedger: Map<string, InMemoryHarnessLedger>;
159
+ harnessSequenceLedger: Map<string, string>;
160
+ harnessLosses: Array<{
161
+ sessionId: string;
162
+ workspaceId: string;
163
+ sourceMessageId: string;
164
+ role: string;
165
+ contentHash: string;
166
+ eventId: string;
167
+ }>;
168
+ harnessRetractions: Array<{
169
+ sessionId: string;
170
+ workspaceId: string;
171
+ sourceMessageId: string;
172
+ predecessorSessionId: string | null;
173
+ eventId: string;
174
+ }>;
175
+ harnessMessageChunks: Array<{
176
+ workspaceId: string;
177
+ sessionId: string;
178
+ ingestionEventId: string;
179
+ logicalSource: string;
180
+ sourceGeneration: number;
181
+ sourceMessageId: string;
182
+ supersedesSourceMessageId?: string;
183
+ role: "user" | "assistant";
184
+ chunkIndex: number;
185
+ chunkCount: number;
186
+ chunkContentHash: string;
187
+ messageContentHash: string;
188
+ content: string;
189
+ }>;
190
+ harnessControls: Map<string, boolean>;
191
+ managedOperations: Map<string, {
192
+ workspaceId: string;
193
+ sessionId: string;
194
+ generation: number;
195
+ result: ManagedCollapseCommitResult;
196
+ }>;
197
+ managedProvenance: Array<{
198
+ workspaceId: string;
199
+ sessionId: string;
200
+ operationId: string;
201
+ primitiveKind: string;
202
+ primitiveId: string;
203
+ sourceMessageIds: string[];
204
+ sensitivity: Sensitivity;
205
+ [key: string]: unknown;
206
+ }>;
207
+ managedCollapseEffects: Array<{
208
+ workspaceId: string;
209
+ operationId: string;
210
+ effectKind: "lifecycle_event" | "metrics" | "redis_cleanup" | ManagedPostCommitEffectKind;
211
+ targetKind?: string;
212
+ targetId?: string;
213
+ payload?: Record<string, unknown>;
214
+ sessionId: string;
215
+ status: "pending" | "completed";
216
+ attempts: number;
217
+ nextAttemptAt: Date | null;
218
+ completedAt: Date | null;
219
+ lastError: string | null;
220
+ }>;
221
+ }
222
+
223
+ /** Per-adapter-instance observation store; never module-level, so tests cannot leak. */
224
+ interface RecallObservationStore {
225
+ requests: Map<string, RecallRequestObservation>;
226
+ hits: RecallHitObservation[];
227
+ }
228
+
229
+ declare class InMemoryStorageAdapter implements StorageAdapter, HarnessIngestionPort, ManagedSessionLifecyclePort {
230
+ readonly capabilities: StorageCapabilities;
231
+ private state;
232
+ ingestHarnessEvent(input: {
233
+ workspaceId: string;
234
+ provenance: ManagedSessionProvenance;
235
+ event: HarnessEvent;
236
+ receivedAt: Date;
237
+ }): Promise<HarnessEventAck>;
238
+ commitManagedCollapse(input: Parameters<ManagedCollapsePort["commitManagedCollapse"]>[0]): Promise<ManagedCollapseCommitResult>;
239
+ inspectHarnessState(workspaceId: string): Promise<{
240
+ sessions: {
241
+ id: string;
242
+ clientInstanceId: string;
243
+ generation: number;
244
+ status: "collapsed" | "archived" | "active" | "collapse_pending";
245
+ closeKind: "authoritative" | "provisional" | null;
246
+ turnCount: number;
247
+ tokenCount: number;
248
+ lastActivityAt: Date;
249
+ closeGraceDeadline: Date | null;
250
+ sensitivity: "public" | "internal";
251
+ captureIncomplete: boolean;
252
+ predecessorSessionId: string | null;
253
+ terminalMessageSetDigest: string | null;
254
+ terminalDigestVersion: number | null;
255
+ terminalMaxEnqueueSequence: number | null;
256
+ leased: boolean;
257
+ }[];
258
+ turns: {
259
+ turnOrigin?: SessionTurn["turnOrigin"];
260
+ turnOriginEvidence?: string;
261
+ sessionId: string;
262
+ workspaceId: string;
263
+ turnIndex: number;
264
+ sourceMessageId: string;
265
+ supersedesSourceMessageId: string | null;
266
+ role: "user" | "assistant";
267
+ content: string;
268
+ contentHash: string;
269
+ retracted: boolean;
270
+ retractedAt: Date | null;
271
+ retractionReason: string | null;
272
+ pinned: boolean;
273
+ tokenCount: number;
274
+ ingestionEventId: string;
275
+ createdAt: Date;
276
+ }[];
277
+ ledger: {
278
+ eventId: string;
279
+ state: "retryable" | "accepted" | "rejected" | "cancelled";
280
+ payloadHash: string;
281
+ actorId: `user:${string}` | `key:${string}` | `system:${string}` | `peer:${string}`;
282
+ actorType: ActorType;
283
+ userId: string | null;
284
+ sensitivityCeiling: Sensitivity;
285
+ acknowledgement: HarnessEventAck;
286
+ }[];
287
+ losses: {
288
+ sessionId: string;
289
+ workspaceId: string;
290
+ sourceMessageId: string;
291
+ role: string;
292
+ contentHash: string;
293
+ eventId: string;
294
+ }[];
295
+ retractions: {
296
+ sessionId: string;
297
+ workspaceId: string;
298
+ sourceMessageId: string;
299
+ predecessorSessionId: string | null;
300
+ eventId: string;
301
+ }[];
302
+ }>;
303
+ setHarnessSessionLifecycle(workspaceId: string, input: {
304
+ generation: number;
305
+ status: "active" | "collapse_pending" | "collapsed" | "archived";
306
+ leased?: boolean;
307
+ closeKind?: "authoritative" | "provisional" | null;
308
+ closeGraceDeadline?: Date | null;
309
+ terminalMaxEnqueueSequence?: number | null;
310
+ terminalMessageSetDigest?: string | null;
311
+ }): Promise<void>;
312
+ seedHarnessManagedTurn(workspaceId: string, input: {
313
+ generation: number;
314
+ sourceMessageId: string;
315
+ role: "user" | "assistant";
316
+ content: string;
317
+ contentHash: string;
318
+ }): Promise<void>;
319
+ get outbox(): OutboxEntry[];
320
+ get auditLog(): AuditLogEntry[];
321
+ get recallLog(): RecallLogEntry[];
322
+ /** P111 — mnemo_review_item rows; see the state field's note. */
323
+ get reviewItems(): InMemoryStorageState["reviewItems"];
324
+ get consolidationReviews(): {
325
+ id: string;
326
+ workspaceId: string;
327
+ factId: string;
328
+ reason: string;
329
+ review: ReplayFailureReview;
330
+ }[];
331
+ get activeLearningReviewQueue(): ActiveLearningReviewRow[];
332
+ /** @internal — legacy reach-in seam; sole consumer consolidation-merge.test.ts:429/449/467. */
333
+ private get facts();
334
+ /** @internal — legacy reach-in seam; sole consumer entities-link-user.test.ts:65 (found during B14, not by design.md's original D5 inventory). */
335
+ private get entities();
336
+ createSession(input: CreateSessionInput): Promise<MnemoSession>;
337
+ appendTurn(sessionId: string, turn: Omit<SessionTurn, "id" | "createdAt">): Promise<number>;
338
+ listTurns(sessionId: string, workspaceId: string): Promise<SessionTurn[]>;
339
+ listManagedCollapseTurns(sessionId: string, workspaceId: string): Promise<SessionTurn[]>;
340
+ claimManagedSessions(input: {
341
+ workspaceId: string;
342
+ leaseOwner: string;
343
+ limit: number;
344
+ inactivityMs: number;
345
+ provisionalGraceMs: number;
346
+ leaseMs: number;
347
+ }): Promise<ManagedSessionClaim[]>;
348
+ markManagedCollapseRetry(input: {
349
+ workspaceId: string;
350
+ sessionId: string;
351
+ leaseOwner: string;
352
+ error: string;
353
+ baseRetryMs: number;
354
+ maxRetryMs: number;
355
+ }): Promise<ManagedCollapseRetry | null>;
356
+ finalizeManagedArchive(input: {
357
+ workspaceId: string;
358
+ sessionId: string;
359
+ leaseOwner: string;
360
+ operationId: string;
361
+ reason: ManagedArchiveReason;
362
+ }): Promise<boolean>;
363
+ releaseExpiredManagedLeases(input: {
364
+ workspaceId: string;
365
+ }): Promise<number>;
366
+ retryLegacyManagedArchive(input: {
367
+ workspaceId: string;
368
+ sessionId: string;
369
+ }): Promise<boolean>;
370
+ quiesceManagedLifecycle(input: {
371
+ workspaceId: string;
372
+ }): Promise<ManagedLifecycleQuiesceResult>;
373
+ purgeManagedTurns(input: {
374
+ workspaceId: string;
375
+ terminalBefore: Date;
376
+ limit: number;
377
+ }): Promise<number>;
378
+ closeSession(id: string, workspaceId: string): Promise<void>;
379
+ /**
380
+ * LIFECYCLE-7/8 parity with the Postgres adapter: `apply` writes into a
381
+ * snapshot that replaces the live state only when it returns, so a throw
382
+ * leaves nothing behind; commits are serialised like the row lock.
383
+ */
384
+ commitSessionCollapse<T>(input: {
385
+ workspaceId: string;
386
+ sessionId: string;
387
+ expectedTurnCount?: number;
388
+ terminalStatus?: "collapsed" | "archived";
389
+ archiveReason?: string;
390
+ topicLocks?: {
391
+ facts: string[];
392
+ decisions: string[];
393
+ };
394
+ }, apply: (storage: StorageAdapter) => Promise<T>): Promise<{
395
+ committed: true;
396
+ value: T;
397
+ } | {
398
+ committed: false;
399
+ status: string | null;
400
+ }>;
401
+ archiveSession(id: string, workspaceId: string, reason?: string): Promise<void>;
402
+ getSession(id: string, workspaceId: string): Promise<MnemoSession | null>;
403
+ listSessions(workspaceId: string): Promise<MnemoSession[]>;
404
+ recordSessionOutcome(sessionId: string, workspaceId: string, rating: "success" | "failure" | "neutral"): Promise<boolean>;
405
+ recordSessionRecall(sessionId: string, workspaceId: string): Promise<void>;
406
+ pinSessionTurn(input: {
407
+ sessionId: string;
408
+ workspaceId: string;
409
+ turnId?: string;
410
+ turnIndex?: number;
411
+ pinned: boolean;
412
+ }): Promise<boolean>;
413
+ replaceSessionScratch(input: {
414
+ workspaceId: string;
415
+ sessionId: string;
416
+ scratch: Record<string, unknown>;
417
+ }): Promise<boolean>;
418
+ getSessionScratch(input: {
419
+ workspaceId: string;
420
+ sessionId: string;
421
+ }): Promise<Record<string, unknown> | null>;
422
+ createFact(input: CreateFactInput): Promise<MnemoFact>;
423
+ findFactByImportedId(workspaceId: string, importedId: string): Promise<MnemoFact | null>;
424
+ getFact(id: string, workspaceId: string): Promise<MnemoFact | null>;
425
+ updateFact(id: string, workspaceId: string, input: UpdateFactInput): Promise<MnemoFact | null>;
426
+ mergeFactByTopicKey(input: MergeFactByTopicKeyInput): Promise<MnemoFact | null>;
427
+ replaceFact(input: ReplaceFactInput): Promise<ReplaceFactResult | null>;
428
+ archiveFact(id: string, workspaceId: string): Promise<boolean>;
429
+ findLiveFactByStatement(input: FindLiveFactByStatementInput): Promise<MnemoFact | null>;
430
+ linkSessionFactsToEpisode(workspaceId: string, sessionId: string, episodeId: string): Promise<number>;
431
+ queryFacts(filter: FactFilter): Promise<PaginatedResult<MnemoFact>>;
432
+ queryFactsPage(filter: FactPageFilter): Promise<FactPage>;
433
+ purgeForgottenFacts(workspaceId: string, actorId?: string): Promise<number>;
434
+ getWorkspaceVitals(workspaceId: string): Promise<WorkspaceVitals>;
435
+ getAuditFeed(filter: AuditFeedFilter): Promise<AuditFeedEntry[]>;
436
+ getHealthSnapshot(input: GetHealthSnapshotInput): Promise<HealthSnapshot | null>;
437
+ getHealthSnapshots(input: {
438
+ workspaceId: string;
439
+ days: number;
440
+ }): Promise<HealthSnapshotDay[]>;
441
+ getAuditFeedStats(input: {
442
+ workspaceId: string;
443
+ days: number;
444
+ maxSensitivity?: Sensitivity;
445
+ }): Promise<AuditFeedStats>;
446
+ applyConsolidationMerge(input: ApplyConsolidationMergeInput): Promise<ConsolidationMergeSnapshot | null>;
447
+ rollbackConsolidationMerge(input: {
448
+ snapshot: ConsolidationMergeSnapshot;
449
+ review: ReplayFailureReview;
450
+ }): Promise<"rolled_back" | "conflict">;
451
+ finalizeConsolidationMerge(input: {
452
+ snapshot: ConsolidationMergeSnapshot;
453
+ applyReplayBoost: boolean;
454
+ }): Promise<"finalized" | "conflict">;
455
+ refreshConsolidationMergeLease(input: {
456
+ snapshot: ConsolidationMergeSnapshot;
457
+ leaseExpiresAt: Date;
458
+ }): Promise<"refreshed" | "conflict">;
459
+ inspectConsolidationMergeState(snapshot: ConsolidationMergeSnapshot): Promise<"pending" | "restored" | "retained" | "divergent">;
460
+ recoverExpiredConsolidationMerges(input: {
461
+ workspaceId: string;
462
+ expiredBefore: Date;
463
+ }): Promise<number>;
464
+ findContradictingFacts(workspaceId: string, input: FindContradictingFactsInput): Promise<ContradictingFact[]>;
465
+ purgeFacts(filter: PurgeFactsFilter): Promise<PurgeFactsResult>;
466
+ createDecisionUnlessDuplicate(input: CreateDecisionInput): Promise<{
467
+ decision: MnemoDecision;
468
+ reused: boolean;
469
+ }>;
470
+ createDecision(input: CreateDecisionInput): Promise<MnemoDecision>;
471
+ mergeDecisionByTopicKey(input: MergeDecisionByTopicKeyInput): Promise<MnemoDecision | null>;
472
+ getDecision(id: string, workspaceId: string): Promise<MnemoDecision | null>;
473
+ updateDecision(id: string, input: UpdateDecisionInput): Promise<MnemoDecision>;
474
+ archiveDecision(id: string, workspaceId: string): Promise<void>;
475
+ supersedeDecision(input: SupersedeDecisionInput): Promise<MnemoDecision>;
476
+ queryDecisions(filter: DecisionFilter): Promise<PaginatedResult<MnemoDecision>>;
477
+ createEpisode(input: CreateEpisodeInput): Promise<MnemoEpisode>;
478
+ getEpisode(id: string, workspaceId: string): Promise<MnemoEpisode | null>;
479
+ updateEpisode(id: string, input: UpdateEpisodeInput): Promise<MnemoEpisode>;
480
+ archiveEpisode(id: string, workspaceId: string): Promise<void>;
481
+ queryEpisodes(filter: EpisodeFilter): Promise<PaginatedResult<MnemoEpisode>>;
482
+ getEpisodeTreeNeighbors(episodeId: string, workspaceId: string, limit?: number): Promise<MnemoEpisode[]>;
483
+ persistCompression(input: {
484
+ workspaceId: string;
485
+ rootEpisodeId: string;
486
+ compressedNarrative: string;
487
+ retainedDeltas: Array<{
488
+ episodeId: string;
489
+ deltaContent: string;
490
+ }>;
491
+ }): Promise<void>;
492
+ getKnowledgeDistribution(workspaceId: string): Promise<Partial<Record<RememberKind, number>>>;
493
+ reconstructEpisode(id: string, workspaceId: string): Promise<MnemoEpisode>;
494
+ findSimilarEpisodes(workspaceId: string, embedding: number[], limit: number, minSim: number): Promise<SimilarEpisode[]>;
495
+ createEntity(input: CreateEntityInput): Promise<MnemoEntity>;
496
+ getEntity(id: string, workspaceId: string): Promise<MnemoEntity | null>;
497
+ updateEntity(id: string, input: UpdateEntityInput): Promise<MnemoEntity>;
498
+ archiveEntity(id: string, workspaceId: string): Promise<void>;
499
+ supersedeEntity(input: SupersedeEntityInput): Promise<MnemoEntity>;
500
+ queryEntities(filter: EntityFilter): Promise<PaginatedResult<MnemoEntity>>;
501
+ findSimilarEntities(workspaceId: string, embedding: number[], limit: number, minSim: number): Promise<SimilarEntity[]>;
502
+ createStrategyUnlessDuplicate(input: CreateStrategyInput): Promise<{
503
+ strategy: MnemoStrategy;
504
+ reused: boolean;
505
+ }>;
506
+ createStrategy(input: CreateStrategyInput): Promise<MnemoStrategy>;
507
+ getStrategy(id: string, workspaceId: string): Promise<MnemoStrategy | null>;
508
+ updateStrategy(id: string, input: UpdateStrategyInput): Promise<MnemoStrategy>;
509
+ archiveStrategy(id: string, workspaceId: string): Promise<void>;
510
+ queryStrategies(filter: StrategyFilter): Promise<PaginatedResult<MnemoStrategy>>;
511
+ createWorkflow(input: CreateWorkflowInput): Promise<MnemoWorkflow>;
512
+ getWorkflow(id: string, workspaceId: string): Promise<MnemoWorkflow | null>;
513
+ updateWorkflow(id: string, input: UpdateWorkflowInput): Promise<MnemoWorkflow>;
514
+ archiveWorkflow(id: string, workspaceId: string): Promise<void>;
515
+ queryWorkflows(filter: WorkflowFilter): Promise<PaginatedResult<MnemoWorkflow>>;
516
+ createSkill(input: CreateSkillInput): Promise<MnemoSkill>;
517
+ getSkill(id: string, workspaceId: string): Promise<MnemoSkill | null>;
518
+ updateSkill(id: string, input: UpdateSkillInput): Promise<MnemoSkill>;
519
+ archiveSkill(id: string, workspaceId: string): Promise<void>;
520
+ querySkills(filter: SkillFilter): Promise<PaginatedResult<MnemoSkill>>;
521
+ createTask(input: CreateTaskInput): Promise<MnemoTask>;
522
+ getTask(id: string, workspaceId: string): Promise<MnemoTask | null>;
523
+ updateTask(id: string, input: UpdateTaskInput): Promise<MnemoTask>;
524
+ archiveTask(id: string, workspaceId: string): Promise<void>;
525
+ listTasksForSession(workspaceId: string, sessionId: string): Promise<Array<{
526
+ id: string;
527
+ status: string;
528
+ }>>;
529
+ listStaleTasks(workspaceId: string, staleSinceMs: number, limit: number): Promise<Array<{
530
+ id: string;
531
+ title: string;
532
+ status: string;
533
+ updatedAt: Date;
534
+ }>>;
535
+ countFactsByTypeStatus(): Promise<Array<{
536
+ type: string;
537
+ status: string;
538
+ count: number;
539
+ }>>;
540
+ worthHistogram(): Promise<Array<{
541
+ bucket: string;
542
+ count: number;
543
+ }>>;
544
+ countActiveSessions(): Promise<number>;
545
+ countTasksByStatus(): Promise<Array<{
546
+ status: string;
547
+ count: number;
548
+ }>>;
549
+ countStaleTasks(): Promise<number>;
550
+ listScoredTrajectories(workspaceId: string, agentId: string, limit: number): Promise<Array<{
551
+ sessionId: string;
552
+ score: number;
553
+ promptVersionId: string | null;
554
+ createdAt: Date;
555
+ }>>;
556
+ computeCandidateAbScore(workspaceId: string, agentId: string, promptVersionId: string): Promise<number | null>;
557
+ delegateTask(id: string, workspaceId: string, input: {
558
+ assignedTo: string;
559
+ delegatedBy: string;
560
+ }): Promise<MnemoTask>;
561
+ queryTasks(filter: TaskFilter): Promise<PaginatedResult<MnemoTask>>;
562
+ createEvent(input: CreateEventInput): Promise<MnemoEvent>;
563
+ getEvent(id: string, workspaceId: string): Promise<MnemoEvent | null>;
564
+ archiveEvent(id: string, workspaceId: string): Promise<void>;
565
+ appendEventAnnotation(id: string, workspaceId: string, annotation: {
566
+ author: string;
567
+ content: string;
568
+ at: Date;
569
+ }): Promise<MnemoEvent>;
570
+ queryEvents(filter: EventFilter): Promise<PaginatedResult<MnemoEvent>>;
571
+ updateEventSensitivity(id: string, workspaceId: string, sensitivity: MnemoEvent["sensitivity"]): Promise<void>;
572
+ createReasoning(input: CreateReasoningInput): Promise<MnemoReasoning>;
573
+ getReasoning(id: string, workspaceId: string): Promise<MnemoReasoning | null>;
574
+ updateReasoning(id: string, input: UpdateReasoningInput): Promise<MnemoReasoning>;
575
+ archiveReasoning(id: string, workspaceId: string): Promise<void>;
576
+ queryReasoning(filter: ReasoningFilter): Promise<PaginatedResult<MnemoReasoning>>;
577
+ searchReasoning(input: {
578
+ workspaceId: string;
579
+ vector: number[];
580
+ limit: number;
581
+ includeAllStatuses?: boolean;
582
+ }): Promise<Array<{
583
+ id: string;
584
+ cosine: number;
585
+ worth: number;
586
+ successCount: number;
587
+ failureCount: number;
588
+ status: MnemoReasoning["status"];
589
+ }>>;
590
+ recordReasoningUse(id: string, workspaceId: string): Promise<void>;
591
+ setReasoningStatus(id: string, workspaceId: string, status: MnemoReasoning["status"]): Promise<void>;
592
+ getAgentProfile(workspaceId: string, agentId: string): Promise<MnemoAgentProfile | null>;
593
+ upsertAgentProfile(input: {
594
+ workspaceId: string;
595
+ agentId: string;
596
+ summary?: string;
597
+ metadata?: Record<string, unknown>;
598
+ }): Promise<MnemoAgentProfile>;
599
+ incrementSessionsSinceReflection(workspaceId: string, agentId: string): Promise<number>;
600
+ createHyperedge(input: CreateHyperedgeInput): Promise<MnemoHyperedge>;
601
+ getHyperedge(id: string, workspaceId: string, opts?: {
602
+ includeClosed?: boolean;
603
+ maxSensitivity?: Sensitivity;
604
+ }): Promise<MnemoHyperedge | null>;
605
+ updateHyperedge(id: string, input: UpdateHyperedgeInput): Promise<MnemoHyperedge>;
606
+ archiveHyperedge(id: string, workspaceId: string): Promise<void>;
607
+ queryHyperedges(filter: HyperedgeFilter): Promise<PaginatedResult<MnemoHyperedge>>;
608
+ bumpHyperedgeActivation(id: string, workspaceId: string): Promise<void>;
609
+ createCompositionRule(input: CreateCompositionRuleInput): Promise<MnemoCompositionRule>;
610
+ getCompositionRule(id: string, workspaceId: string): Promise<MnemoCompositionRule | null>;
611
+ updateCompositionRule(id: string, workspaceId: string, input: UpdateCompositionRuleInput): Promise<MnemoCompositionRule>;
612
+ queryCompositionRules(filter: CompositionRuleFilter): Promise<PaginatedResult<MnemoCompositionRule>>;
613
+ bumpCompositionExecution(id: string, workspaceId: string): Promise<void>;
614
+ ensureBuiltinCompositionRules(_workspaceId: string): Promise<void>;
615
+ appendInference(input: AppendInferenceInput): Promise<MnemoInferenceLogEntry>;
616
+ materialiseInference(input: MaterialiseInferenceInput): Promise<{
617
+ id: string;
618
+ }>;
619
+ queryInferences(filter: InferenceLogFilter): Promise<PaginatedResult<MnemoInferenceLogEntry>>;
620
+ lookupFactHash(workspaceId: string, statementHash: string): Promise<MnemoFactHash | null>;
621
+ upsertFactHash(input: UpsertFactHashInput): Promise<MnemoFactHash>;
622
+ /** Test-only helper: store a pre-computed embedding to be returned by pointerCandidates. */
623
+ setEmbedding(id: string, vec: number[]): void;
624
+ /**
625
+ * Test-only helper (flatten-legacy-dual-core PR9g): directly set a fact's
626
+ * `embedding` column — `createFact` never writes it synchronously (it
627
+ * enqueues a `vector_upsert` outbox entry instead, mirroring
628
+ * `FactRepository`'s real async-embed contract), so tests exercising
629
+ * `backfillSemanticNeighbors`'s kNN over `MnemoFact.embedding` need a way
630
+ * to seed it deterministically without draining the outbox.
631
+ */
632
+ setFactEmbedding(id: string, vec: ArrayLike<number>): void;
633
+ upsertFactLsh(input: UpsertFactLshInput): Promise<void>;
634
+ getRecallPrimitives(workspaceId: string, refs: RecallPrimitiveRef[]): Promise<RecallPrimitiveRecord[]>;
635
+ getRecallStructures(workspaceId: string, sourceIds: string[], hyperedgeLimitPerMember: number, maxSensitivity?: Sensitivity): Promise<RecallStructures>;
636
+ getUnresolvedConflictIds(workspaceId: string, ids: string[], maxSensitivity?: Sensitivity): Promise<string[]>;
637
+ pointerCandidates(query: PointerCandidateQuery): Promise<PointerCandidate[]>;
638
+ /** FTS arm of hybrid Tier-3 recall: lexical substring match over statement. */
639
+ ftsCandidates(query: Omit<PointerCandidateQuery, "bands">): Promise<FtsCandidate[]>;
640
+ /** make-primitives-recallable (PR3) — non-fact candidates over `mnemo_decision`-equivalent state. */
641
+ recallableCandidates(query: PrimitiveCandidateQuery): Promise<PrimitiveCandidate[]>;
642
+ getConfidenceMap(workspaceId: string, opts?: {
643
+ limit?: number;
644
+ }): Promise<ConfidenceMapRow[]>;
645
+ getKnowledgeGaps(workspaceId: string, opts?: {
646
+ limit?: number;
647
+ minScore?: number;
648
+ }): Promise<KnowledgeGapRow[]>;
649
+ getMetacognitionTrends(workspaceId: string): Promise<MetacognitionTrends>;
650
+ refreshMetacognitionViews(): Promise<void>;
651
+ getSequentialPatterns(args: {
652
+ workspaceId: string;
653
+ predecessorId?: string;
654
+ minConfidence?: number;
655
+ limit?: number;
656
+ }): Promise<SequentialPatternRow[]>;
657
+ getPeriodicPatterns(args: {
658
+ workspaceId: string;
659
+ dayOfWeek?: number;
660
+ hourBucket?: number;
661
+ limit?: number;
662
+ }): Promise<PeriodicPatternRow[]>;
663
+ refreshAnticipationViews(): Promise<void>;
664
+ getConditionalPatterns(): Promise<ConditionalPatternRow[]>;
665
+ getCoOccurrencePatterns(): Promise<CoOccurrencePatternRow[]>;
666
+ createRelation(input: CreateRelationInput): Promise<MnemoRelation>;
667
+ getRelations(filter: RelationFilter): Promise<MnemoRelation[]>;
668
+ listCitations(filter: CitationFilter): Promise<MnemoCitation[]>;
669
+ /**
670
+ * flatten-legacy-dual-core PR9f (design.md D6.5) — mirrors legacy
671
+ * `buildGraphQuery`'s filters exactly (canonical entities only, non-
672
+ * synthetic episodes, active decisions, non-dismissed relations valid at
673
+ * `asOf`/now), then shares `assembleGraphSnapshot` with `GraphRepository`
674
+ * (adapter-postgres) for the focus/meta tail so both never drift.
675
+ */
676
+ getGraphSnapshot(filter: GraphSnapshotFilter): Promise<GraphSnapshot>;
677
+ countEntityMentions(input: {
678
+ workspaceId: string;
679
+ entityIds: string[];
680
+ maxSensitivity?: Sensitivity;
681
+ }): Promise<Record<string, number>>;
682
+ findHiddenIds(input: {
683
+ workspaceId: string;
684
+ ids: string[];
685
+ maxSensitivity: Sensitivity;
686
+ }): Promise<string[]>;
687
+ countOpenConflicts(input: {
688
+ workspaceId: string;
689
+ maxSensitivity?: Sensitivity;
690
+ }): Promise<number>;
691
+ /**
692
+ * flatten-legacy-dual-core PR9g (design.md D6.5) — mirrors legacy
693
+ * `backfillSemanticNeighbors` (`core/src/graph/semantic-neighbors.ts`):
694
+ * delete-then-insert per workspace, brute-force top-k cosine over active
695
+ * embedded facts (no real HNSW index to fake in-memory — this fake has no
696
+ * pgvector, so it's a full scan instead of the adapter-postgres/legacy
697
+ * `INSERT ... JOIN LATERAL`), same per-fact top-k/threshold semantics.
698
+ * Idempotent: delete-first means a repeat call with unchanged embeddings
699
+ * reproduces the identical edge set.
700
+ */
701
+ backfillSemanticNeighbors(input: {
702
+ workspaceId: string;
703
+ k?: number;
704
+ threshold?: number;
705
+ modelVersion?: string;
706
+ }): Promise<number>;
707
+ updateRelationStrength(id: string, delta: number): Promise<void>;
708
+ deleteRelation(id: string, workspaceId: string): Promise<void>;
709
+ closeRelation(id: string, workspaceId: string, opts?: {
710
+ maxSensitivity?: Sensitivity;
711
+ }): Promise<boolean>;
712
+ /** flatten-legacy-dual-core D6.4 — see `ApplyRelationJudgmentInput`'s doc comment (ports.ts). */
713
+ applyRelationJudgment(input: ApplyRelationJudgmentInput): Promise<MnemoRelation | null>;
714
+ resolveConflict(input: ResolveConflictInput): Promise<ResolveConflictResult>;
715
+ updateWorth(id: string, workspaceId: string, primitiveKind: PrimitiveKind, delta: WorthDelta): Promise<void>;
716
+ recordRecall(entry: RecallLogEntry): Promise<void>;
717
+ /** Test inspection of observations recorded by this instance only. */
718
+ readonly recallObservations: RecallObservationStore;
719
+ recordRecallObservation(request: RecallRequestObservation, hits: RecallHitObservation[]): Promise<void>;
720
+ getTdPredecessors(_workspaceId: string, _sessionId: string, _excludeFactId: string): Promise<Array<{
721
+ factId: string;
722
+ tdCredit: number;
723
+ recalledAt: Date;
724
+ }>>;
725
+ getRecallPrecision(workspaceId: string): Promise<RecallPrecisionReport>;
726
+ getContextEconomy(workspaceId: string, days: number, maxSensitivity: Sensitivity): Promise<{
727
+ recalls: number;
728
+ servedCharsAvg: number | null;
729
+ servedCharsP95: number | null;
730
+ liveFacts: number;
731
+ liveFactChars: number;
732
+ }>;
733
+ getRecallLatency(workspaceId: string, days: number): Promise<{
734
+ p50Ms: number | null;
735
+ p95Ms: number | null;
736
+ samples: number;
737
+ }>;
738
+ getWritesPerDay(workspaceId: string, days: number): Promise<Array<{
739
+ day: string;
740
+ count: number;
741
+ }>>;
742
+ getRecallMetrics(workspaceId: string, days: number): Promise<RecallMetrics>;
743
+ getSessionStats(input: {
744
+ workspaceId: string;
745
+ days: number;
746
+ maxSensitivity?: Sensitivity;
747
+ }): Promise<SessionStats>;
748
+ getFactStats(input: {
749
+ workspaceId: string;
750
+ maxSensitivity?: Sensitivity;
751
+ }): Promise<FactStats>;
752
+ setCanonical(id: string, workspaceId: string, canonical: boolean): Promise<void>;
753
+ getRecalledFactIds(workspaceId: string, sessionId: string): Promise<string[]>;
754
+ getProvenanceCredit(workspaceId: string, terminalIds: string[], lambda: number, maxHops: number): Promise<Array<{
755
+ factId: string;
756
+ credit: number;
757
+ }>>;
758
+ listActiveLearningReview(filter: ActiveLearningReviewFilter): Promise<ActiveLearningReviewRow[]>;
759
+ countUnresolvedActiveLearningReview(workspaceId: string): Promise<number>;
760
+ enqueueActiveLearningReview(input: EnqueueActiveLearningReviewInput): Promise<EnqueueActiveLearningReviewResult>;
761
+ resolveActiveLearningReview(input: ResolveActiveLearningReviewInput): Promise<ResolveActiveLearningReviewResult>;
762
+ appendAuditEntry(entry: Omit<AuditLogEntry, "id" | "createdAt">): Promise<void>;
763
+ listAuditLog(workspaceId: string, limit: number): Promise<AuditLogEntry[]>;
764
+ getAuditActivity(input: {
765
+ workspaceId: string;
766
+ days: number;
767
+ actorIds: string[];
768
+ }): Promise<AuditActivity>;
769
+ appendOutbox(entry: Omit<OutboxEntry, "id" | "createdAt" | "attempts">): Promise<void>;
770
+ claimOutbox(limit: number): Promise<OutboxEntry[]>;
771
+ markOutboxProcessed(ids: string[]): Promise<void>;
772
+ markOutboxFailed(id: string, error: string): Promise<void>;
773
+ reapDeadLetters(maxAttempts: number): Promise<number>;
774
+ purgeOutbox(olderThanMs: number): Promise<number>;
775
+ countPendingOutbox(): Promise<number>;
776
+ createWebhookEndpoint(input: CreateWebhookEndpointInput): Promise<MnemoWebhookEndpoint>;
777
+ getWebhookEndpoint(id: string, workspaceId: string): Promise<MnemoWebhookEndpoint | null>;
778
+ listWebhookEndpoints(workspaceId: string): Promise<MnemoWebhookEndpoint[]>;
779
+ updateWebhookEndpoint(id: string, workspaceId: string, input: UpdateWebhookEndpointInput): Promise<MnemoWebhookEndpoint>;
780
+ deleteWebhookEndpoint(id: string, workspaceId: string): Promise<void>;
781
+ recordWebhookDelivery(entry: CreateWebhookDeliveryInput): Promise<void>;
782
+ listWebhookDeliveries(webhookId: string, workspaceId: string, limit?: number): Promise<MnemoWebhookDelivery[]>;
783
+ listPendingWebhookDeliveries(limit: number): Promise<MnemoWebhookDelivery[]>;
784
+ updateWebhookDelivery(id: string, workspaceId: string, update: {
785
+ status?: "pending" | "delivered" | "failed";
786
+ responseStatus?: number;
787
+ responseBody?: string;
788
+ attempt?: number;
789
+ deliveredAt?: Date;
790
+ nextAttemptAt?: Date | null;
791
+ }): Promise<void>;
792
+ createReminder(input: CreateReminderInput): Promise<MnemoReminder>;
793
+ listDueReminderWorkspaceIds(): Promise<string[]>;
794
+ getReminder(id: string, workspaceId: string): Promise<MnemoReminder | null>;
795
+ listPendingReminders(workspaceId: string, asOf: Date): Promise<MnemoReminder[]>;
796
+ dismissReminder(id: string, workspaceId: string, newStatus: "triggered" | "dismissed"): Promise<void>;
797
+ listReminders(workspaceId: string, status: "pending" | "triggered" | "dismissed" | "all", limit: number): Promise<MnemoReminder[]>;
798
+ claimUndeliveredReminders(workspaceId: string, input: {
799
+ ids: string[];
800
+ limit: number;
801
+ }): Promise<MnemoReminder[]>;
802
+ getRecallLog(workspaceId: string, memoryId: string, limit: number): Promise<Array<{
803
+ id: string;
804
+ recalledAt: string;
805
+ recallScore: number;
806
+ }>>;
807
+ getRecallLogs(workspaceId: string, memoryIds: string[], limitPerMemory: number): Promise<RecallLogRecord[]>;
808
+ getRecentQueriesForFacts(workspaceId: string, factIds: string[], limit: number): Promise<string[]>;
809
+ lookupQueryCache(input: LookupQueryCacheInput): Promise<{
810
+ resultIds: string[];
811
+ resultKinds: string[];
812
+ } | null>;
813
+ pruneQueryCache(workspaceId: string, olderThanMs: number): Promise<number>;
814
+ insertQueryCache(input: InsertQueryCacheInput): Promise<void>;
815
+ getCachedEmbedding(workspaceId: string, textHash: string, model?: string): Promise<Float32Array | null>;
816
+ putCachedEmbedding(input: {
817
+ workspaceId: string;
818
+ textHash: string;
819
+ embedding: Float32Array;
820
+ model: string;
821
+ }): Promise<void>;
822
+ healthCheck(): Promise<HealthStatus>;
823
+ close(): Promise<void>;
824
+ listWorkspaceIds(): Promise<string[]>;
825
+ getWorkspaceMode(workspaceId: string): Promise<{
826
+ entityCount: number;
827
+ mode: "learning" | "production";
828
+ sessionCount: number;
829
+ promoteAt: number | null;
830
+ startedAt: Date;
831
+ factCount: number;
832
+ } | null>;
833
+ setWorkspaceMode(workspaceId: string, patch: {
834
+ mode?: "learning" | "production";
835
+ sessionCount?: number;
836
+ promoteAt?: number | null;
837
+ factCount?: number;
838
+ entityCount?: number;
839
+ }): Promise<void>;
840
+ incrementWorkspaceModeCounters(workspaceId: string, delta: {
841
+ factCount?: number;
842
+ entityCount?: number;
843
+ sessionCount?: number;
844
+ }): Promise<void>;
845
+ decayKind(workspaceId: string, decayClass: string, halfLifeDays: number): Promise<number>;
846
+ recordCoRecallStdp(workspaceId: string, relationId: string, coRecalledAt: Date): Promise<void>;
847
+ normalizeHebbianWeights(workspaceId: string): Promise<number>;
848
+ enqueueReviewItem(input: {
849
+ workspaceId: string;
850
+ primitiveId: string;
851
+ primitiveKind?: string;
852
+ reason: string;
853
+ detail?: Record<string, unknown>;
854
+ }): Promise<void>;
855
+ queryDriftCandidates(workspaceId: string): Promise<Array<{
856
+ id: string;
857
+ statement: string;
858
+ metadata: Record<string, unknown>;
859
+ sensitivity: Sensitivity;
860
+ }>>;
861
+ listStaleEmbeddings(table: EmbeddableTable, workspaceId: string, currentModel: string, limit: number, opts?: {
862
+ plaintextOnly?: boolean;
863
+ }): Promise<Array<{
864
+ id: string;
865
+ text: string;
866
+ }>>;
867
+ hasActiveEmbeddingMigration(workspaceId: string, currentModel: string): Promise<boolean>;
868
+ markEmbeddingsStale(table: EmbeddableTable, workspaceId: string, currentModel: string): Promise<number>;
869
+ updateEmbeddingVector(table: EmbeddableTable, id: string, workspaceId: string, vector: number[], model: string): Promise<void>;
870
+ upsertHotTierSnapshot(rows: HotTierSnapshotRow[]): Promise<void>;
871
+ loadHotTierSnapshots(workspaceId?: string): Promise<HotTierSnapshotRow[]>;
872
+ /**
873
+ * Return distinct topic_keys for facts in a session that were tagged with the
874
+ * given extraction_source. Used by the hybrid collapse dedup gate.
875
+ */
876
+ listSessionTopicKeysBySource(workspaceId: string, sessionId: string, source: string): Promise<string[]>;
877
+ /** Clear all data — call between test cases. */
878
+ reset(): void;
879
+ }
880
+
881
+ declare function runStorageAdapterContractTests(makeAdapter: () => StorageAdapter | Promise<StorageAdapter>): void;
882
+
883
+ declare class InMemoryAccessPolicyStore implements AccessPolicyStore {
884
+ private readonly byKey;
885
+ private key;
886
+ getPolicy(workspaceId: string, agentId: string): Promise<AccessPolicyRecord | null>;
887
+ putPolicy(policy: AccessPolicyRecord): Promise<void>;
888
+ listPolicies(workspaceId: string): Promise<AccessPolicyRecord[]>;
889
+ deletePolicy(workspaceId: string, agentId: string): Promise<boolean>;
890
+ }
891
+
892
+ declare class InMemoryApprovalStore implements ApprovalStore {
893
+ private readonly byId;
894
+ create(input: ApprovalRequestInput): Promise<ApprovalRequest>;
895
+ get(workspaceId: string, id: string): Promise<ApprovalRequest | null>;
896
+ resolve(workspaceId: string, id: string, status: "approved" | "denied", resolvedBy: string): Promise<boolean>;
897
+ consume(workspaceId: string, id: string, by: {
898
+ requestedBy: string;
899
+ method: string;
900
+ path: string;
901
+ }): Promise<boolean>;
902
+ }
903
+
904
+ /**
905
+ * WP8 (F10) — In-memory test double for the BreakGlassStore port.
906
+ *
907
+ * Pure decision logic only — no infra imports (Postgres / Drizzle live in the
908
+ * adapter layer). The two-person dual-control rule (requester ≠ approver) and
909
+ * the pending → approved → used finite-state machine are enforced here so they
910
+ * can be unit-tested without a database.
911
+ */
912
+ declare class InMemoryBreakGlassStore implements BreakGlassStore {
913
+ private readonly byId;
914
+ request(input: BreakGlassRequestInput): Promise<BreakGlassRequestRecord>;
915
+ approve(workspaceId: string, id: string, approverId: string): Promise<void>;
916
+ get(workspaceId: string, id: string): Promise<BreakGlassRequestRecord | null>;
917
+ getActiveApproved(workspaceId: string, requestedBy: string): Promise<BreakGlassRequestRecord | null>;
918
+ markUsed(workspaceId: string, id: string): Promise<void>;
919
+ }
920
+
921
+ interface HarnessContractSnapshot {
922
+ sessions: Array<{
923
+ id: string;
924
+ clientInstanceId: string;
925
+ generation: number;
926
+ status: string;
927
+ closeKind: string | null;
928
+ turnCount: number;
929
+ tokenCount: number;
930
+ lastActivityAt: Date | null;
931
+ closeGraceDeadline: Date | null;
932
+ sensitivity: string;
933
+ captureIncomplete: boolean;
934
+ predecessorSessionId: string | null;
935
+ terminalMessageSetDigest: string | null;
936
+ terminalMaxEnqueueSequence: number | null;
937
+ leased: boolean;
938
+ }>;
939
+ turns: Array<{
940
+ sessionId: string;
941
+ turnIndex: number;
942
+ sourceMessageId: string;
943
+ supersedesSourceMessageId: string | null;
944
+ role: string;
945
+ content: string;
946
+ contentHash: string;
947
+ retracted: boolean;
948
+ }>;
949
+ ledger: Array<{
950
+ eventId: string;
951
+ state: string;
952
+ payloadHash: string;
953
+ actorId?: string;
954
+ actorType?: string;
955
+ userId?: string | null;
956
+ sensitivityCeiling?: string;
957
+ acknowledgement: HarnessEventAck | null;
958
+ }>;
959
+ losses: Array<{
960
+ sessionId: string;
961
+ sourceMessageId: string;
962
+ role: string;
963
+ contentHash: string;
964
+ }>;
965
+ retractions: Array<{
966
+ sessionId: string;
967
+ sourceMessageId: string;
968
+ predecessorSessionId: string | null;
969
+ }>;
970
+ }
971
+ interface HarnessContractFixture {
972
+ workspaceId: string;
973
+ port: HarnessIngestionPort;
974
+ inspect(): Promise<HarnessContractSnapshot>;
975
+ getSessionStatus(id: string): Promise<string | null>;
976
+ setSessionLifecycle(input: {
977
+ generation: number;
978
+ status: "active" | "collapse_pending" | "collapsed" | "archived";
979
+ leased?: boolean;
980
+ closeKind?: "authoritative" | "provisional" | null;
981
+ closeGraceDeadline?: Date | null;
982
+ terminalMaxEnqueueSequence?: number | null;
983
+ terminalMessageSetDigest?: string | null;
984
+ }): Promise<void>;
985
+ seedManagedTurn(input: {
986
+ generation: number;
987
+ sourceMessageId: string;
988
+ role: "user" | "assistant";
989
+ content: string;
990
+ contentHash: string;
991
+ }): Promise<void>;
992
+ }
993
+ type HarnessContractFixtureFactory = () => Promise<HarnessContractFixture>;
994
+ declare function runHarnessIngestionContractTests(makeFixture: HarnessContractFixtureFactory): void;
995
+
996
+ export { InMemoryAccessPolicyStore, InMemoryApprovalStore, InMemoryBreakGlassStore, InMemoryStorageAdapter, runHarnessIngestionContractTests, runStorageAdapterContractTests };
997
+ export type { HarnessContractFixture, HarnessContractSnapshot };