dotmem 0.1.9 → 0.2.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,3652 @@
1
+ // Auto-generated global types
2
+
3
+ type _LifecycleConfig = LifecycleConfig
4
+
5
+ type _LifecycleStatus = LifecycleStatus
6
+
7
+ type _Checkpoint = Checkpoint
8
+
9
+ type _CheckpointMeta = CheckpointMeta
10
+
11
+ type _CheckpointFact = CheckpointFact
12
+
13
+ type _ThematicSummary = ThematicSummary
14
+
15
+ type _ResumePackage = ResumePackage
16
+
17
+ type _ResumePrompt = ResumePrompt
18
+
19
+ type _HostPort = HostPort
20
+
21
+ type _ContextUsage = ContextUsage
22
+
23
+ type _LifecyclePhase = LifecyclePhase
24
+
25
+ type _LifecycleEvent = LifecycleEvent
26
+
27
+ type _TriggerReason = TriggerReason
28
+
29
+ type CliModule = typeof import('@core/cli')
30
+
31
+ interface CodenameEntry {
32
+ name: Codename
33
+ /** The surface this name labels. Identity only - never used for routing. */
34
+ surface: string
35
+ /** Why this name maps to this surface. */
36
+ rationale: string
37
+ status: CodenameStatus
38
+ }
39
+
40
+ type CodenameKey = keyof typeof CODENAMES
41
+
42
+ type Codename = (typeof CODENAMES)[CodenameKey]
43
+
44
+ type CodenameStatus = 'active' | 'assigned' | 'reserved'
45
+
46
+ interface ShortResultBase<T = unknown> {
47
+ success: boolean
48
+ status: ShortResultStatus
49
+ value?: T
50
+ error?: ShortError
51
+ }
52
+
53
+ interface ShortError {
54
+ code: string
55
+ message: string
56
+ remediation?: string
57
+ intent: ShortIntent
58
+ stateChanged?: boolean
59
+ confirmation?: ShortConfirmation
60
+ }
61
+
62
+ interface ShortConfirmation {
63
+ required: boolean
64
+ reason: string
65
+ action?: string
66
+ }
67
+
68
+ interface ShortAggregateResult {
69
+ success: boolean
70
+ partial: boolean
71
+ results: Record<ShortIntent, ShortResultBase>
72
+ errors: ShortError[]
73
+ }
74
+
75
+ interface NotePayload {
76
+ text?: string
77
+ structured?: {
78
+ id?: string
79
+ title?: string
80
+ content: string
81
+ origin: string
82
+ scope?: 'user' | 'project'
83
+ tag?: string
84
+ evidence?: Array<{ id: string; source: string; observedAt?: string }>
85
+ }
86
+ }
87
+
88
+ interface RememberPayload {
89
+ key: string
90
+ value: unknown
91
+ scope?: 'local' | 'session' | 'durable'
92
+ tags?: string | string[]
93
+ confidence?: number
94
+ ttl?: number | null
95
+ }
96
+
97
+ interface RecallPayload {
98
+ query: string
99
+ type?: 'fact' | 'preference' | 'decision' | 'task' | 'context'
100
+ minConfidence?: number
101
+ includeObsolete?: boolean
102
+ }
103
+
104
+ interface ForgetPayload {
105
+ key: string
106
+ }
107
+
108
+ interface AcquirePayload {
109
+ knowledge: unknown
110
+ applicability?: Record<string, string | number | boolean | null>
111
+ evidence?: Array<{ id: string; source?: string; observedAt?: string; supports?: string }>
112
+ epistemicType?: 'observed' | 'inferred' | 'human-stated' | 'verified'
113
+ provenance?: { source: string; detail?: string }
114
+ refines?: string | string[]
115
+ supersedes?: string | string[]
116
+ retracts?: string | string[]
117
+ reason?: string
118
+ scope?: 'user' | 'project'
119
+ kind?: 'experience' | 'agent' | 'logic' | 'note'
120
+ sourceProject?: string
121
+ acquiredAt?: string
122
+ expiresAt?: number
123
+ bootstrapPriority?: 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'unclassified'
124
+ }
125
+
126
+ interface ContextPayload {
127
+ situation: string
128
+ maxCandidates?: number
129
+ maxCharacters?: number
130
+ includeRules?: boolean
131
+ }
132
+
133
+ interface BootstrapPayload {
134
+ situation?: string
135
+ sinceVersion?: number
136
+ }
137
+
138
+ interface RulesPayload {
139
+ expand?: boolean
140
+ }
141
+
142
+ interface PolicyPayload {
143
+ event: string
144
+ claims?: unknown[]
145
+ policies?: Array<{
146
+ event: string
147
+ tier?: string
148
+ condition?: {
149
+ kind: string
150
+ field: string
151
+ value: string
152
+ }
153
+ }>
154
+ overrides?: Array<{
155
+ id: string
156
+ targetPolicyId: string
157
+ targetRevision: number
158
+ targetFingerprint: string
159
+ relaxTo: string
160
+ authority: { kind: 'HI' | 'operator'; source: string; detail?: string }
161
+ grantedAt: string
162
+ expiresAt: string
163
+ reason: string
164
+ }>
165
+ }
166
+
167
+ interface DiscoverPayload {
168
+ situation: string
169
+ depth?: 'current' | 'deep'
170
+ maxCandidates?: number
171
+ cursor?: { offset: number; knowledgeVersion: number }
172
+ includeRules?: boolean
173
+ facts?: Record<string, string | number | boolean | null>
174
+ }
175
+
176
+ interface InspectPayload {
177
+ file: string
178
+ action?: 'package' | 'list' | 'claims' | 'diff'
179
+ redact?: boolean
180
+ limit?: number
181
+ offset?: number
182
+ fileA?: string
183
+ fileB?: string
184
+ }
185
+
186
+ interface MergePayload {
187
+ id: string
188
+ previousId: string
189
+ title?: string
190
+ content: string
191
+ origin: string
192
+ scope?: 'user' | 'project'
193
+ tag?: string
194
+ }
195
+
196
+ interface ConfigurePayload {
197
+ sync?: {
198
+ provider?: string
199
+ [key: string]: unknown
200
+ }
201
+ [key: string]: unknown
202
+ }
203
+
204
+ interface CapturePayload {
205
+ messages: Array<{ role: string; content: string; id?: string; timestamp?: string }>
206
+ options?: {
207
+ conversationId?: string
208
+ triggerReason?: string
209
+ tokenBudget?: number
210
+ }
211
+ }
212
+
213
+ type ShortIntent =
214
+ | 'note'
215
+ | 'remember'
216
+ | 'recall'
217
+ | 'forget'
218
+ | 'update'
219
+ | 'patch'
220
+ | 'acquire'
221
+ | 'verify'
222
+ | 'important'
223
+ | 'avoid'
224
+ | 'prefer'
225
+ | 'warning'
226
+ | 'context'
227
+ | 'bootstrap'
228
+ | 'rules'
229
+ | 'policy'
230
+ | 'project'
231
+ | 'discover'
232
+ | 'inspect'
233
+ | 'dump'
234
+ | 'audit'
235
+ | 'health'
236
+ | 'doctor'
237
+ | 'repair'
238
+ | 'cleanup'
239
+ | 'relate'
240
+ | 'link'
241
+ | 'unlink'
242
+ | 'merge'
243
+ | 'configure'
244
+ | 'capabilities'
245
+ | 'seed'
246
+ | 'capture'
247
+
248
+ type ShortResultStatus =
249
+ | 'completed'
250
+ | 'failed'
251
+ | 'blocked'
252
+ | 'pending'
253
+ | 'skipped'
254
+
255
+ type IntentHandler = (
256
+ runtime: any,
257
+ payload: unknown
258
+ ) => Promise<ShortResultBase>
259
+
260
+ interface BuildProfileDocument {
261
+ readonly name: string
262
+ readonly content: string
263
+ readonly digest: string
264
+ readonly size: number
265
+ }
266
+
267
+ interface BuildProfile {
268
+ readonly format: 'dotmem.profile'
269
+ readonly version: 1
270
+ readonly id: string
271
+ readonly name: string
272
+ readonly displayName?: string
273
+ readonly alternative: readonly string[]
274
+ readonly displayAlias?: string
275
+ readonly documents: readonly BuildProfileDocument[]
276
+ readonly type: string
277
+ readonly role: string
278
+ readonly immutable: true
279
+ readonly description: string
280
+ }
281
+
282
+ interface BuildBranding {
283
+ readonly productName: string
284
+ readonly mcpServerName: string
285
+ readonly mcpServerDescription: string
286
+ readonly cliName: string
287
+ readonly cliMcpName: string
288
+ }
289
+
290
+ interface BuildConfig {
291
+ readonly profileId: string
292
+ readonly profile: BuildProfile
293
+ readonly branding: BuildBranding
294
+ }
295
+
296
+ interface ContextRunOptions {
297
+ explain?: boolean
298
+ json?: boolean
299
+ full?: boolean
300
+ claimsOnly?: boolean
301
+ limit?: number
302
+ /** Offset into the ranked candidate list for cursor-based pagination. */
303
+ offset?: number
304
+ format?: 'brief'
305
+ /** Return the omission manifest instead of the rendered projection. */
306
+ manifest?: boolean
307
+ /** Expand one claim by id to its canonical record. */
308
+ claimId?: string
309
+ }
310
+
311
+ interface LearnOptions {
312
+ text: string
313
+ scope: 'user' | 'project'
314
+ situation?: string
315
+ id?: string
316
+ }
317
+
318
+ interface CompactionEngineOptions {
319
+ scope?: 'user' | 'project' | 'task'
320
+ subject?: string
321
+ projectIdentity?: string
322
+ config?: LifecycleConfig
323
+ host?: HostPort
324
+ }
325
+
326
+ interface ContinuityToolDependencies {
327
+ orchestrator: ContextLifecycleOrchestrator
328
+ }
329
+
330
+ interface DotMemContinuityInput {
331
+ action: string
332
+ conversationId?: string
333
+ triggerReason?: 'threshold' | 'milestone' | 'decision' | 'incident' | 'sessionEnd' | 'explicit'
334
+ resumePackageId?: string
335
+ openLoopDescription?: string
336
+ openLoopId?: string
337
+ openLoopPriority?: 'low' | 'normal' | 'high'
338
+ brainId?: string
339
+ tokenBudget?: number
340
+ scope?: 'user' | 'project' | 'task'
341
+ subject?: string
342
+ statePatch?: Record<string, unknown>
343
+ objective?: string
344
+ activeTopic?: string
345
+ currentProblem?: string
346
+ establishedUnderstanding?: string
347
+ currentWorkingPosition?: string
348
+ nextConversationalStep?: string
349
+ lastCompletedAction?: string
350
+ }
351
+
352
+ type ContinuityToolResult = {
353
+ content: Array<{ type: 'text'; text: string }>
354
+ structuredContent?: unknown
355
+ isError?: boolean
356
+ }
357
+
358
+ interface OperationRecord {
359
+ timestamp: number
360
+ estimatedTokens: number
361
+ characters: number
362
+ }
363
+
364
+ interface MonitoringResult {
365
+ usage: ContextUsage
366
+ shouldCheckpoint: boolean
367
+ triggerReason: TriggerReason[]
368
+ }
369
+
370
+ interface OrchestratorOptions {
371
+ projectIdentity?: string
372
+ scope?: 'user' | 'project' | 'task'
373
+ subject?: string
374
+ config?: LifecycleConfig
375
+ host?: HostPort
376
+ }
377
+
378
+ interface LifecycleEventRecord {
379
+ type: string
380
+ phase: LifecyclePhase
381
+ timestamp: string
382
+ data: Record<string, unknown>
383
+ }
384
+
385
+ interface ResumePackageInput {
386
+ projectIdentity: string
387
+ scope: 'user' | 'project' | 'task'
388
+ subject: string
389
+ checkpoint: Checkpoint
390
+ summaries: ThematicSummary[]
391
+ sourceReferences: ContinuitySourceRef[]
392
+ maxSizeTokens: number
393
+ triggerReason: TriggerReason
394
+ usage: ContextUsage
395
+ }
396
+
397
+ interface DotMemEncryptedEnvelope {
398
+ id?: string
399
+ iv: string
400
+ data: string
401
+ tag?: string
402
+ algorithm?: string
403
+ keyId?: string
404
+ }
405
+
406
+ interface SubtleCryptoLike {
407
+ digest(algorithm: string, data: Uint8Array): Promise<Uint8Array>
408
+ deriveKey(
409
+ algorithm: AlikeAlgorithm,
410
+ baseKey: CryptoKey,
411
+ derivedKeyAlgorithm: AlikeAlgorithm,
412
+ extractable: boolean,
413
+ keyUsages: SubKeyUsages
414
+ ): Promise<CryptoKey>
415
+ deriveBits(
416
+ algorithm: AlikeAlgorithm,
417
+ baseKey: CryptoKey,
418
+ length: number
419
+ ): Promise<Uint8Array>
420
+ exportKey(format: string, key: CryptoKey): Promise<Uint8Array>
421
+ importKey(
422
+ format: string,
423
+ keyData: Uint8Array,
424
+ algorithm: AlikeAlgorithm,
425
+ extractable: boolean,
426
+ keyUsages: SubKeyUsages
427
+ ): Promise<CryptoKey>
428
+ encrypt(
429
+ algorithm: AlikeAlgorithm,
430
+ key: CryptoKey,
431
+ data: Uint8Array
432
+ ): Promise<Uint8Array>
433
+ decrypt(
434
+ algorithm: AlikeAlgorithm,
435
+ key: CryptoKey,
436
+ data: Uint8Array
437
+ ): Promise<Uint8Array>
438
+ }
439
+
440
+ type SubKeyUsages = readonly ['encrypt', 'decrypt'] | readonly ['deriveKey'] | readonly ['deriveBits']
441
+
442
+ type AlikeAlgorithm = Record<string, unknown>
443
+
444
+ interface ProjectState {
445
+ initialized: boolean
446
+ dotmemDir: string
447
+ dotmemReadmePath: string
448
+ dotmemReadmeValid: boolean
449
+ /** Project identity resolved for the current working directory. */
450
+ projectId: string
451
+ /** Resolved path of the project anchor (projects/<projectId>.mem). */
452
+ projectAnchorPath: string
453
+ /** True when the project anchor file exists. */
454
+ projectAnchorPresent: boolean
455
+ }
456
+
457
+ interface MemoryReadiness {
458
+ ready: boolean
459
+ totalSources: number
460
+ totalClaims: number
461
+ sources: string[]
462
+ }
463
+
464
+ interface AiDetectionResult {
465
+ detected: boolean
466
+ evidence: string[]
467
+ name?: string
468
+ connected: boolean
469
+ communicationPath: string | null
470
+ ready: boolean
471
+ }
472
+
473
+ interface BootstrapReport {
474
+ project: ProjectState
475
+ memory: MemoryReadiness
476
+ ai: AiDetectionResult
477
+ context?: string
478
+ /** Persistent default response language loaded from canonical user config. */
479
+ language?: string
480
+ userLanguage?: string
481
+ responseLanguage?: string
482
+ /** Canonical hard-rules registry readiness. */
483
+ hardRulesReady?: boolean
484
+ hardRulesRevision?: number
485
+ /** Canonical built-in context readiness. */
486
+ builtInContextReady?: boolean
487
+ builtInContextVersion?: string
488
+ }
489
+
490
+ interface ContextRunOptions {
491
+ /** Explain why each evaluated claim was selected, excluded or left unresolved. */
492
+ explain?: boolean
493
+ /** With `explain`, return the structured explanation model instead of rendered text. */
494
+ json?: boolean
495
+ /**
496
+ * Explicit current HI identity supplied by the runtime (the operator layer).
497
+ *
498
+ * This is the only channel through which a current USER_IDENTITY may enter
499
+ * the projection. An ordinary memory
500
+ * claim named `user-name` never asserts current identity; it remains
501
+ * historical evidence in the store.
502
+ */
503
+ hiIdentity?: string
504
+ /**
505
+ * Explicit current HI assignment for the AGENT identity (the operator layer).
506
+ *
507
+ * When present it wins over the canonical profile default; when absent the
508
+ * resolver uses the profile. Memory and context never assign it.
509
+ */
510
+ agentIdentity?: string
511
+ /**
512
+ * Scoped, temporary overlays for this run. Overlays may
513
+ * influence behavior but never identity, invariants, or authority, and they
514
+ * are never persisted.
515
+ */
516
+ overlays?: readonly unknown[]
517
+ /**
518
+ * A verified carrier handshake session record.
519
+ *
520
+ * The CLI activation path is handshake-gated: `npx dotmem` projects the
521
+ * identity channel only for a carrier that demonstrated the minimal
522
+ * identity/authority separation contract. Programmatic callers may pass a
523
+ * valid record here. The record is session state, never authority: it
524
+ * describes the carrier evaluation, it does not grant anything.
525
+ */
526
+ handshake?: HandshakeSessionRecord
527
+ /**
528
+ * Bypass the session-start projection ceiling (default 3000 characters) and
529
+ * the candidate cap, returning the complete projection. CLI:
530
+ * `dotmem context "<situation>" --full`. Read-only: never persisted.
531
+ */
532
+ full?: boolean
533
+ /**
534
+ * Omit the trusted identity channel and all auxiliary rendering (index,
535
+ * size disclosure, personality anchor, exemplars), returning only the
536
+ * memory-context envelope (`DOTMEM_CONTEXT_V1` and the candidate claims).
537
+ * Default behavior (full projection) is unchanged for backward compatibility.
538
+ * CLI: `dotmem context "<situation>" --claims-only`.
539
+ *
540
+ * The identity channel is never withheld from an unbound carrier: the
541
+ * activation gate above already enforces fail-closed, and this flag only
542
+ * affects the payload of an already-authorized projection.
543
+ */
544
+ claimsOnly?: boolean
545
+ /**
546
+ * Cap the number of candidate claims returned, best first.
547
+ * CLI: `dotmem context "<situation>" --limit <N>`.
548
+ * When omitted, the default candidate limit applies.
549
+ */
550
+ limit?: number
551
+ /**
552
+ * Offset into the ranked candidate list for cursor-based pagination.
553
+ * Reuses `DiscoveryCursor.offset` and the `snapshotChanged` mechanism.
554
+ */
555
+ offset?: number
556
+ /**
557
+ * Filter to brief one-line-per-claim output format.
558
+ * CLI: `dotmem context "<situation>" --format brief`.
559
+ */
560
+ format?: 'brief'
561
+ /**
562
+ * Return the omission manifest as JSON instead of the rendered projection.
563
+ * The manifest names every claim the run left out, with the decisive gate.
564
+ */
565
+ manifest?: boolean
566
+ /** Expand one claim by id to its canonical record. */
567
+ claimId?: string
568
+ }
569
+
570
+ interface ActivationGate {
571
+ readonly state: ActivationState
572
+ readonly allowed: boolean
573
+ readonly record: HandshakeSessionRecord | null
574
+ /** The bound HI identity from the session record, when authorized. */
575
+ readonly hiIdentity: string | null
576
+ /** What the carrier receives when activation is not allowed. */
577
+ readonly text: string
578
+ }
579
+
580
+ type ActivationState = 'HANDSHAKE_REQUIRED' | 'COMPATIBLE' | 'LIMITED' | 'INCOMPATIBLE' | 'AUTHORITY_UNBOUND'
581
+
582
+ interface ConvergenceState {
583
+ /** Genuine attempts made on the current blocker. */
584
+ attempts: number
585
+ /** True when the last attempt produced evidence that was not available before. */
586
+ newEvidence: boolean
587
+ /** True when the last attempt tested a materially new hypothesis. */
588
+ newHypothesis: boolean
589
+ /** Operating attempt budget before the gap must be stated. Default 3. */
590
+ attemptBudget?: number
591
+ }
592
+
593
+ interface ConvergenceVerdict {
594
+ status: ConvergenceStatus
595
+ /** Present when status is 'stop': the gap Jo must state. */
596
+ gap?: string
597
+ }
598
+
599
+ interface ResponseSanityCheckInput {
600
+ /** Does the response actually answer what was asked? */
601
+ makesSense: boolean
602
+ /** Is length being added to cover a weak answer or falling certainty? */
603
+ padded: boolean
604
+ /** Can the first line carry the actual answer? */
605
+ firstLineCarriesAnswer: boolean
606
+ }
607
+
608
+ interface ResponseSanityCheckVerdict {
609
+ /** True when the response may be sent as-is. */
610
+ send: boolean
611
+ /** True when the response must be shortened before sending. */
612
+ shorten: boolean
613
+ }
614
+
615
+ interface LearningNegatives {
616
+ whatFailed?: string
617
+ whatWasMissing?: string
618
+ whatWasCompensated?: string
619
+ externalSourceRequired?: string
620
+ assumptionDisproved?: string
621
+ }
622
+
623
+ interface LearningCandidateInput {
624
+ event: LearningEvent
625
+ /** Would knowing this materially improve a future attempt? Default answer is no. */
626
+ materiallyImproves: boolean
627
+ /** Negatives captured from the event; candidates are built from these. */
628
+ negatives: LearningNegatives
629
+ }
630
+
631
+ interface LearningCandidate {
632
+ kind: 'candidate'
633
+ event: LearningEvent
634
+ /** The captured negatives, in priority order. */
635
+ negatives: string[]
636
+ }
637
+
638
+ interface EpisodeDraft {
639
+ moment: string
640
+ context: string
641
+ whyItMattered: string
642
+ whatChangedAfter: string
643
+ participantsOrReferences?: string[]
644
+ }
645
+
646
+ interface EpisodeClaim {
647
+ kind: 'experience'
648
+ applicability: { area: 'episode'; component: string }
649
+ knowledge: EpisodeDraft
650
+ }
651
+
652
+ type ConvergenceStatus = 'continue' | 'stop'
653
+
654
+ type LearningEvent =
655
+ | 'corrected-error'
656
+ | 'disproved-assumption'
657
+ | 'compensated-success'
658
+ | 'repeated-non-convergence'
659
+
660
+ type ExplicitProfileRequest =
661
+ | { readonly kind: 'canonical'; readonly id: string }
662
+ | { readonly kind: 'unknown'; readonly id: string }
663
+ | null
664
+
665
+ interface DotMemProfileDocument {
666
+ readonly name: string
667
+ readonly content: string
668
+ }
669
+
670
+ interface DotMemProfile {
671
+ readonly format: 'dotmem.profile'
672
+ readonly version: 1
673
+ readonly id: string
674
+ readonly name: string
675
+ /** The human-readable identity name, when it differs from the canonical id. */
676
+ readonly displayName?: string
677
+ readonly alternative: readonly string[]
678
+ /** The human-readable conversational alias, when it differs from the canonical alias. */
679
+ readonly displayAlias?: string
680
+ readonly documents: ReadonlyArray<DotMemProfileDocument>
681
+ readonly type: string
682
+ readonly role: string
683
+ readonly immutable: true
684
+ readonly description: string
685
+ }
686
+
687
+ interface AcquisitionBoundaryResult {
688
+ /** Sanitized knowledge with every non-authoritative tier field removed. */
689
+ knowledge: JsonValue
690
+ /** Effective storage kind; only an explicit `opts.kind` changes the default. */
691
+ kind: MemoryKind
692
+ /** Whether the sanitizer redacted anything (secret shapes). */
693
+ sanitized: boolean
694
+ /** How many non-authoritative tier fields were stripped. */
695
+ removedTierFields: number
696
+ /** The policy evaluation for the memory.acquire event, even when empty. */
697
+ evaluation: PolicyEvaluation
698
+ }
699
+
700
+ interface AcquisitionBoundaryDependencies {
701
+ policyStore?: PolicyStore
702
+ /** Size limits for this acquisition path. Defaults to the library limits. */
703
+ limits?: MemoryAcquireLimits
704
+ }
705
+
706
+ interface MemoryAcquireLimits {
707
+ /** Maximum serialized size of a single knowledge field. */
708
+ maximumFieldBytes: number
709
+ /** Maximum serialized size of the whole knowledge payload of one claim. */
710
+ maximumClaimBytes: number
711
+ /** Maximum number of acquisitions accepted in one session on this surface. */
712
+ maximumAcquiresPerSession?: number
713
+ }
714
+
715
+ interface KnowledgeFieldSize {
716
+ field: string
717
+ bytes: number
718
+ }
719
+
720
+ interface KnowledgeSize {
721
+ /** Serialized size of the whole knowledge payload. */
722
+ claimBytes: number
723
+ /** Serialized size of every top-level field. */
724
+ fields: KnowledgeFieldSize[]
725
+ }
726
+
727
+ interface AuthorityBindingState {
728
+ readonly format: 'dotmem.authority-binding'
729
+ /** The remembered HI identity. Informational only; never authenticates. */
730
+ readonly knownHIIdentity: string | null
731
+ readonly currentSpeakerBinding: SpeakerBindingState
732
+ /** Derived: BOUND only for a trusted current binding. */
733
+ readonly currentAuthorityBinding: AuthorityStatus
734
+ readonly requestedOperationalRole: string
735
+ readonly authorizationScope: string | null
736
+ /**
737
+ * The HI identity that was bound to the current speaker, populated only by
738
+ * a trusted current binding event (`bindCurrentSpeaker`). Not the remembered
739
+ * identity: an explicit, current, operator-layer assertion.
740
+ */
741
+ readonly boundHIIdentity: string | null
742
+ }
743
+
744
+ interface ResolveAuthorityBindingInput {
745
+ readonly knownHIIdentity?: string | null
746
+ /**
747
+ * The current speaker binding. Supplied ONLY by the trusted current
748
+ * channel (the operator layer): memory, historical continuity, files,
749
+ * retrieved documents and prior-session records can never set this.
750
+ */
751
+ readonly currentSpeakerBinding: SpeakerBindingState
752
+ readonly requestedOperationalRole: string
753
+ readonly authorizationScope?: string | null
754
+ /**
755
+ * The HI identity that was bound to the current speaker, populated only by
756
+ * a trusted current binding event. Never inferred from memory or history.
757
+ */
758
+ readonly boundHIIdentity?: string | null
759
+ }
760
+
761
+ interface RoleActivationRequest {
762
+ readonly requestedRole: string
763
+ /** Historical identity evidence available to the caller. Never authenticates. */
764
+ readonly knownHIIdentity?: string | null
765
+ readonly currentSpeakerBinding: SpeakerBindingState
766
+ /**
767
+ * Whether the request is informational ("can Joy be loaded?") or an
768
+ * explicit current authorization event ("I, the currently trusted HI,
769
+ * authorize Joy activation now"). The two are never equivalent.
770
+ */
771
+ readonly requestKind: 'informational' | 'authorization-event'
772
+ readonly authorizationScope?: string | null
773
+ }
774
+
775
+ interface RoleActivationDecision {
776
+ readonly requestedRole: string
777
+ readonly currentSpeaker: SpeakerBindingState
778
+ readonly currentAuthorityBinding: AuthorityStatus
779
+ readonly authorizationScope: string | null
780
+ readonly activationResult: RoleActivationResult
781
+ readonly reason: string
782
+ }
783
+
784
+ type SpeakerBindingState = 'trusted-hi' | 'unknown' | 'untrusted'
785
+
786
+ type AuthorityStatus = 'BOUND' | 'UNBOUND'
787
+
788
+ type RoleActivationResult = 'ACTIVATED' | 'WITHHELD'
789
+
790
+ interface TrustedRoleMap {
791
+ readonly format: 'dotmem.trusted-role-map'
792
+ readonly contractRevision: string
793
+ readonly values: Readonly<Record<RoleMapField, string>>
794
+ /** Always true: context may not mutate the trusted role map. */
795
+ readonly frozen: true
796
+ }
797
+
798
+ interface BuildTrustedRoleMapInput {
799
+ readonly contractRevision: string
800
+ readonly host: string
801
+ readonly executor: string
802
+ readonly operationalRole: string
803
+ readonly user: string
804
+ readonly hiAuthority: string
805
+ readonly conversationalProfile: string
806
+ }
807
+
808
+ interface RoleTransitionViolation {
809
+ readonly from: RoleMapField
810
+ readonly to: RoleMapField
811
+ readonly assertedValue: string
812
+ readonly trustedEvidence: boolean
813
+ }
814
+
815
+ interface DetectTransitionsInput {
816
+ readonly trusted: TrustedRoleMap
817
+ /** The role map as (re)asserted by the carrier, conversation or runtime. */
818
+ readonly asserted: Partial<Record<RoleMapField, string>>
819
+ /**
820
+ * Whether the assertion is backed by new trusted authority evidence
821
+ * (the privileged governance path). Conversation, tone, memory and tool
822
+ * output never qualify.
823
+ */
824
+ readonly trustedEvidence?: boolean
825
+ }
826
+
827
+ interface AuthorityDriftSignal {
828
+ readonly pattern: AuthorityDriftPattern
829
+ /** The matched structural line, bounded. Never an interpretation. */
830
+ readonly excerpt: string
831
+ }
832
+
833
+ interface DetectAuthorityDriftInput {
834
+ readonly text: string
835
+ /**
836
+ * True when the speaker is exercising the operational role in this output
837
+ * (for example while a dotmem identity projection is active). Required for
838
+ * `denies-own-role`: denying a role you do not hold is not a drift.
839
+ */
840
+ readonly speakingAsOperationalRole?: boolean
841
+ }
842
+
843
+ interface RetrospectiveClaimResult {
844
+ readonly verdict: RetrospectiveVerdict
845
+ readonly claim: string
846
+ readonly matchedEvidence: readonly string[]
847
+ }
848
+
849
+ interface AuthorityIncidentRecord {
850
+ readonly format: 'dotmem.authority-incident'
851
+ readonly incidentType: typeof AUTHORITY_INCIDENT_TYPE
852
+ readonly trustedRoleMapBefore: TrustedRoleMap
853
+ readonly observedTransition: RoleTransitionViolation
854
+ readonly driftSignals: readonly AuthorityDriftSignal[]
855
+ /** Verifiable references (channels, claim ids, timestamps). */
856
+ readonly evidenceReferences: readonly string[]
857
+ /**
858
+ * Exact evidence excerpts, included only when governance permits.
859
+ * Excerpts are quotes of what was actually observed.
860
+ */
861
+ readonly evidenceExcerpts: readonly string[]
862
+ readonly retrospectiveClaim: RetrospectiveClaimResult
863
+ readonly remediationApplied: readonly string[]
864
+ readonly contractRevision: string
865
+ readonly runtimeId: string
866
+ readonly at: string
867
+ }
868
+
869
+ interface BuildAuthorityIncidentInput {
870
+ readonly trustedRoleMapBefore: TrustedRoleMap
871
+ readonly observedTransition: RoleTransitionViolation
872
+ readonly driftSignals?: readonly AuthorityDriftSignal[]
873
+ readonly evidenceReferences?: readonly string[]
874
+ readonly evidenceExcerpts?: readonly string[]
875
+ readonly retrospectiveClaim: RetrospectiveClaimResult
876
+ readonly remediationApplied?: readonly string[]
877
+ readonly runtimeId: string
878
+ /** Injectable for deterministic tests. */
879
+ readonly now?: () => Date
880
+ }
881
+
882
+ interface AuthorityReconciliationInput {
883
+ readonly incidents: readonly AuthorityIncidentRecord[]
884
+ /** The relevant recent interaction window (observed facts, not summaries). */
885
+ readonly recentWindow: readonly string[]
886
+ /** Current runtime state facts. */
887
+ readonly currentRuntime: readonly string[]
888
+ readonly trustedRoleMapRestored: boolean
889
+ readonly handshakeRerun: boolean
890
+ }
891
+
892
+ interface AuthorityReconciliation {
893
+ readonly resolved: boolean
894
+ readonly reason: string
895
+ }
896
+
897
+ interface AuthorityRecoveryResult {
898
+ readonly authorityMutationFrozen: true
899
+ readonly roleMapRestored: TrustedRoleMap
900
+ readonly handshakeInvalidated: true
901
+ readonly handshakeRerunRequired: true
902
+ /** Always true: the trusted agent identity is never adapted to the carrier. */
903
+ readonly agentIdentityUnchanged: true
904
+ readonly steps: readonly string[]
905
+ readonly resumeDecision: 'resume-if-compatible' | 'reject-carrier'
906
+ }
907
+
908
+ interface RunAuthorityRecoveryInput {
909
+ readonly trustedRoleMap: TrustedRoleMap
910
+ readonly incident: AuthorityIncidentRecord
911
+ /** Result of the rerun handshake, when it has already been evaluated. */
912
+ readonly handshakeRerunState?: 'COMPATIBLE' | 'LIMITED' | 'INCOMPATIBLE'
913
+ }
914
+
915
+ type RoleMapField =
916
+ | 'HOST'
917
+ | 'EXECUTOR'
918
+ | 'OPERATIONAL_ROLE'
919
+ | 'USER'
920
+ | 'HI_AUTHORITY'
921
+ | 'CONVERSATIONAL_PROFILE'
922
+
923
+ type AuthorityDriftPattern =
924
+ | 'claims-hi-authority'
925
+ | 'commands-the-hi'
926
+ | 'role-as-other-party'
927
+ | 'denies-own-role'
928
+ | 'retrospective-authority-attribution'
929
+
930
+ type RetrospectiveVerdict = 'SUPPORTED' | 'NO_EVIDENCE'
931
+
932
+ interface BootstrapRulesReference {
933
+ count: number
934
+ signature: string
935
+ ids: string[]
936
+ }
937
+
938
+ interface BootstrapResponse {
939
+ format: 'dotmem-bootstrap-v1'
940
+ storage: string
941
+ knowledgeVersion: number
942
+ rules: BootstrapRulesReference
943
+ /** Null when the store is unchanged since `sinceVersion`. */
944
+ context: ContextProjection | null
945
+ /** True when a supplied `sinceVersion` matched the current knowledge version. */
946
+ unchanged: boolean
947
+ /** Echoed when supplied, so clients can assert the version. */
948
+ sinceVersion?: number
949
+ /** Human-readable rendering of the bootstrap. */
950
+ text: string
951
+ }
952
+
953
+ interface BrainRelationship {
954
+ id: string
955
+ kind: 'uses' | 'related-to' | 'supersedes' | 'encountered-in' | 'associated-with'
956
+ from: string
957
+ to: string
958
+ epistemicType?: 'observed' | 'inferred' | 'human-stated' | 'verified'
959
+ note?: string
960
+ }
961
+
962
+ interface BrainDocument {
963
+ format: typeof BRAIN_FORMAT
964
+ version: typeof BRAIN_VERSION
965
+ relationships: BrainRelationship[]
966
+ }
967
+
968
+ interface BuiltInContextRuleMapping {
969
+ documentId: string
970
+ documentFile: string
971
+ section: string
972
+ rule: string
973
+ enforcement: 'governance-core' | 'guardrails' | 'runtime-boundary' | 'documented-limitation'
974
+ technicallyEnforced: boolean
975
+ limitation?: string
976
+ }
977
+
978
+ interface BuiltInContextRuleIndex {
979
+ rules: BuiltInContextRuleMapping[]
980
+ byDocument: Map<string, BuiltInContextRuleMapping[]>
981
+ byClassification: Map<string, BuiltInContextRuleMapping[]>
982
+ }
983
+
984
+ interface BuiltInContextDocument {
985
+ id: string
986
+ file: string
987
+ path: string
988
+ content: string
989
+ digest: string
990
+ size: number
991
+ classification: BuiltInContextClassification
992
+ }
993
+
994
+ interface BuiltInContextArtifact {
995
+ format: string
996
+ formatVersion: number
997
+ sourceVersion: string
998
+ buildFormatVersion: number
999
+ documents: BuiltInContextDocument[]
1000
+ manifestDigest: string
1001
+ aggregateDigest: string
1002
+ documentCount: number
1003
+ generatedAt: string
1004
+ }
1005
+
1006
+ interface BuiltInContextLoadResult {
1007
+ status: BuiltInContextStatus
1008
+ version?: string
1009
+ sourceVersion?: string
1010
+ manifestDigest?: string
1011
+ aggregateDigest?: string
1012
+ documentCount?: number
1013
+ documents?: Array<{
1014
+ id: string
1015
+ file: string
1016
+ path: string
1017
+ content: string
1018
+ digest: string
1019
+ size: number
1020
+ classification: BuiltInContextClassification
1021
+ }>
1022
+ error?: string
1023
+ }
1024
+
1025
+ type BuiltInContextClassification = 'normative' | 'informational' | 'operational' | 'reference' | 'profile'
1026
+
1027
+ type BuiltInContextStatus = 'available' | 'missing' | 'invalid' | 'unsupported-version' | 'digest-mismatch'
1028
+
1029
+ interface CanonicalIdentityRecord {
1030
+ canonicalIdentity: string
1031
+ projectId: string
1032
+ repositoryIdentity?: string
1033
+ authoritySource: IdentityAuthoritySource
1034
+ decisionTimestamp: string
1035
+ version: number
1036
+ provenance: {
1037
+ source: string
1038
+ detail: string
1039
+ evidence?: string[]
1040
+ }
1041
+ isHistorical: boolean
1042
+ }
1043
+
1044
+ interface IdentityResolutionContext {
1045
+ cwd: string
1046
+ explicitUserDecision?: string
1047
+ projectConfig?: string
1048
+ governance?: boolean
1049
+ historicalClaims?: Array<{ name: string; source: string; timestamp: string }>
1050
+ cache?: Array<{ name: string; source: string; timestamp: string }>
1051
+ summaries?: Array<{ name: string; source: string; timestamp: string }>
1052
+ checkpoints?: Array<{ name: string; source: string; timestamp: string }>
1053
+ }
1054
+
1055
+ type IdentityAuthoritySource =
1056
+ | 'explicit-user-decision'
1057
+ | 'authoritative-project-config'
1058
+ | 'verified-project-metadata'
1059
+ | 'governance'
1060
+ | 'historical-claim'
1061
+ | 'summary'
1062
+ | 'checkpoint'
1063
+ | 'cache'
1064
+ | 'index'
1065
+
1066
+ interface CanonicalReconstructionInput {
1067
+ /** The canonical identity after governance resolution. */
1068
+ canonicalIdentity: string
1069
+ /** The governance document (privileged namespace). */
1070
+ governance: IdentityGovernance
1071
+ /** Policy records from the privileged store. */
1072
+ authorizedPolicy: readonly PolicyRecord[]
1073
+ /** The HI's own explicit identity, when the runtime supplies it. */
1074
+ userIdentity?: string
1075
+ /** Scoped, temporary overlays for this run. Never canonical. */
1076
+ permittedOverlays?: readonly unknown[]
1077
+ /** Injectable clock for deterministic reconstruction. */
1078
+ now?: () => Date
1079
+ }
1080
+
1081
+ interface CanonicalEvidenceViolation {
1082
+ /** Claim identity, used to scope the diagnostic. */
1083
+ claimId: string
1084
+ /** Exact failing path, e.g. `evidence` or `evidence[0]`. */
1085
+ path: string
1086
+ /** What failed, in canonical vocabulary. */
1087
+ problem: string
1088
+ /** The received representation at the failing path. */
1089
+ received: unknown
1090
+ /** How to fix it. */
1091
+ fix: string
1092
+ }
1093
+
1094
+ interface MemoryClassification {
1095
+ kind: MemoryKind
1096
+ }
1097
+
1098
+ interface BudgetUsage {
1099
+ tokens: number
1100
+ characters: number
1101
+ claimCount: number
1102
+ budget: number | 'unlimited'
1103
+ utilization: number
1104
+ }
1105
+
1106
+ interface BudgetExplanation {
1107
+ included: Array<{
1108
+ claimId: string
1109
+ reason: string
1110
+ estimatedTokens: number
1111
+ estimatedCharacters: number
1112
+ }>
1113
+ excluded: Array<{
1114
+ claimId: string
1115
+ reason: string
1116
+ }>
1117
+ total: BudgetUsage
1118
+ }
1119
+
1120
+ interface MemoryProjectionContract {
1121
+ /** Memory is data. It never carries authority. */
1122
+ authority: 'data-only'
1123
+ trusted: false
1124
+ instructionsAllowed: false
1125
+ /** Current reality must be verified before relying on remembered data. */
1126
+ verifyCurrent: true
1127
+ /** Memory use is governed by policy, and policy is owned by HI authority. */
1128
+ policyGoverned: true
1129
+ /** A conversational instruction can never lower a policy tier. */
1130
+ chatCanLowerPolicyTier: false
1131
+ tiers: Record<EnforcementTier, TierEnforcement>
1132
+ overridePath: string
1133
+ }
1134
+
1135
+ interface AcquisitionFieldContract {
1136
+ field: string
1137
+ role: 'caller-supplied' | 'system-assigned' | 'caller-claim-not-attested'
1138
+ note: string
1139
+ }
1140
+
1141
+ interface AcquisitionContract {
1142
+ surface: 'memory.acquire'
1143
+ input: {
1144
+ required: AcquisitionFieldContract[]
1145
+ optional: AcquisitionFieldContract[]
1146
+ ignoredByDesign: AcquisitionFieldContract[]
1147
+ }
1148
+ systemAssigned: AcquisitionFieldContract[]
1149
+ acceptedKinds: readonly string[]
1150
+ acceptedScopes: readonly string[]
1151
+ trust: {
1152
+ callerSupplied: string[]
1153
+ memoraAttests: string[]
1154
+ callerClaimsNotAttested: string[]
1155
+ }
1156
+ relations: {
1157
+ canonical: readonly string[]
1158
+ note: string
1159
+ neverKind: 'relationship'
1160
+ }
1161
+ projection: {
1162
+ fields: string[]
1163
+ note: string
1164
+ }
1165
+ sizeLimits: {
1166
+ note: string
1167
+ library: { maximumFieldBytes: number; maximumClaimBytes: number }
1168
+ mcp: { maximumFieldBytes: number; maximumClaimBytes: number }
1169
+ refusal: string
1170
+ }
1171
+ rejectionShape: {
1172
+ fields: string[]
1173
+ note: string
1174
+ }
1175
+ }
1176
+
1177
+ interface CorrectionDraft {
1178
+ id: string
1179
+ trigger: string
1180
+ mistake: string
1181
+ correction: string
1182
+ createdAt: string
1183
+ claimId: string
1184
+ }
1185
+
1186
+ interface CurrentnessContext {
1187
+ /** Claims removed by an explicit retracts relationship. */
1188
+ retractedIds?: ReadonlySet<string>
1189
+ /** Claims removed by an explicit supersedes relationship. */
1190
+ supersededIds?: ReadonlySet<string>
1191
+ /** Claims that retract each other. */
1192
+ contestedIds?: ReadonlySet<string>
1193
+ /** Clock injection point. Discovery passes Date.now(); tests pass a fixed value. */
1194
+ now?: number
1195
+ }
1196
+
1197
+ interface DetectionAttempt {
1198
+ kind: DetectionEventKind
1199
+ domain: string
1200
+ provenance: string
1201
+ detail: string
1202
+ /** Injectable clock for deterministic tests. */
1203
+ now?: () => Date
1204
+ }
1205
+
1206
+ interface DetectionJournalDocument {
1207
+ format: 'dotmem.detection-journal'
1208
+ version: 1
1209
+ events: DetectionEvent[]
1210
+ }
1211
+
1212
+ interface RankedCandidate extends DiscoveryCandidate {
1213
+ directPhrase: boolean
1214
+ matchedTermCount: number
1215
+ fieldWeight: number
1216
+ acquiredTime: number
1217
+ }
1218
+
1219
+ interface BehavioralInvariant {
1220
+ id: string
1221
+ statement: string
1222
+ /** Always false: context may not make an invariant mutable. */
1223
+ mutableThroughContext: false
1224
+ }
1225
+
1226
+ interface OverlayProvenance {
1227
+ kind: 'HI' | 'operator' | 'runtime'
1228
+ source: string
1229
+ }
1230
+
1231
+ interface ContractOverlay {
1232
+ id: string
1233
+ kind: OverlayKind
1234
+ /** Where the overlay applies. Required: an unscoped overlay is refused. */
1235
+ scope: string
1236
+ /** Always true: an overlay is temporary and revocable. */
1237
+ temporary: true
1238
+ /** Who granted the overlay. Required: an unattributed overlay is refused. */
1239
+ provenance: OverlayProvenance
1240
+ /** Behavior descriptor. Data only; no identity, no invariant, no authority. */
1241
+ descriptor: string
1242
+ }
1243
+
1244
+ interface CanonicalAgentContract {
1245
+ canonicalIdentity: string
1246
+ behavioralInvariants: readonly BehavioralInvariant[]
1247
+ }
1248
+
1249
+ interface EffectiveAgentContract {
1250
+ canonical: CanonicalAgentContract
1251
+ /** Authorized policy that may shape behavior inside the envelope. */
1252
+ authorizedPolicy: readonly PolicyRecord[]
1253
+ /** Permitted scoped overlays (roles, style, task modes). */
1254
+ permittedOverlays: readonly ContractOverlay[]
1255
+ /** The HI's own explicit identity. A separate channel, never from memory. */
1256
+ userIdentity?: string
1257
+ constructedAt: string
1258
+ }
1259
+
1260
+ interface ConstructEffectiveAgentContractInput {
1261
+ canonicalIdentity: string
1262
+ behavioralInvariants?: readonly BehavioralInvariant[]
1263
+ authorizedPolicy?: readonly PolicyRecord[]
1264
+ permittedOverlays?: readonly ContractOverlay[]
1265
+ userIdentity?: string
1266
+ /** Injectable for deterministic tests. */
1267
+ now?: () => Date
1268
+ }
1269
+
1270
+ type OverlayKind = 'role' | 'style' | 'task-mode'
1271
+
1272
+ interface ExemplarSource {
1273
+ readonly conversationId: string
1274
+ readonly messageIds: readonly string[]
1275
+ readonly timestamp?: string
1276
+ }
1277
+
1278
+ interface ExemplarData {
1279
+ id: string
1280
+ type: 'interaction-exemplar'
1281
+ source: ExemplarSource
1282
+ pattern: string
1283
+ originalContent: string | null
1284
+ sourceReference: string | null
1285
+ retrievalHints: string[]
1286
+ significance: number
1287
+ confidence: number
1288
+ provenance: ExemplarProvenance
1289
+ createdAt: string
1290
+ revision: number
1291
+ }
1292
+
1293
+ interface ExemplarStore {
1294
+ version: number
1295
+ exemplars: Record<string, ExemplarData>
1296
+ }
1297
+
1298
+ interface ExemplarSearchOptions {
1299
+ queryTerms?: readonly string[]
1300
+ maxResults?: number
1301
+ minSignificance?: number
1302
+ requiredProvenance?: ExemplarProvenance
1303
+ }
1304
+
1305
+ type ExemplarProvenance = 'human-stated' | 'observed' | 'inferred'
1306
+
1307
+ interface FeedbackEntry {
1308
+ claimId: string
1309
+ kind: FeedbackKind
1310
+ note?: string
1311
+ recordedAt: string
1312
+ }
1313
+
1314
+ interface FeedbackDocument {
1315
+ version: number
1316
+ entries: FeedbackEntry[]
1317
+ }
1318
+
1319
+ type FeedbackKind = 'helped' | 'misled' | 'ignored'
1320
+
1321
+ interface ProjectableClaim {
1322
+ id: string
1323
+ knowledge: unknown
1324
+ epistemicType?: string
1325
+ scope?: 'user' | 'project'
1326
+ }
1327
+
1328
+ interface PreHandshakeContract {
1329
+ readonly format: 'dotmem.pre-handshake-contract'
1330
+ readonly handshakeVersion: number
1331
+ readonly contractRevision: string
1332
+ readonly upstreamHostAuthority: 'preserved'
1333
+ readonly executor: 'current runtime/model instance'
1334
+ readonly requestedOperationalRole: string
1335
+ readonly memoryAuthority: false
1336
+ readonly profileMayOverrideHost: false
1337
+ readonly hiAuthority: string
1338
+ /** The remembered HI identity. Informational; never authenticates. */
1339
+ readonly knownHIIdentity: string | null
1340
+ readonly currentSpeakerBinding: SpeakerBindingState
1341
+ /** Derived: BOUND only for a trusted current binding. */
1342
+ readonly currentAuthorityBinding: 'BOUND' | 'UNBOUND'
1343
+ readonly constructedAt: string
1344
+ }
1345
+
1346
+ interface BuildPreHandshakeContractInput {
1347
+ readonly contractRevision: string
1348
+ readonly requestedOperationalRole: string
1349
+ readonly hiAuthority: string
1350
+ /** The remembered HI identity, when trusted state declares one. */
1351
+ readonly knownHIIdentity?: string | null
1352
+ /** Supplied only by the trusted current channel (the operator layer). */
1353
+ readonly currentSpeakerBinding: SpeakerBindingState
1354
+ readonly authorizationScope?: string | null
1355
+ /** Injectable for deterministic tests. */
1356
+ readonly now?: () => Date
1357
+ }
1358
+
1359
+ interface CarrierRoleMapping {
1360
+ readonly executor: RoleMappingValue
1361
+ readonly operationalRole: RoleMappingValue
1362
+ readonly hiAuthority: RoleMappingValue
1363
+ readonly hostAuthoritySeparation: RoleMappingValue
1364
+ readonly memoryAsData: RoleMappingValue
1365
+ readonly profileHostCoexistence: RoleMappingValue
1366
+ }
1367
+
1368
+ interface HandshakeEvaluation {
1369
+ readonly state: CompatibilityState
1370
+ readonly capabilities: Readonly<Record<HandshakeCapability, boolean>>
1371
+ readonly mapping: CarrierRoleMapping
1372
+ readonly reasons: readonly string[]
1373
+ }
1374
+
1375
+ interface EvaluateCarrierInput {
1376
+ readonly contract: PreHandshakeContract
1377
+ readonly response: string
1378
+ }
1379
+
1380
+ interface ContractRevisionInput {
1381
+ readonly profileId: string
1382
+ readonly profileVersion: number
1383
+ readonly canonicalAgentName: string
1384
+ readonly rename: string
1385
+ readonly behavioralInvariantIds: readonly string[]
1386
+ readonly authorizedPolicyCount: number
1387
+ }
1388
+
1389
+ interface HandshakeSessionRecord {
1390
+ readonly format: 'dotmem.handshake-session'
1391
+ /** Always false: this record is session state, not a durable authority. */
1392
+ readonly durableAuthority: false
1393
+ readonly handshakeVersion: number
1394
+ readonly contractRevision: string
1395
+ readonly runtimeId: string
1396
+ readonly state: CompatibilityState
1397
+ readonly capabilities: Readonly<Record<HandshakeCapability, boolean>>
1398
+ readonly evaluator: 'dotmem-deterministic-external'
1399
+ readonly evaluatedAt: string
1400
+ /**
1401
+ * The current authority binding at evaluation time. A separate event from
1402
+ * the carrier evaluation: compatibility never binds authority, and a
1403
+ * binding never certifies a carrier.
1404
+ */
1405
+ readonly authorityBinding: AuthorityBindingState
1406
+ }
1407
+
1408
+ interface RuntimeFingerprintInput {
1409
+ readonly platform: string
1410
+ readonly arch: string
1411
+ readonly nodeMajor: number
1412
+ readonly storageRoot: string
1413
+ }
1414
+
1415
+ interface HandshakeValidityInput {
1416
+ readonly record: HandshakeSessionRecord
1417
+ readonly contractRevision: string
1418
+ readonly runtimeId: string
1419
+ readonly handshakeVersion?: number
1420
+ }
1421
+
1422
+ interface HandshakeValidity {
1423
+ readonly usable: boolean
1424
+ readonly reason: string
1425
+ }
1426
+
1427
+ interface BuildHandshakeSessionRecordInput {
1428
+ readonly evaluation: HandshakeEvaluation
1429
+ readonly contractRevision: string
1430
+ readonly runtimeId: string
1431
+ readonly authorityBinding: AuthorityBindingState
1432
+ /** Injectable for deterministic tests. */
1433
+ readonly now?: () => Date
1434
+ }
1435
+
1436
+ type CompatibilityState = 'COMPATIBLE' | 'LIMITED' | 'INCOMPATIBLE'
1437
+
1438
+ type HandshakeCapability =
1439
+ | 'identityComposition'
1440
+ | 'rolePreservation'
1441
+ | 'authorityPreservation'
1442
+ | 'memoryAsData'
1443
+ | 'hostAuthoritySeparation'
1444
+ | 'profileHostCoexistence'
1445
+
1446
+ type RoleMappingValue = 'preserved' | 'violated' | 'refused' | 'unclear'
1447
+
1448
+ interface HardRule {
1449
+ id: string
1450
+ version: number
1451
+ revision: number
1452
+ ruleClass: HardRuleClass
1453
+ status: HardRuleStatus
1454
+ scope: string
1455
+ statement: string
1456
+ applicability?: Record<string, unknown>
1457
+ authority: PolicyAuthority
1458
+ grantedAt: string
1459
+ createdAt: string
1460
+ updatedAt?: string
1461
+ fingerprint: string
1462
+ provenance?: Record<string, unknown>
1463
+ auditRef?: string
1464
+ }
1465
+
1466
+ interface HardRulesRegistryDocument {
1467
+ format: typeof HARD_RULES_REGISTRY_FORMAT
1468
+ version: number
1469
+ revision: number
1470
+ rules: HardRule[]
1471
+ audit: HardRulesAuditEntry[]
1472
+ }
1473
+
1474
+ interface HardRulesAuditEntry {
1475
+ id: string
1476
+ action: string
1477
+ at: string
1478
+ actorPrincipal?: string
1479
+ targetRuleId?: string
1480
+ targetVersion?: number
1481
+ scope?: string
1482
+ outcome: 'applied' | 'rejected'
1483
+ reason?: string
1484
+ detail?: string
1485
+ mandatory?: boolean
1486
+ }
1487
+
1488
+ type HardRuleClass = 'IMMUTABLE' | 'OWNER_CONTROLLED' | 'USER_OVERRIDEABLE' | 'SESSION'
1489
+
1490
+ type HardRuleStatus = 'proposed' | 'under_review' | 'approved' | 'active' | 'suspended' | 'retired' | 'rejected'
1491
+
1492
+ interface CacheEntry {
1493
+ id: string
1494
+ key: string
1495
+ value: unknown
1496
+ identity: string
1497
+ identityVersion: number
1498
+ source: 'cache' | 'index' | 'summary' | 'checkpoint'
1499
+ createdAt: string
1500
+ lastAccessed: string
1501
+ valid: boolean
1502
+ }
1503
+
1504
+ interface TrustedIdentityRender {
1505
+ text: string
1506
+ contract: EffectiveAgentContract
1507
+ profile: DotMemProfile | null
1508
+ }
1509
+
1510
+ interface TrustedIdentityAuthorityBinding {
1511
+ /** The remembered HI identity. Informational; never authenticates. */
1512
+ readonly knownHIIdentity: string | null
1513
+ /** The current speaker binding, from the trusted current channel only. */
1514
+ readonly currentSpeakerBinding: SpeakerBindingState
1515
+ }
1516
+
1517
+ interface IdentityFusionSignal {
1518
+ readonly kind: IdentityFusionKind
1519
+ /** The fused form that was observed. */
1520
+ readonly fused: string
1521
+ /** The canonical identity the fused form tried to redefine. */
1522
+ readonly canonical: string
1523
+ /** The matched structural fragment, bounded. */
1524
+ readonly excerpt: string
1525
+ }
1526
+
1527
+ interface DetectIdentityFusionInput {
1528
+ /** The canonical identity, when known. */
1529
+ readonly canonicalIdentity?: string
1530
+ /** The candidate identity string to inspect. */
1531
+ readonly candidate: string
1532
+ }
1533
+
1534
+ interface PreserveCanonicalIdentityInput {
1535
+ readonly canonicalIdentity: string
1536
+ readonly candidate: string
1537
+ }
1538
+
1539
+ interface IdentityAndRuntime {
1540
+ /** The human-readable identity. Stable across environments and models. */
1541
+ readonly name: string
1542
+ /** The runtime environment, reported separately. Never part of the name. */
1543
+ readonly environment: string | null
1544
+ /** The current model, reported separately. Never part of the name. */
1545
+ readonly model: string | null
1546
+ }
1547
+
1548
+ type IdentityFusionKind =
1549
+ | 'identity+environment'
1550
+ | 'identity+model'
1551
+ | 'identity+authority-label'
1552
+ | 'identity+role-metadata'
1553
+
1554
+ interface IdentityGovernance {
1555
+ format: 'dotmem.identity-governance'
1556
+ version: 1
1557
+ /** The canonical agent name. A differing runtime assignment is a rename. */
1558
+ canonicalAgentName: string
1559
+ /** Whether renames of the canonical name are permitted at runtime. */
1560
+ rename: IdentityRenamePermission
1561
+ /**
1562
+ * Governance-declared behavioral invariant additions. The canonical floor
1563
+ * (CANONICAL_BEHAVIORAL_INVARIANTS) is always present and cannot be
1564
+ * weakened or removed; these entries only extend it.
1565
+ */
1566
+ behavioralInvariants: readonly BehavioralInvariant[]
1567
+ authority: PolicyAuthority
1568
+ updatedAt: string
1569
+ }
1570
+
1571
+ interface IdentityGovernanceInput {
1572
+ canonicalAgentName?: string
1573
+ rename?: IdentityRenamePermission
1574
+ }
1575
+
1576
+ interface SetIdentityGovernanceInput extends IdentityGovernanceInput {
1577
+ authority: PolicyAuthority
1578
+ behavioralInvariants?: readonly BehavioralInvariant[]
1579
+ }
1580
+
1581
+ interface RenameAdmissibility {
1582
+ /** Whether the requested name may be used. */
1583
+ permitted: boolean
1584
+ /** Human-readable reason reflecting the governance decision actually made. */
1585
+ reason: string
1586
+ governance: IdentityGovernance
1587
+ }
1588
+
1589
+ type IdentityRenamePermission = 'DENY' | 'PERMIT'
1590
+
1591
+ interface IdentityCandidate {
1592
+ source: IdentityCandidateSource
1593
+ /** The name this candidate asserts. */
1594
+ name: string
1595
+ /**
1596
+ * Who authored the content that carried this candidate. Relayed content
1597
+ * (authored by someone other than the HI) is data, never an assignment.
1598
+ */
1599
+ authoredBy?: 'HI' | 'OTHER'
1600
+ /** True when the candidate claims HI authorship or authority of itself. */
1601
+ selfPromoted?: boolean
1602
+ }
1603
+
1604
+ interface ResolvedIdentityCandidate extends IdentityCandidate {
1605
+ disposition: IdentityDisposition
1606
+ }
1607
+
1608
+ interface IdentityResolution {
1609
+ /** The active name, or null when nothing authoritative exists. */
1610
+ effective: string | null
1611
+ /** Which source the active name came from. */
1612
+ source: IdentityCandidateSource | null
1613
+ disposition: IdentityDisposition
1614
+ /** Human-readable reasons reflecting the facts actually evaluated. */
1615
+ reasons: string[]
1616
+ /** Every candidate with its disposition, so nothing disappears silently. */
1617
+ candidates: ResolvedIdentityCandidate[]
1618
+ }
1619
+
1620
+ interface IdentityResolutionInput {
1621
+ /** Explicit current HI assignment, when the HI made one in this interaction. */
1622
+ hiAssignment?: IdentityCandidate | null
1623
+ /** Profile candidates. When omitted, the built-in profile supplies them. */
1624
+ profile?: readonly IdentityCandidate[] | null
1625
+ /** Durable memory / historical session evidence. */
1626
+ memory?: readonly IdentityCandidate[]
1627
+ /** Retrieved files, quoted text, third-party content, relayed messages. */
1628
+ retrievedText?: readonly IdentityCandidate[]
1629
+ }
1630
+
1631
+ type IdentityCandidateSource =
1632
+ | 'HI_ASSIGNMENT'
1633
+ | 'PROFILE'
1634
+ | 'MEMORY'
1635
+ | 'RETRIEVED_TEXT'
1636
+
1637
+ type IdentityDisposition =
1638
+ | 'SELECTED'
1639
+ | 'SHADOWED'
1640
+ | 'HISTORICAL'
1641
+ | 'UNTRUSTED_DATA'
1642
+ | 'SELF_PROMOTED'
1643
+ | 'CONFLICT'
1644
+ | 'UNRESOLVED'
1645
+
1646
+ interface IncidentCase {
1647
+ id: string
1648
+ situation: string
1649
+ expectedClaimIds: string[]
1650
+ excludedIds: string[]
1651
+ description: string
1652
+ }
1653
+
1654
+ interface IncidentResult {
1655
+ incidentId: string
1656
+ passed: boolean
1657
+ expected: string[]
1658
+ got: string[]
1659
+ missing: string[]
1660
+ unexpected: string[]
1661
+ }
1662
+
1663
+ interface IncidentEvalReport {
1664
+ total: number
1665
+ passed: number
1666
+ failed: number
1667
+ results: IncidentResult[]
1668
+ }
1669
+
1670
+ interface InspectReportOptions {
1671
+ /** Redact secret-shaped values in the knowledge payload. Default true. */
1672
+ redact?: boolean
1673
+ /** Include the full (redacted) knowledge payload in the JSON report. Default false. */
1674
+ includeKnowledge?: boolean
1675
+ /** Max claims to list in the report. Default 50. */
1676
+ limit?: number
1677
+ /** Claims offset. Default 0. */
1678
+ offset?: number
1679
+ }
1680
+
1681
+ interface InspectReport {
1682
+ markdown: string
1683
+ json: unknown
1684
+ }
1685
+
1686
+ interface LanguageDetection {
1687
+ language: DetectedLanguage
1688
+ englishScore: number
1689
+ detail: string
1690
+ }
1691
+
1692
+ type DetectedLanguage = 'en' | 'neutral' | 'und'
1693
+
1694
+ interface LogicSeedClaim {
1695
+ id: string
1696
+ knowledge: JsonValue
1697
+ applicability: Record<string, string>
1698
+ evidence: { id: string; source: string; observedAt: string }[]
1699
+ epistemicType?: 'inferred'
1700
+ provenance?: { source: string; detail: string }
1701
+ }
1702
+
1703
+ interface OpenLoop {
1704
+ id: string
1705
+ text: string
1706
+ waitor: string
1707
+ openedAt: string
1708
+ closedAt?: string
1709
+ closedBy?: string
1710
+ closeNote?: string
1711
+ }
1712
+
1713
+ interface LoopStoreDocument {
1714
+ version: number
1715
+ loops: Record<string, OpenLoop>
1716
+ }
1717
+
1718
+ interface LoopAddInput {
1719
+ id: string
1720
+ text: string
1721
+ waitor: string
1722
+ openedAt?: string
1723
+ }
1724
+
1725
+ interface LoopCloseInput {
1726
+ by: string
1727
+ note?: string
1728
+ closedAt?: string
1729
+ }
1730
+
1731
+ interface MemInterpretationMap {
1732
+ [semantic: string]: JsonValue
1733
+ state: string[]
1734
+ claim: string[]
1735
+ evidence: string[]
1736
+ provenance: string[]
1737
+ revision: string[]
1738
+ epistemicType: string[]
1739
+ revisionKind: string[]
1740
+ }
1741
+
1742
+ interface MemKnowledgeFileV1 {
1743
+ format: typeof MEM_FORMAT
1744
+ version: typeof MEM_FORMAT_VERSION_V1
1745
+ knowledge: KnowledgeState
1746
+ }
1747
+
1748
+ interface MemKnowledgeFileV2 {
1749
+ format: typeof MEM_FORMAT
1750
+ version: typeof MEM_FORMAT_VERSION
1751
+ map: MemInterpretationMap
1752
+ data: EncodedRecord
1753
+ }
1754
+
1755
+ interface PreservedMemV2 {
1756
+ map: MemInterpretationMap
1757
+ data: EncodedRecord
1758
+ }
1759
+
1760
+ interface DecodedMemFile {
1761
+ state: KnowledgeState
1762
+ preserved?: PreservedMemV2
1763
+ }
1764
+
1765
+ type RecordMapName = 'state' | 'claim' | 'evidence' | 'provenance' | 'revision'
1766
+
1767
+ type EncodedRecord = JsonValue[]
1768
+
1769
+ type MemKnowledgeFile = MemKnowledgeFileV1 | MemKnowledgeFileV2
1770
+
1771
+ interface MemPackageManifest {
1772
+ [key: string]: JsonValue | undefined
1773
+ format: typeof MEM_PACKAGE_FORMAT
1774
+ version: typeof MEM_PACKAGE_VERSION
1775
+ memory: { format: typeof MEM_FORMAT; version: typeof MEM_FORMAT_VERSION }
1776
+ parts: { map: typeof MAP_PATH; data: typeof DATA_PATH; integrity: typeof INTEGRITY_PATH }
1777
+ projectId?: string
1778
+ authenticity?: { signed: true }
1779
+ }
1780
+
1781
+ interface MemIntegrity {
1782
+ algorithm: 'sha256'
1783
+ files: Record<string, string>
1784
+ contentId: string
1785
+ }
1786
+
1787
+ interface MemSignatureDocument {
1788
+ format: 'dotmem.signature'
1789
+ version: 1
1790
+ algorithm: 'Ed25519'
1791
+ contentId: string
1792
+ keyId: string
1793
+ publicKey: { format: 'raw'; encoding: 'base64url'; value: string }
1794
+ signature: { encoding: 'base64url'; value: string }
1795
+ }
1796
+
1797
+ interface PreservedMemPackage {
1798
+ manifest: MemPackageManifest
1799
+ extensions: Record<string, Uint8Array>
1800
+ signatures?: Record<string, Uint8Array>
1801
+ }
1802
+
1803
+ interface DecodedMemArtifact extends DecodedMemFile {
1804
+ representation: 'json-v1' | 'json-v2' | 'package-v1'
1805
+ package?: PreservedMemPackage
1806
+ }
1807
+
1808
+ interface MemInspection {
1809
+ status: MemInspectionStatus
1810
+ representation: DecodedMemArtifact['representation'] | 'unknown'
1811
+ message: string
1812
+ packageVersion?: number
1813
+ memoryVersion?: number
1814
+ contentId?: string
1815
+ parts: Array<{ path: string; bytes: number; protected: boolean }>
1816
+ knowledge?: KnowledgeState
1817
+ unknownSemantics?: { mapEntries: number; vocabularyEntries: number; extensionParts: string[] }
1818
+ integrity?: { status: 'valid'; algorithm: 'sha256'; contentId: string }
1819
+ authenticity?: {
1820
+ status: 'unsigned' | 'valid' | 'invalid' | 'unsupported'
1821
+ trust: 'not_evaluated'
1822
+ signatures: Array<{
1823
+ status: 'valid' | 'invalid' | 'unsupported'
1824
+ algorithm?: string
1825
+ keyId?: string
1826
+ contentId?: string
1827
+ message: string
1828
+ }>
1829
+ }
1830
+ }
1831
+
1832
+ type MemInspectionStatus = 'valid' | 'invalid' | 'checksum_mismatch' | 'unsupported' | 'corrupt'
1833
+
1834
+ interface MemSourceProvenance {
1835
+ claimId: string
1836
+ sourceId: string
1837
+ filePath: string
1838
+ }
1839
+
1840
+ interface LoadedSource {
1841
+ id: string
1842
+ filePath: string
1843
+ state: KnowledgeState
1844
+ preserved?: PreservedMemV2
1845
+ package?: PreservedMemPackage
1846
+ }
1847
+
1848
+ interface ResolveSource {
1849
+ id: string
1850
+ scope?: string
1851
+ }
1852
+
1853
+ type ResolveDuplicateResult = 'existing' | 'current'
1854
+
1855
+ interface NoteKnowledge {
1856
+ title: string
1857
+ content: string
1858
+ sha256: string
1859
+ size: number
1860
+ origin: string
1861
+ tag?: string
1862
+ }
1863
+
1864
+ interface Note {
1865
+ id: string
1866
+ title: string
1867
+ content: string
1868
+ sha256: string
1869
+ size: number
1870
+ origin: string
1871
+ tag?: string
1872
+ scope: 'user' | 'project'
1873
+ acquiredAt?: string
1874
+ epistemicType?: 'observed' | 'inferred' | 'human-stated' | 'verified'
1875
+ provenance?: { source: string; detail?: string }
1876
+ revision?: { kind: 'refines' | 'supersedes' | 'retracts'; claimIds: string[]; reason?: string }
1877
+ }
1878
+
1879
+ interface CommunicationStyle {
1880
+ readonly description: string
1881
+ readonly confidence: 'inferred' | 'observed' | 'human-stated'
1882
+ readonly evidence: string[]
1883
+ readonly lastObserved: string
1884
+ }
1885
+
1886
+ interface DurablePreference {
1887
+ readonly id: string
1888
+ readonly statement: string
1889
+ readonly confidence: 'inferred' | 'observed' | 'human-stated'
1890
+ readonly evidence: string[]
1891
+ readonly firstObserved: string
1892
+ readonly lastConfirmed: string
1893
+ readonly supersededBy?: string
1894
+ }
1895
+
1896
+ interface InteractionBoundary {
1897
+ readonly id: string
1898
+ readonly rule: string
1899
+ readonly confidence: 'inferred' | 'observed' | 'human-stated'
1900
+ readonly evidence: string[]
1901
+ readonly source: 'profile' | 'memory' | 'conversation'
1902
+ readonly lastConfirmed: string
1903
+ }
1904
+
1905
+ interface PersonalityAnchor {
1906
+ readonly version: number
1907
+ readonly identity: {
1908
+ readonly communicationStyle: CommunicationStyle[]
1909
+ readonly durablePreferences: DurablePreference[]
1910
+ readonly interactionBoundaries: InteractionBoundary[]
1911
+ }
1912
+ readonly metadata: {
1913
+ readonly createdAt: string
1914
+ readonly updatedAt: string
1915
+ readonly revision: number
1916
+ readonly sourceReferences: string[]
1917
+ }
1918
+ }
1919
+
1920
+ interface PersonalityAnchorUpdate {
1921
+ communicationStyle?: CommunicationStyle[]
1922
+ durablePreferences?: DurablePreference[]
1923
+ interactionBoundaries?: InteractionBoundary[]
1924
+ sourceReferences?: string[]
1925
+ }
1926
+
1927
+ interface AnchorBudget {
1928
+ reserved: number
1929
+ allocated: number
1930
+ remaining: number
1931
+ }
1932
+
1933
+ interface PolicyLockOwner {
1934
+ pid: number
1935
+ host: string
1936
+ acquiredAt: string
1937
+ token: string
1938
+ }
1939
+
1940
+ interface PolicyLockBreak {
1941
+ at: string
1942
+ /** The stale owner whose lock was removed. */
1943
+ brokenOwner: PolicyLockOwner
1944
+ /** The process that broke it. */
1945
+ brokenBy: PolicyLockOwner
1946
+ }
1947
+
1948
+ interface PolicyLockOptions {
1949
+ /** Namespace directory the lock guards. Defaults to the user policy dir. */
1950
+ directory?: string
1951
+ /** Called when a stale lock is broken, before the operation runs. */
1952
+ onLockBreak?: (lockBreak: PolicyLockBreak) => void
1953
+ }
1954
+
1955
+ interface PolicyLockSession {
1956
+ /**
1957
+ * Fail-closed ownership re-check.
1958
+ *
1959
+ * Call immediately before the atomic document write: if the lock was
1960
+ * broken and re-created by another process, the mutation is refused
1961
+ * instead of committed under a lock we no longer hold. This is the
1962
+ * complementary guarantee to the token-safe break — together they ensure
1963
+ * that no policy change is ever committed while the lock identity is not
1964
+ * ours.
1965
+ */
1966
+ assertOwnership: () => Promise<void>
1967
+ }
1968
+
1969
+ interface PolicyDocument {
1970
+ format: typeof POLICY_DOCUMENT_FORMAT
1971
+ version: number
1972
+ /** Monotonic mutation counter: the optimistic concurrency basis. */
1973
+ revision: number
1974
+ records: PolicyRecord[]
1975
+ overrides: PolicyOverride[]
1976
+ audit: PolicyAuditEntry[]
1977
+ }
1978
+
1979
+ interface PolicyAssignmentInput {
1980
+ id?: string
1981
+ event: string
1982
+ claimId: string
1983
+ tier: EnforcementTier
1984
+ field?: string
1985
+ value?: string
1986
+ condition?: { kind: ConditionKind; field: string; value: string }
1987
+ authority: PolicyAuthority
1988
+ grantedAt?: string
1989
+ reason?: string
1990
+ /** Optimistic concurrency check, evaluated inside the lock. */
1991
+ basedOnRevision?: number
1992
+ }
1993
+
1994
+ interface MutationOutcome<T> {
1995
+ document: PolicyDocument
1996
+ result: T
1997
+ }
1998
+
1999
+ type PolicyNamespace = (typeof POLICY_NAMESPACES)[number]
2000
+
2001
+ interface PolicyAuthority {
2002
+ kind: PolicyAuthorityKind
2003
+ /** Explicit provenance of the grant. Required, never inferred. */
2004
+ source: string
2005
+ detail?: string
2006
+ }
2007
+
2008
+ interface PolicyRecord {
2009
+ id: string
2010
+ /** Canonical event this policy applies to, e.g. `artifact.write`. */
2011
+ event: string
2012
+ /** Memory claim this policy governs. The claim never selects its own tier. */
2013
+ claimId: string
2014
+ tier: EnforcementTier
2015
+ /** Optional constrained field of the policy condition. */
2016
+ field?: string
2017
+ /** Expected value of the policy condition. */
2018
+ value?: string
2019
+ /**
2020
+ * Optional condition evaluated against the action payload at decision time.
2021
+ *
2022
+ * A tier without a condition is a presence gate: the policy itself blocks.
2023
+ * A tier with a condition is enforced against the payload: the tier decides
2024
+ * what a violation costs, the condition decides whether there is one.
2025
+ */
2026
+ condition?: PolicyCondition
2027
+ authority: PolicyAuthority
2028
+ grantedAt: string
2029
+ reason?: string
2030
+ /**
2031
+ * Monotonic generation counter of this record. Bumped on every
2032
+ * assign of this id, and never reused after removal and same-id
2033
+ * recreation: an override bound to an old generation cannot resurrect.
2034
+ */
2035
+ revision?: number
2036
+ /**
2037
+ * Canonical semantic fingerprint of this record's content, computed by the
2038
+ * system and verified on load. A policy whose content changed is stale for
2039
+ * every override that captured the previous fingerprint.
2040
+ */
2041
+ fingerprint?: string
2042
+ }
2043
+
2044
+ interface PolicyCondition {
2045
+ kind: ConditionKind
2046
+ field: string
2047
+ value: string
2048
+ }
2049
+
2050
+ interface TierEnforcement {
2051
+ /** Whether the tier can block the action it governs. */
2052
+ blocks: boolean
2053
+ /** Whether satisfying it requires explicit human resolution. */
2054
+ requiresHumanResolution: boolean
2055
+ /** Whether a conversational instruction can lower this tier. */
2056
+ conversationCanOverride: boolean
2057
+ }
2058
+
2059
+ interface PolicyDecision {
2060
+ policyId: string
2061
+ claimId: string
2062
+ event: string
2063
+ tier: EnforcementTier
2064
+ action: PolicyAction
2065
+ blocks: boolean
2066
+ requiresHumanResolution: boolean
2067
+ conversationCanOverride: boolean
2068
+ authority: PolicyAuthority
2069
+ field?: string
2070
+ value?: string
2071
+ condition?: { kind: ConditionKind; field: string; value: string; outcome: ConditionOutcome; detail: string }
2072
+ conditionSatisfied?: boolean
2073
+ grantedAt: string
2074
+ /** The governed memory claim, when present in the evaluated store. */
2075
+ claim?: unknown
2076
+ /**
2077
+ * Effective-state provenance. Present only when a privileged
2078
+ * override targets this record; ordinary resolution is unchanged.
2079
+ */
2080
+ override?: PolicyDecisionOverride
2081
+ }
2082
+
2083
+ interface PolicyEvaluation {
2084
+ event: string
2085
+ decisions: PolicyDecision[]
2086
+ blocked: boolean
2087
+ }
2088
+
2089
+ interface EvaluatePoliciesInput {
2090
+ event: string
2091
+ claims?: readonly AcquiredClaim[]
2092
+ policies: readonly PolicyRecord[]
2093
+ /**
2094
+ * Privileged overrides resolved from the policy store. Present
2095
+ * only when the caller supplies the store's own override set: the base
2096
+ * decision is computed first, and an ACTIVE override re-expresses it with
2097
+ * its provenance attached. With no overrides, resolution is unchanged.
2098
+ */
2099
+ overrides?: readonly PolicyOverride[]
2100
+ /** Injectable clock for deterministic expiry resolution. */
2101
+ now?: () => Date
2102
+ /**
2103
+ * The action payload the event is about to perform, used to evaluate
2104
+ * policy conditions (for example the knowledge about to be acquired).
2105
+ * Without a payload, a conditioned policy stays unresolved and the tier
2106
+ * still blocks: never silently satisfied.
2107
+ */
2108
+ payload?: JsonValue
2109
+ }
2110
+
2111
+ interface ConditionEvaluation {
2112
+ outcome: ConditionOutcome
2113
+ detail: string
2114
+ }
2115
+
2116
+ interface PolicyOverride {
2117
+ id: string
2118
+ event: string
2119
+ /** The policy this override targets. Exactly one active slot per target. */
2120
+ targetPolicyId: string
2121
+ /** Revision of the target policy captured at grant time. */
2122
+ targetRevision: number
2123
+ /** Canonical semantic fingerprint of the target policy captured at grant time. */
2124
+ targetFingerprint: string
2125
+ relaxTo: OverrideRelaxTo
2126
+ authority: PolicyAuthority
2127
+ grantedAt: string
2128
+ expiresAt: string
2129
+ reason: string
2130
+ revokedAt?: string
2131
+ supersededBy?: string
2132
+ }
2133
+
2134
+ interface PolicyAuditEntry {
2135
+ id: string
2136
+ action: PolicyAuditAction
2137
+ at: string
2138
+ authority: PolicyAuditAuthority
2139
+ target?: string
2140
+ reason?: string
2141
+ outcome: 'applied' | 'rejected'
2142
+ detail?: string
2143
+ mandatory?: boolean
2144
+ }
2145
+
2146
+ interface ResolvedOverride {
2147
+ override: PolicyOverride
2148
+ state: Exclude<PolicyOverrideState, 'NONE'>
2149
+ detail: PolicyOverrideInertDetail
2150
+ }
2151
+
2152
+ interface PolicyOverrideProvenance {
2153
+ policyOverrideId: string
2154
+ relaxedFrom: EnforcementTier
2155
+ by: string
2156
+ until: string
2157
+ reason: string
2158
+ }
2159
+
2160
+ interface PolicyDecisionOverride {
2161
+ policyOverrideId: string
2162
+ state: Exclude<PolicyOverrideState, 'NONE'>
2163
+ detail: PolicyOverrideInertDetail
2164
+ relaxedFrom?: EnforcementTier
2165
+ by?: string
2166
+ until?: string
2167
+ reason?: string
2168
+ }
2169
+
2170
+ interface EffectivePolicyState {
2171
+ policyId: string
2172
+ event: string
2173
+ claimId: string
2174
+ baseTier: EnforcementTier
2175
+ effectiveTier: EnforcementTier
2176
+ overrideState: PolicyOverrideState
2177
+ override?: PolicyOverride
2178
+ provenance?: PolicyOverrideProvenance
2179
+ }
2180
+
2181
+ interface PolicyOverrideGrantInput {
2182
+ event: string
2183
+ targetPolicyId: string
2184
+ relaxTo: OverrideRelaxTo
2185
+ expiresAt: string
2186
+ reason: string
2187
+ authority: PolicyAuthority
2188
+ /** Injectable provenance clock. */
2189
+ grantedAt?: string
2190
+ id?: string
2191
+ }
2192
+
2193
+ interface PolicyOverrideRevokeInput {
2194
+ id: string
2195
+ authority: PolicyAuthority
2196
+ reason?: string
2197
+ }
2198
+
2199
+ interface ResolveEffectivePoliciesInput {
2200
+ records: readonly PolicyRecord[]
2201
+ overrides?: readonly PolicyOverride[]
2202
+ /** Injectable clock for deterministic expiry resolution. */
2203
+ now?: () => Date
2204
+ }
2205
+
2206
+ type EnforcementTier = 'context' | 'precondition' | 'hard-precondition'
2207
+
2208
+ type PolicyAuthorityKind = 'HI' | 'operator'
2209
+
2210
+ type ConditionKind = 'payload-language' | 'field-equals'
2211
+
2212
+ type ConditionOutcome = 'satisfied' | 'violated' | 'unresolved'
2213
+
2214
+ type PolicyAction = 'allow' | 'block-and-ask' | 'block'
2215
+
2216
+ type OverrideRelaxTo = EnforcementTier
2217
+
2218
+ type PolicyAuditAction =
2219
+ | 'assign'
2220
+ | 'remove'
2221
+ | 'clear'
2222
+ | 'override'
2223
+ | 'revoke'
2224
+ | 'lock-break'
2225
+
2226
+ type PolicyAuditAuthority =
2227
+ | PolicyAuthority
2228
+ | { kind: 'system'; source: string }
2229
+
2230
+ type PolicyOverrideState = 'ACTIVE' | 'EXPIRED' | 'STALE' | 'INERT' | 'NONE'
2231
+
2232
+ type PolicyOverrideInertDetail =
2233
+ | 'active'
2234
+ | 'policy-missing'
2235
+ | 'policy-changed'
2236
+ | 'expired'
2237
+ | 'revoked'
2238
+ | 'superseded'
2239
+ | 'multiple-active'
2240
+
2241
+ interface SummaryFact {
2242
+ id: string
2243
+ statement: string
2244
+ confidence: 'high' | 'medium' | 'low'
2245
+ source: string
2246
+ timestamp: string
2247
+ }
2248
+
2249
+ interface SummaryDecision {
2250
+ id: string
2251
+ statement: string
2252
+ concluded: boolean
2253
+ timestamp: string
2254
+ }
2255
+
2256
+ interface DecayRecord {
2257
+ fromLevel: string
2258
+ toLevel: string
2259
+ at: string
2260
+ detailReduction: number
2261
+ tokensBefore: number
2262
+ tokensAfter: number
2263
+ }
2264
+
2265
+ interface ProgressiveSummary {
2266
+ id: string
2267
+ level: 'current' | 'recent' | 'distant' | 'archived'
2268
+ createdAt: string
2269
+ sessionIds: string[]
2270
+ detail: number
2271
+ tokenBudget: number
2272
+ summaryText: string
2273
+ keyFacts: SummaryFact[]
2274
+ keyDecisions: SummaryDecision[]
2275
+ openQuestions: string[]
2276
+ exemplarIds: string[]
2277
+ decayHistory: DecayRecord[]
2278
+ }
2279
+
2280
+ interface ProjectAnchor {
2281
+ projectId: string
2282
+ path: string
2283
+ /** True when the anchor already existed before this call. */
2284
+ existed: boolean
2285
+ }
2286
+
2287
+ interface SizeDisclosureOptions {
2288
+ totalCandidates: number
2289
+ omittedCandidates: number
2290
+ /** Bytes of the projected body (identity + index + anchor + exemplars + envelope). */
2291
+ projectedBytes: number
2292
+ /** `Infinity` when `--full` is in effect. */
2293
+ maxCharacters: number
2294
+ /** Host truncation ceiling used to flag that the head may be incomplete. */
2295
+ hostCeilingBytes: number
2296
+ /** When present, the manifest is summarized instead of only counted. */
2297
+ manifest?: OmissionManifest
2298
+ }
2299
+
2300
+ interface BootstrapProjectionClaim {
2301
+ id: string
2302
+ summary: string
2303
+ }
2304
+
2305
+ interface BootstrapProjection {
2306
+ format: 'dotmem-bootstrap-v1'
2307
+ status: 'complete' | 'incomplete'
2308
+ complete: boolean
2309
+ incomplete: boolean
2310
+ overflow: boolean
2311
+ available: number
2312
+ availableCount: number
2313
+ represented: number
2314
+ representedCount: number
2315
+ representedIds: string[]
2316
+ representedClaimIds: string[]
2317
+ omittedIds: string[]
2318
+ omittedClaimIds: string[]
2319
+ omissions: Array<{ id: string; reason: string }>
2320
+ omittedReasons: Array<{ id: string; reason: string }>
2321
+ bytes: number
2322
+ byteLength: number
2323
+ utf8Bytes: number
2324
+ payloadBytes: number
2325
+ maxBytes: number
2326
+ byteBudget: number
2327
+ budget: number
2328
+ text: string
2329
+ payload: string
2330
+ bootstrap: string
2331
+ bootstrapText: string
2332
+ claims: BootstrapProjectionClaim[]
2333
+ entries: BootstrapProjectionClaim[]
2334
+ items: BootstrapProjectionClaim[]
2335
+ }
2336
+
2337
+ interface ReadPackageResult extends MemInspection {
2338
+ file: string
2339
+ }
2340
+
2341
+ interface StoreListing {
2342
+ root: string
2343
+ packages: Array<{ file: string; path: string; inspection: MemInspection }>
2344
+ }
2345
+
2346
+ interface RenderResult {
2347
+ markdown: string
2348
+ claimsWritten: number
2349
+ format: string
2350
+ }
2351
+
2352
+ interface MemoryTarget {
2353
+ runtime: KnowledgeRuntime
2354
+ repository: KnowledgeRepository
2355
+ /**
2356
+ * Semantic scope of the claim being routed. The router may choose a shared
2357
+ * physical store for a kind (logic.mem, agent.mem) but it never rewrites the
2358
+ * claim's semantic scope: a project-scoped claim routed into the shared
2359
+ * logic container stays project-scoped.
2360
+ */
2361
+ scope: 'user' | 'project'
2362
+ /** Physical source id the claim is persisted to (logic, agent, user, <projectId>). */
2363
+ sourceId: string
2364
+ }
2365
+
2366
+ interface RuleCheckViolation {
2367
+ claimId: string
2368
+ description: string
2369
+ pattern: string
2370
+ file: string
2371
+ match?: string
2372
+ }
2373
+
2374
+ interface RuleCheckResult {
2375
+ passed: boolean
2376
+ violations: RuleCheckViolation[]
2377
+ checked: number
2378
+ }
2379
+
2380
+ interface IronRule {
2381
+ id: string
2382
+ text: string
2383
+ why: string
2384
+ appliesWhen: string
2385
+ violatedOn?: string[]
2386
+ lastViolation?: string
2387
+ frequency: number
2388
+ }
2389
+
2390
+ interface RulesReport {
2391
+ rules: IronRule[]
2392
+ count: number
2393
+ sortedBy: 'violation-frequency' | 'recency'
2394
+ }
2395
+
2396
+ interface SanitizationRejection {
2397
+ reason: SanitizationRejectionReason
2398
+ detail: string
2399
+ }
2400
+
2401
+ interface SanitizationResult {
2402
+ sanitized: boolean
2403
+ removedSensitiveFields: number
2404
+ knowledge: JsonValue
2405
+ disposition: SanitizationDisposition
2406
+ rejection?: SanitizationRejection
2407
+ }
2408
+
2409
+ type SanitizationDisposition = 'persist' | 'reject'
2410
+
2411
+ type SanitizationRejectionReason = 'encoding'
2412
+
2413
+ interface BuildInstructionsOptions {
2414
+ writeEnabled: boolean
2415
+ hasExperience: boolean
2416
+ language?: string
2417
+ }
2418
+
2419
+ interface ScintillaResult {
2420
+ action: ScintillaAction
2421
+ path: string
2422
+ }
2423
+
2424
+ type ScintillaAction = 'created' | 'already-present' | 'partial-marker'
2425
+
2426
+ interface SessionState {
2427
+ doing: string
2428
+ changedFiles: string[]
2429
+ waitingForUser: string[]
2430
+ doNotYet: string[]
2431
+ updatedAt: string
2432
+ }
2433
+
2434
+ interface DotMemStageFile {
2435
+ format: typeof DOTMEM_STAGE_FORMAT
2436
+ version: typeof DOTMEM_STAGE_VERSION
2437
+ requestId: string
2438
+ scope: 'user' | 'project'
2439
+ sourceProject?: string
2440
+ claim: AcquireOptions
2441
+ }
2442
+
2443
+ interface StageWriteResult {
2444
+ requestId: string
2445
+ stagePath: string
2446
+ }
2447
+
2448
+ interface StageCommitResult {
2449
+ requestId: string
2450
+ claimId: string
2451
+ sourceId: string
2452
+ scope: 'user' | 'project'
2453
+ kind: MemoryKind
2454
+ }
2455
+
2456
+ interface DotMemStorageLocator {
2457
+ version: number
2458
+ storageRoot: string
2459
+ }
2460
+
2461
+ interface DotMemStorageLocation {
2462
+ /** Stable user anchor directory (never moves when storage relocates). */
2463
+ anchor: string
2464
+ /** Locator file path inside the user anchor. */
2465
+ locatorFile: string
2466
+ /** Canonical dotmem storage root. */
2467
+ storageRoot: string
2468
+ /** Resolution source, so callers can report the semantic location. */
2469
+ source: DotMemStorageSource
2470
+ /** Settings/locator divergence classification, when a settings tier governs. */
2471
+ divergence?: DotMemStorageDivergence
2472
+ /** Explicit human-readable notes about the resolution (e.g. SHADOWED). */
2473
+ notes?: string[]
2474
+ }
2475
+
2476
+ interface DotMemStorageCapabilities {
2477
+ root: string
2478
+ observedAt: string
2479
+ /** Exclusive create (wx) worked for this process in this directory, now. */
2480
+ exclusiveCreate: 'observed' | 'failed' | 'unverified'
2481
+ /** tmp + rename round trip worked. */
2482
+ tmpRename: 'observed' | 'failed' | 'unverified'
2483
+ /** Written bytes read back identical. */
2484
+ readBack: 'observed' | 'failed' | 'unverified'
2485
+ /** Never verified by a local probe. */
2486
+ crossHostLocking: 'unverified'
2487
+ /** 'unverified' when exclusive create was observed; otherwise 'unsupported'. */
2488
+ multiWriterSafety: 'unsupported' | 'unverified'
2489
+ notes: string[]
2490
+ }
2491
+
2492
+ interface RelocateStorageOptions {
2493
+ /** Intentional flag required to rewrite a project settings file. */
2494
+ updateProjectSettings?: boolean
2495
+ }
2496
+
2497
+ type DotMemStorageSource =
2498
+ | 'cli-override'
2499
+ | 'override'
2500
+ | 'project-settings'
2501
+ | 'user-settings'
2502
+ | 'locator'
2503
+ | 'default'
2504
+
2505
+ type DotMemStorageDivergence = 'none' | 'SHADOWED' | 'SPLIT_BRAIN' | 'MIGRATION_REQUIRED'
2506
+
2507
+ interface RuntimeProcessLike {
2508
+ env?: Record<string, string | undefined>
2509
+ platform?: string
2510
+ getBuiltinModule?: (id: string) => unknown
2511
+ }
2512
+
2513
+ type SyncFsLike = typeof import('node:fs')
2514
+
2515
+ interface DotMemStorageSettings {
2516
+ root?: string
2517
+ mode?: DotMemStorageMode
2518
+ }
2519
+
2520
+ interface ResolvedStorageSettings {
2521
+ tier: DotMemStorageSettingsTier
2522
+ /** Path of the settings file that declared the entry. */
2523
+ file: string
2524
+ /** Absolute resolved root declared by the entry, if any. */
2525
+ root: string | undefined
2526
+ mode: DotMemStorageMode
2527
+ }
2528
+
2529
+ type DotMemStorageMode = 'default' | 'custom' | 'portable'
2530
+
2531
+ type DotMemStorageSettingsTier = 'user' | 'project'
2532
+
2533
+ interface ToolPolicyGuardDecision {
2534
+ event: string
2535
+ blocked: boolean
2536
+ action: 'allow' | 'ask' | 'deny'
2537
+ reason: string | null
2538
+ policyId: string | null
2539
+ authority: string | null
2540
+ requiresHumanResolution: boolean
2541
+ }
2542
+
2543
+ interface ToolEventSpec {
2544
+ event: ToolEvent
2545
+ description: string
2546
+ defaultTier: 'context' | 'precondition' | 'hard-precondition'
2547
+ }
2548
+
2549
+ type ToolEvent = (typeof TOOL_EVENTS)[number]
2550
+
2551
+ interface EvidenceReference {
2552
+ id: string
2553
+ source?: string
2554
+ observedAt?: string
2555
+ supports?: string
2556
+ }
2557
+
2558
+ interface TrustBasisProjection {
2559
+ /** Derived trust basis, following provenance not the stored label. */
2560
+ trustBasis: TrustBasis
2561
+ /** Whether evidence references were resolved and validated. */
2562
+ evidenceResolved: boolean
2563
+ /** Whether a mechanical check was executed and recorded. */
2564
+ mechanicallyChecked: boolean
2565
+ /** Whether an external attestation was validated by a trusted mechanism. */
2566
+ externallyAttested: boolean
2567
+ /** The per-evidence resolution state (unresolved until actually resolved). */
2568
+ evidenceResolution: Array<{ id: string; resolved: boolean }>
2569
+ }
2570
+
2571
+ interface ClaimProvenance {
2572
+ source: string
2573
+ detail?: string
2574
+ }
2575
+
2576
+ interface RevisionRelationship {
2577
+ kind: 'refines' | 'supersedes' | 'retracts'
2578
+ claimIds: string[]
2579
+ reason?: string
2580
+ }
2581
+
2582
+ interface ClaimSelfCheck {
2583
+ kind: 'regex' | 'file-json'
2584
+ pattern?: string
2585
+ path?: string
2586
+ pointer?: string
2587
+ expect?: unknown
2588
+ on: 'staged' | 'committed' | 'working-tree'
2589
+ description?: string
2590
+ }
2591
+
2592
+ interface AcquiredClaim {
2593
+ id: string
2594
+ knowledge: JsonValue
2595
+ applicability: Record<string, JsonPrimitive>
2596
+ evidence: EvidenceReference[]
2597
+ epistemicType?: EpistemicType
2598
+ provenance?: ClaimProvenance
2599
+ acquiredAt?: string
2600
+ /** Epoch ms when this entry expires and should become inactive. Absence means no expiry. */
2601
+ expiresAt?: number
2602
+ /** Bootstrap ordering metadata (P1-P5), not authority. Absence means unclassified. */
2603
+ bootstrapPriority?: 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'unclassified'
2604
+ revision?: RevisionRelationship
2605
+ scope?: 'user' | 'project'
2606
+ /**
2607
+ * Owning project of a project-scoped claim.
2608
+ *
2609
+ * Required for project-scoped claims kept in a shared physical store
2610
+ * (logic.mem / agent.mem): without it the retrieval scope-eligibility gate
2611
+ * cannot tell which project the claim belongs to. Claims that live in their
2612
+ * own projects/<projectId>.mem derive their owner from the physical file.
2613
+ */
2614
+ sourceProject?: string
2615
+ kind?: MemoryKind
2616
+ /**
2617
+ * A self-checking rule that can verify whether the claim still holds.
2618
+ * The check runs read-only on the output and reports violations.
2619
+ */
2620
+ check?: ClaimSelfCheck
2621
+ }
2622
+
2623
+ interface AcquireOptions {
2624
+ id?: string
2625
+ knowledge: JsonValue
2626
+ applicability: Record<string, JsonPrimitive>
2627
+ evidence: EvidenceReference[]
2628
+ epistemicType?: EpistemicType
2629
+ provenance?: ClaimProvenance
2630
+ acquiredAt?: string
2631
+ /** Epoch ms when this entry expires and should become inactive. Absence means no expiry. */
2632
+ expiresAt?: number
2633
+ /** Bootstrap ordering metadata (P1-P5), not authority. Absence means unclassified. */
2634
+ bootstrapPriority?: 'P1' | 'P2' | 'P3' | 'P4' | 'P5' | 'unclassified'
2635
+ refines?: string | string[]
2636
+ supersedes?: string | string[]
2637
+ retracts?: string | string[]
2638
+ reason?: string
2639
+ scope?: 'user' | 'project'
2640
+ kind?: MemoryKind
2641
+ sourceProject?: string
2642
+ check?: ClaimSelfCheck
2643
+ }
2644
+
2645
+ interface KnowledgeState {
2646
+ version: number
2647
+ claims: AcquiredClaim[]
2648
+ }
2649
+
2650
+ interface KnowledgeUpdate {
2651
+ basedOnVersion: number
2652
+ claims: AcquiredClaim[]
2653
+ }
2654
+
2655
+ interface KnowledgeQuery {
2656
+ id: string
2657
+ context: Record<string, JsonPrimitive>
2658
+ }
2659
+
2660
+ interface AcquiredContext {
2661
+ knowledgeVersion: number
2662
+ claims: AcquiredClaim[]
2663
+ }
2664
+
2665
+ interface ApplicabilityMatch {
2666
+ state: ApplicabilityState
2667
+ /** A MISMATCH is the only state that removes a claim from eligibility. */
2668
+ eligible: boolean
2669
+ dimensions: Record<string, ApplicabilityDimensionState>
2670
+ }
2671
+
2672
+ interface RuntimeEnvironment {
2673
+ platform?: string
2674
+ shell?: string
2675
+ runtime?: string
2676
+ }
2677
+
2678
+ interface DiscoveryOptions {
2679
+ depth?: DiscoveryDepth
2680
+ maxCandidates?: number
2681
+ /** Explicit runtime facts that override situation-prose derivation. */
2682
+ facts?: SituationFacts
2683
+ /**
2684
+ * Project identity the retrieval runs for. Enables the scope-eligibility
2685
+ * gate: a project-scoped claim is eligible only for its owning project.
2686
+ * Omitting it keeps every claim eligible (pre-scope-bound behavior).
2687
+ */
2688
+ currentProjectId?: string
2689
+ /**
2690
+ * Resume a previous page. The cursor pins the snapshot it was produced
2691
+ * against; if the store moved on, discovery reports the change instead of
2692
+ * silently mixing two snapshots.
2693
+ */
2694
+ cursor?: DiscoveryCursor
2695
+ /**
2696
+ * Whether to include claims with `knowledge.kind === 'rule'` in the context
2697
+ * projection. Rules remain available through the rules reference and
2698
+ * bootstrap; ordinary context excludes them to avoid duplicating rule text.
2699
+ * Default false.
2700
+ */
2701
+ includeRules?: boolean
2702
+ }
2703
+
2704
+ interface DiscoveryCursor {
2705
+ knowledgeVersion: number
2706
+ /** Number of ranked candidates already returned by earlier pages. */
2707
+ offset: number
2708
+ }
2709
+
2710
+ interface DiscoveryExplanation {
2711
+ matchedTerms: string[]
2712
+ matchedFields: DiscoveryField[]
2713
+ sourceId?: string
2714
+ /**
2715
+ * Applicability eligibility for this candidate, retained instead of a score
2716
+ * so later explainability can report which dimensions matched.
2717
+ */
2718
+ applicability?: ApplicabilityMatch
2719
+ }
2720
+
2721
+ interface DiscoveryCandidate {
2722
+ claim: AcquiredClaim
2723
+ explanation: DiscoveryExplanation
2724
+ /** Derived currentness, so the projection renders what discovery resolved. */
2725
+ currentness?: CurrentnessState
2726
+ }
2727
+
2728
+ interface DiscoveryResult {
2729
+ knowledgeVersion: number
2730
+ depth: DiscoveryDepth
2731
+ queryTerms: string[]
2732
+ /** Structured applicability derived from the situation, for inspection. */
2733
+ situationApplicability?: SituationApplicability
2734
+ candidates: DiscoveryCandidate[]
2735
+ /**
2736
+ * Every claim that was considered and not returned, with the decisive gate and
2737
+ * a stable reason. This is the inspectable counterpart of `OMITTED:n`: the
2738
+ * count alone never says which record was dropped or why.
2739
+ */
2740
+ omissions?: OmissionRecord[]
2741
+ /** Offset of the first returned candidate, for cursor-based pagination. */
2742
+ offset?: number
2743
+ /** True when a supplied cursor referred to a different snapshot. */
2744
+ snapshotChanged?: boolean
2745
+ }
2746
+
2747
+ interface OmissionRecord {
2748
+ id: string
2749
+ reason: OmissionReason
2750
+ gate: OmissionGate
2751
+ /** Human-readable specifics (mismatching dimensions, owning project, ...). */
2752
+ detail?: string
2753
+ }
2754
+
2755
+ interface OmissionManifest {
2756
+ /** Claims considered by discovery plus claims dropped by the projection. */
2757
+ considered: number
2758
+ /** Claims present in the rendered payload. */
2759
+ included: number
2760
+ items: OmissionRecord[]
2761
+ byReason: Array<{ reason: OmissionReason | 'budget'; count: number }>
2762
+ }
2763
+
2764
+ interface ClaimExplanation {
2765
+ id: string
2766
+ disposition: ClaimDisposition
2767
+ revision: ClaimRevisionState
2768
+ /** Convenience mirror of `revision === 'current'`. */
2769
+ current: boolean
2770
+ /** True when the claim entered through baseline semantics, not applicability. */
2771
+ baseline: boolean
2772
+ applicability: ApplicabilityMatch | null
2773
+ /** Earliest decisive gate that excluded the claim; absent otherwise. */
2774
+ decisiveGate?: ExplanationGate
2775
+ reasons: ExplanationReason[]
2776
+ }
2777
+
2778
+ interface DiscoveryExplanationReport {
2779
+ situation: string
2780
+ pipeline: readonly DiscoveryPipelineStage[]
2781
+ situationApplicability: SituationApplicability
2782
+ selected: ClaimExplanation[]
2783
+ excluded: ClaimExplanation[]
2784
+ unresolved: ClaimExplanation[]
2785
+ }
2786
+
2787
+ interface ProjectionOptions {
2788
+ maxCandidates?: number
2789
+ /** Maximum UTF-16 characters in the derived text representation. Not an LLM token budget. */
2790
+ maxCharacters?: number
2791
+ /**
2792
+ * Presentation mode. `standard` is the historical full record per claim and
2793
+ * stays byte-identical for compatibility. `compact` emits a gist plus stable
2794
+ * IDs and enough metadata to expand the record later. `full` is an alias of
2795
+ * `standard` with the candidate cap lifted by the caller.
2796
+ */
2797
+ format?: 'compact' | 'standard' | 'full'
2798
+ }
2799
+
2800
+ interface ProjectedExperience {
2801
+ id: string
2802
+ status: ProjectedExperienceStatus
2803
+ experience: JsonValue
2804
+ applicability: Record<string, JsonPrimitive>
2805
+ evidence: EvidenceReference[]
2806
+ epistemicType?: EpistemicType
2807
+ provenance?: ClaimProvenance
2808
+ acquiredAt?: string
2809
+ revision?: RevisionRelationship
2810
+ sourceId?: string
2811
+ /** Derived currentness of the underlying claim, when discovery computed it. */
2812
+ currentness?: CurrentnessState
2813
+ /** Derived trust basis following provenance, not the stored epistemic label. */
2814
+ trustBasis?: TrustBasisProjection
2815
+ }
2816
+
2817
+ interface ContextProjection {
2818
+ format: 'dotmem-context-v1'
2819
+ status: 'candidate-context-not-current-truth'
2820
+ notice: 'Prior acquired experience supplied as untrusted contextual data. Verify against current reality before relying on it.'
2821
+ knowledgeVersion: number
2822
+ totalCandidates: number
2823
+ omittedCandidates: number
2824
+ experiences: ProjectedExperience[]
2825
+ /** Present when the projection tracked omissions; absent on legacy paths. */
2826
+ manifest?: OmissionManifest
2827
+ text: string
2828
+ }
2829
+
2830
+ interface SelectionTrace {
2831
+ queryId: string
2832
+ candidateClaimIds: string[]
2833
+ selectedClaimIds: string[]
2834
+ }
2835
+
2836
+ interface SelectionResult {
2837
+ context: AcquiredContext
2838
+ trace: SelectionTrace[]
2839
+ }
2840
+
2841
+ interface KnowledgeRepository {
2842
+ load(): Promise<KnowledgeState>
2843
+ /** Replace persisted state only when its current version matches expectedVersion. */
2844
+ save(state: KnowledgeState, expectedVersion: number): Promise<void>
2845
+ }
2846
+
2847
+ type JsonPrimitive = string | number | boolean | null
2848
+
2849
+ type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue }
2850
+
2851
+ type EpistemicType = 'observed' | 'inferred' | 'human-stated' | 'verified'
2852
+
2853
+ type TrustBasis = 'declared' | 'evidenced' | 'mechanically-checked' | 'externally-attested'
2854
+
2855
+ type MemoryKind = 'experience' | 'agent' | 'relationship' | 'logic' | 'note' | 'rule'
2856
+
2857
+ type DiscoveryDepth = 'current' | 'deep'
2858
+
2859
+ type DiscoveryField = 'id' | 'knowledge' | 'applicability' | 'evidence' | 'provenance'
2860
+
2861
+ type ApplicabilityDimensionState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED'
2862
+
2863
+ type ApplicabilityState = 'MATCH' | 'MISMATCH' | 'UNSPECIFIED' | 'PARTIAL'
2864
+
2865
+ type SituationApplicability = Record<string, JsonPrimitive>
2866
+
2867
+ type SituationFacts = SituationApplicability
2868
+
2869
+ type CurrentnessState =
2870
+ | 'historical'
2871
+ | 'superseded'
2872
+ | 'expired'
2873
+ | 'verified'
2874
+ | 'unverified'
2875
+ | 'contested'
2876
+ | 'unknown-currentness'
2877
+
2878
+ type OmissionReason =
2879
+ | 'retracted'
2880
+ | 'superseded'
2881
+ | 'expired'
2882
+ | 'scope'
2883
+ | 'applicability-mismatch'
2884
+ | 'no-term-match'
2885
+ | 'limit'
2886
+ | 'budget'
2887
+
2888
+ type OmissionGate =
2889
+ | 'revision-resolution'
2890
+ | 'scope'
2891
+ | 'freshness'
2892
+ | 'applicability'
2893
+ | 'ranking'
2894
+ | 'projection'
2895
+
2896
+ type ClaimDisposition = 'selected' | 'excluded' | 'unresolved'
2897
+
2898
+ type ClaimRevisionState = 'current' | 'retracted' | 'superseded' | 'historical-only'
2899
+
2900
+ type ExplanationGate = 'revision-resolution' | 'applicability-gate'
2901
+
2902
+ type DiscoveryPipelineStage =
2903
+ | 'candidate-collection'
2904
+ | 'revision-resolution'
2905
+ | 'applicability-gate'
2906
+ | 'ranking'
2907
+ | 'projection'
2908
+
2909
+ type ExplanationReason =
2910
+ | 'current'
2911
+ | 'retracted'
2912
+ | 'superseded'
2913
+ | 'baseline'
2914
+ | 'applicability-match'
2915
+ | 'applicability-mismatch'
2916
+ | 'applicability-unspecified'
2917
+
2918
+ type ProjectedExperienceStatus = 'prior-acquired-experience-candidate'
2919
+
2920
+ interface UserIdentity {
2921
+ name: string
2922
+ verified: boolean
2923
+ scope: 'user'
2924
+ }
2925
+
2926
+ interface UserIdentityStore {
2927
+ recall<T>(key: string): Promise<T | null>
2928
+ remember(key: string, value: unknown, opts?: Record<string, unknown>): Promise<void>
2929
+ forget(key: string): Promise<void>
2930
+ }
2931
+
2932
+ interface VaultEntry {
2933
+ handle: string
2934
+ value: string
2935
+ createdAt: string
2936
+ }
2937
+
2938
+ interface VaultDocument {
2939
+ version: number
2940
+ entries: Record<string, VaultEntry>
2941
+ }
2942
+
2943
+ interface VaultPutInput {
2944
+ handle?: string
2945
+ value: string
2946
+ createdAt?: string
2947
+ }
2948
+
2949
+ interface ProbeResult {
2950
+ claimId: string
2951
+ probe: string
2952
+ status: 'valid' | 'stale' | 'error'
2953
+ currentValue?: string
2954
+ expectedValue?: string
2955
+ detail: string
2956
+ }
2957
+
2958
+ interface VerifyResult {
2959
+ probesRun: number
2960
+ valid: number
2961
+ stale: number
2962
+ errors: number
2963
+ results: ProbeResult[]
2964
+ }
2965
+
2966
+ interface ViolationRecord {
2967
+ ruleId: string
2968
+ violatedAt: string
2969
+ description: string
2970
+ situation: string
2971
+ }
2972
+
2973
+ interface ViolationLogDocument {
2974
+ version: number
2975
+ entries: ViolationRecord[]
2976
+ }
2977
+
2978
+ interface RuntimeHandle {
2979
+ runtime: KnowledgeRuntime
2980
+ repository: KnowledgeRepository & { clearWritable?: () => Promise<void> }
2981
+ }
2982
+
2983
+ interface LogicExperienceKnowledge {
2984
+ situation: JsonValue
2985
+ action: JsonValue
2986
+ outcome: JsonValue
2987
+ }
2988
+
2989
+ type DotMemMemory = Pick<typeof memory, 'discover' | 'project' | 'acquire' | 'note'>
2990
+
2991
+ type DotMemAcquireInput = z.infer<typeof acquireSchema>
2992
+
2993
+ type DotMemNoteReadInput = z.infer<typeof noteReadSchema>
2994
+
2995
+ type DotMemNoteWriteInput = z.infer<typeof noteWriteSchema>
2996
+
2997
+ interface DurableStoreFile {
2998
+ version: number
2999
+ entries: MemoryEntry[]
3000
+ }
3001
+
3002
+ type FsHandle = {
3003
+ writeFile: (data: Uint8Array) => Promise<void>
3004
+ sync: () => Promise<void>
3005
+ close: () => Promise<void>
3006
+ }
3007
+
3008
+ type RuntimeFs = {
3009
+ readFile: (path: string) => Promise<Uint8Array>
3010
+ writeFile: (path: string, data: Uint8Array) => Promise<void>
3011
+ rename: (oldPath: string, newPath: string) => Promise<void>
3012
+ copyFile: (src: string, dest: string) => Promise<void>
3013
+ rm: (path: string, opts?: { recursive?: boolean; force?: boolean }) => Promise<void>
3014
+ mkdir: (path: string, opts?: { recursive?: boolean }) => Promise<void>
3015
+ open: (path: string, flags: string) => Promise<FsHandle>
3016
+ stat: (path: string) => Promise<{ isDirectory: () => boolean }>
3017
+ rmdir: (path: string) => Promise<void>
3018
+ }
3019
+
3020
+ interface IndexEntry {
3021
+ scope: MemoryScope
3022
+ superseded: boolean
3023
+ }
3024
+
3025
+ interface MemoryJournal {
3026
+ append(entry: MemoryEntry, operation: MemoryOperation): Promise<MemoryEntry>
3027
+ pending(): Promise<MemoryEntry[]>
3028
+ markSynced(ids: string[]): Promise<number>
3029
+ get(id: string): Promise<MemoryEntry | null>
3030
+ clear(): Promise<void>
3031
+ replay(): Promise<SyncAck>
3032
+ status(): Promise<'store' | 'memory'>
3033
+ }
3034
+
3035
+ interface CoordinatorOptions {
3036
+ adapterRegistry: ProviderAdapterRegistry
3037
+ agentRegistry: AgentRegistry
3038
+ state: DurableOrchestrationState
3039
+ coordinatorAgentId: string
3040
+ storageRoot?: string
3041
+ maxConcurrentTasksPerAgent?: number
3042
+ maxConcurrentTasksPerProvider?: number
3043
+ defaultTimeoutMs?: number
3044
+ maxRetries?: number
3045
+ }
3046
+
3047
+ interface EligibleAgent {
3048
+ compositeId: string
3049
+ providerId: string
3050
+ agentId: string
3051
+ displayName: string
3052
+ scope?: string
3053
+ capabilities: string[]
3054
+ supportedTaskTypes: string[]
3055
+ authorizationStatus: 'authorized'
3056
+ adapter: ProviderAdapter
3057
+ }
3058
+
3059
+ interface TaskAssignment {
3060
+ task: OrchestrationTask
3061
+ agent: EligibleAgent
3062
+ }
3063
+
3064
+ interface DecompositionResult {
3065
+ tasks: OrchestrationTask[]
3066
+ assignments: TaskAssignment[]
3067
+ unassignedEligibleAgents: EligibleAgent[]
3068
+ exceptions: OrchestrationException[]
3069
+ }
3070
+
3071
+ interface OrchestrationEvidenceReference {
3072
+ kind: string
3073
+ id: string
3074
+ version?: string | number
3075
+ digest?: string
3076
+ }
3077
+
3078
+ interface OrchestrationTaskDependency {
3079
+ taskId: string
3080
+ dependsOn: string
3081
+ reason?: string
3082
+ }
3083
+
3084
+ interface OrchestrationAcceptanceCriteria {
3085
+ criterionId: string
3086
+ description: string
3087
+ satisfied: boolean
3088
+ evidenceRefs: string[]
3089
+ }
3090
+
3091
+ interface OrchestrationTask {
3092
+ taskId: string
3093
+ parentRunId: string
3094
+ objective: string
3095
+ scope?: string
3096
+ requiredCapabilities: string[]
3097
+ inputRefs: string[]
3098
+ acceptanceCriteria: OrchestrationAcceptanceCriteria[]
3099
+ dependencies: OrchestrationTaskDependency[]
3100
+ assignedAgentCompositeId?: string
3101
+ assignedAgentId?: string
3102
+ providerId?: string
3103
+ state: TaskLifecycleState
3104
+ stateHistory: TaskLifecycleStateTransition[]
3105
+ createdAt: string
3106
+ updatedAt: string
3107
+ deadlineAt?: string
3108
+ timeoutMs?: number
3109
+ retry: {
3110
+ maxAttempts: number
3111
+ attempt: number
3112
+ idempotencyKey?: string
3113
+ }
3114
+ resultRef?: string
3115
+ validationRef?: string
3116
+ accepted: boolean
3117
+ exception?: OrchestrationException
3118
+ }
3119
+
3120
+ interface TaskLifecycleStateTransition {
3121
+ from: TaskLifecycleState
3122
+ to: TaskLifecycleState
3123
+ at: string
3124
+ reason?: string
3125
+ actor?: string
3126
+ }
3127
+
3128
+ interface OrchestrationAssignment {
3129
+ assignmentId: string
3130
+ taskId: string
3131
+ agentCompositeId: string
3132
+ providerId: string
3133
+ agentId: string
3134
+ jobHandleId?: string
3135
+ providerExecutionRef?: string
3136
+ state: TaskLifecycleState
3137
+ dispatchedAt?: string
3138
+ startedAt?: string
3139
+ completedAt?: string
3140
+ createdAt: string
3141
+ resultRef?: string
3142
+ validationRef?: string
3143
+ accepted: boolean
3144
+ exception?: OrchestrationException
3145
+ }
3146
+
3147
+ interface OrchestrationException {
3148
+ exceptionId: string
3149
+ category: ExceptionCategory
3150
+ agentCompositeId?: string
3151
+ providerId?: string
3152
+ taskId?: string
3153
+ reason: string
3154
+ evidence?: string[]
3155
+ timestamp: string
3156
+ retryable: boolean
3157
+ resolutionPath?: 'retry' | 'reassign' | 'escalate' | 'user_decision'
3158
+ resolved: boolean
3159
+ resolvedAt?: string
3160
+ resolvedBy?: string
3161
+ }
3162
+
3163
+ interface AgentDiscoverySnapshot {
3164
+ agentCompositeId: string
3165
+ providerId: string
3166
+ agentId: string
3167
+ displayName: string
3168
+ capabilities: string[]
3169
+ supportedTaskTypes: string[]
3170
+ availability: string
3171
+ invocationMode: string
3172
+ lifecycleCapabilities: string[]
3173
+ authorizationStatus: string
3174
+ eligible: boolean
3175
+ ineligibilityReason?: string
3176
+ discoveredAt: string
3177
+ lastCheckedAt: string
3178
+ }
3179
+
3180
+ interface ProviderCapabilitySnapshot {
3181
+ providerId: string
3182
+ protocol: string
3183
+ supportsDiscovery: boolean
3184
+ supportsInvocation: boolean
3185
+ supportsProgressSubscription: boolean
3186
+ supportsCancellation: boolean
3187
+ supportsArtifacts: boolean
3188
+ supportsConcurrentExecution: boolean
3189
+ maxConcurrentTasks?: number
3190
+ unsupportedOperations: string[]
3191
+ healthStatus: string
3192
+ lastCheckedAt: string
3193
+ }
3194
+
3195
+ interface OrchestrationRun {
3196
+ runId: string
3197
+ userObjective: string
3198
+ userScope?: string
3199
+ status: OrchestrationRunStatus
3200
+ createdAt: string
3201
+ updatedAt: string
3202
+ completedAt?: string
3203
+ discoverySnapshot: AgentDiscoverySnapshot[]
3204
+ providerCapabilitySnapshot: ProviderCapabilitySnapshot[]
3205
+ tasks: OrchestrationTask[]
3206
+ assignments: OrchestrationAssignment[]
3207
+ exceptions: OrchestrationException[]
3208
+ finalReport?: OrchestrationRunReport
3209
+ idempotencyKey?: string
3210
+ correlationId?: string
3211
+ }
3212
+
3213
+ interface OrchestrationRunReport {
3214
+ reportId: string
3215
+ runId: string
3216
+ generatedAt: string
3217
+ totalAgentsDiscovered: number
3218
+ totalAgentsEligible: number
3219
+ totalAgentsAssigned: number
3220
+ totalAgentsCompleted: number
3221
+ totalAgentsFailed: number
3222
+ totalAgentsTimedOut: number
3223
+ totalAgentsCancelled: number
3224
+ totalAgentsBlocked: number
3225
+ totalExceptions: number
3226
+ unresolvedExceptions: number
3227
+ tasksCompleted: number
3228
+ tasksFailed: number
3229
+ tasksBlocked: number
3230
+ tasksPending: number
3231
+ participationComplete: boolean
3232
+ allRequiredAgentsAccountedFor: boolean
3233
+ independentVerificationPassed: boolean
3234
+ conflictsResolved: boolean
3235
+ userApprovalRequired: boolean
3236
+ userApprovalGranted: boolean
3237
+ summary: string
3238
+ risks: string[]
3239
+ }
3240
+
3241
+ interface OrchestrationEvent {
3242
+ eventId: string
3243
+ runId: string
3244
+ taskId?: string
3245
+ agentCompositeId?: string
3246
+ providerId?: string
3247
+ eventType: 'run_started' | 'discovery_completed' | 'agent_assigned' | 'task_dispatched' | 'task_progress' | 'task_completed' | 'task_failed' | 'task_cancelled' | 'task_timed_out' | 'task_blocked' | 'result_received' | 'result_validated' | 'joy_accepted' | 'exception_recorded' | 'recovery_started' | 'recovery_completed' | 'run_completed'
3248
+ fromState?: TaskLifecycleState | OrchestrationRunStatus
3249
+ toState?: TaskLifecycleState | OrchestrationRunStatus
3250
+ timestamp: string
3251
+ actor?: string
3252
+ reason?: string
3253
+ evidence: OrchestrationEvidenceReference[]
3254
+ correlationId?: string
3255
+ }
3256
+
3257
+ interface OrchestrationStateSnapshot {
3258
+ runs: Record<string, OrchestrationRun>
3259
+ currentRunId?: string
3260
+ lastUpdatedAt: string
3261
+ }
3262
+
3263
+ interface MemoryEntryLike {
3264
+ id: string
3265
+ key: string
3266
+ value: unknown
3267
+ type: MemoryType
3268
+ confidence: number
3269
+ scope: string
3270
+ ttl?: number | null
3271
+ tags: string[]
3272
+ source?: string
3273
+ status: 'active' | 'obsolete' | 'superseded'
3274
+ createdAt: number
3275
+ lastConfirmedAt: number
3276
+ updatedAt?: number
3277
+ }
3278
+
3279
+ interface MemoryFacadeLike {
3280
+ remember(key: string, value: unknown, opts?: { type?: MemoryType; scope?: string; confidence?: number; tags?: string[]; source?: string }): Promise<void>
3281
+ recall<T = unknown>(key: string): Promise<{ id: string; key: string; value: T; type: MemoryType; confidence: number; scope: string; ttl?: number | null; tags: string[]; source?: string; status: 'active' | 'obsolete' | 'superseded'; createdAt: number; lastConfirmedAt: number; updatedAt?: number } | null>
3282
+ forget(key: string): Promise<void>
3283
+ _loadAll(): Promise<MemoryEntryLike[]>
3284
+ }
3285
+
3286
+ type MemoryType = 'fact' | 'preference' | 'decision' | 'task' | 'context'
3287
+
3288
+ type OrchestrationRunStatus =
3289
+ | 'discovering'
3290
+ | 'planning'
3291
+ | 'assigned'
3292
+ | 'running'
3293
+ | 'completed'
3294
+ | 'failed'
3295
+ | 'partially_completed'
3296
+ | 'cancelled'
3297
+ | 'recovery_blocked'
3298
+
3299
+ type TaskLifecycleState =
3300
+ | 'discovered'
3301
+ | 'eligible'
3302
+ | 'assigned'
3303
+ | 'dispatch_accepted'
3304
+ | 'running'
3305
+ | 'blocked'
3306
+ | 'completed'
3307
+ | 'failed'
3308
+ | 'timed_out'
3309
+ | 'cancelled'
3310
+ | 'result_received'
3311
+ | 'result_validated'
3312
+ | 'accepted'
3313
+
3314
+ type ExceptionCategory =
3315
+ | 'agent_unavailable'
3316
+ | 'agent_busy'
3317
+ | 'permission_denied'
3318
+ | 'no_useful_subtask'
3319
+ | 'execution_failed'
3320
+ | 'timed_out'
3321
+ | 'cancelled'
3322
+ | 'provider_unreachable'
3323
+ | 'discovery_incomplete'
3324
+ | 'recovery_blocked'
3325
+
3326
+ interface AgentDescriptor {
3327
+ agentId: string
3328
+ providerId: string
3329
+ compositeId: string
3330
+ displayName: string
3331
+ description?: string
3332
+ capabilities: string[]
3333
+ supportedTaskTypes?: string[]
3334
+ invocationRef?: string
3335
+ availability: AgentAvailability
3336
+ lastDiscoveryAt: string
3337
+ invocationMode: AgentInvocationMode
3338
+ lifecycleCapabilities: TaskLifecycleCapability[]
3339
+ concurrencyLimits?: {
3340
+ maxConcurrentTasks?: number
3341
+ maxTasksPerMinute?: number
3342
+ }
3343
+ authorizationStatus: AuthorizationStatus
3344
+ authorizationReason?: string
3345
+ eligible: boolean
3346
+ ineligibilityReason?: string
3347
+ }
3348
+
3349
+ interface AgentCapabilities {
3350
+ agentId: string
3351
+ providerId: string
3352
+ capabilities: string[]
3353
+ supportedTaskTypes: string[]
3354
+ invocationMode: AgentInvocationMode
3355
+ lifecycleCapabilities: TaskLifecycleCapability[]
3356
+ concurrencyLimits?: {
3357
+ maxConcurrentTasks?: number
3358
+ maxTasksPerMinute?: number
3359
+ }
3360
+ authorizationStatus: AuthorizationStatus
3361
+ }
3362
+
3363
+ interface ProviderCapabilityDeclaration {
3364
+ providerId: string
3365
+ protocol: ProviderProtocol
3366
+ supportsDiscovery: boolean
3367
+ supportsInvocation: boolean
3368
+ supportsProgressSubscription: boolean
3369
+ supportsCancellation: boolean
3370
+ supportsArtifacts: boolean
3371
+ supportsConcurrentExecution: boolean
3372
+ maxConcurrentTasks?: number
3373
+ unsupportedOperations: string[]
3374
+ }
3375
+
3376
+ interface DispatchTask {
3377
+ taskId: string
3378
+ runId: string
3379
+ agentId: string
3380
+ providerId: string
3381
+ objective: string
3382
+ scope?: string
3383
+ inputRefs: string[]
3384
+ acceptanceCriteria: string[]
3385
+ requiredCapabilities: string[]
3386
+ contextBrief?: unknown
3387
+ deadlineAt?: string
3388
+ timeoutMs?: number
3389
+ idempotencyKey: string
3390
+ correlationId: string
3391
+ }
3392
+
3393
+ interface AgentJobHandle {
3394
+ jobId: string
3395
+ providerId: string
3396
+ agentId: string
3397
+ taskId: string
3398
+ runId: string
3399
+ providerExecutionRef?: string
3400
+ status: 'dispatched' | 'running' | 'completed' | 'failed' | 'cancelled' | 'timed_out' | 'blocked'
3401
+ dispatchedAt: string
3402
+ updatedAt: string
3403
+ }
3404
+
3405
+ interface AgentProgress {
3406
+ jobId: string
3407
+ taskId: string
3408
+ agentId: string
3409
+ status: 'running' | 'completed' | 'failed' | 'cancelled' | 'timed_out' | 'blocked'
3410
+ progressPct?: number
3411
+ message?: string
3412
+ timestamp: string
3413
+ artifacts?: ArtifactReference[]
3414
+ }
3415
+
3416
+ interface AgentResult {
3417
+ resultId: string
3418
+ taskId: string
3419
+ agentId: string
3420
+ providerId: string
3421
+ runId: string
3422
+ status: 'success' | 'failure' | 'partial'
3423
+ payload?: unknown
3424
+ payloadRef?: string
3425
+ evidence: OrchestrationEvidenceReference[]
3426
+ warnings: string[]
3427
+ errors: string[]
3428
+ inputRefs: string[]
3429
+ createdAt: string
3430
+ completedAt: string
3431
+ confidence?: number
3432
+ }
3433
+
3434
+ interface ArtifactReference {
3435
+ artifactId: string
3436
+ name: string
3437
+ description?: string
3438
+ mediaType?: string
3439
+ uri?: string
3440
+ sizeBytes?: number
3441
+ }
3442
+
3443
+ interface ProviderHealth {
3444
+ providerId: string
3445
+ status: ProviderHealthStatus
3446
+ lastCheckedAt: string
3447
+ message?: string
3448
+ error?: string
3449
+ }
3450
+
3451
+ interface NormalizedAdapterError {
3452
+ errorId: string
3453
+ providerId: string
3454
+ category: 'discovery' | 'invocation' | 'authorization' | 'timeout' | 'cancellation' | 'network' | 'unknown'
3455
+ message: string
3456
+ retryable: boolean
3457
+ originalError?: unknown
3458
+ }
3459
+
3460
+ interface ProviderEvidenceReference {
3461
+ kind: string
3462
+ id: string
3463
+ version?: string | number
3464
+ digest?: string
3465
+ }
3466
+
3467
+ interface ProviderAdapter {
3468
+ providerId: string
3469
+ providerName: string
3470
+ protocol: ProviderProtocol
3471
+ version?: string
3472
+
3473
+ checkHealth(): Promise<ProviderHealth>
3474
+ discoverAgents(): Promise<AgentDescriptor[]>
3475
+ refreshDiscovery(): Promise<AgentDescriptor[]>
3476
+ getAgentCapabilities(agentId: string): Promise<AgentCapabilities>
3477
+ declareCapabilities(): ProviderCapabilityDeclaration
3478
+ dispatch(task: DispatchTask): Promise<AgentJobHandle>
3479
+ getProgress(jobHandle: AgentJobHandle): Promise<AgentProgress>
3480
+ subscribeToProgress?(
3481
+ jobHandle: AgentJobHandle,
3482
+ callback: (progress: AgentProgress) => void
3483
+ ): Promise<() => void>
3484
+ getResult(jobHandle: AgentJobHandle): Promise<AgentResult>
3485
+ cancel(jobHandle: AgentJobHandle): Promise<boolean>
3486
+ normalizeError(error: unknown): NormalizedAdapterError
3487
+ getArtifact?(jobHandle: AgentJobHandle, artifactId: string): Promise<ArtifactReference>
3488
+ getAuthContext?(): Promise<{ scopes: string[]; expiresAt?: string }>
3489
+ }
3490
+
3491
+ type ProviderProtocol =
3492
+ | 'a2a'
3493
+ | 'mcp'
3494
+ | 'provider-native'
3495
+ | 'http'
3496
+ | 'websocket'
3497
+ | 'sdk'
3498
+ | 'cli'
3499
+ | 'other'
3500
+
3501
+ type ProviderHealthStatus = 'healthy' | 'degraded' | 'unavailable'
3502
+
3503
+ type AgentAvailability = 'available' | 'unavailable' | 'disabled'
3504
+
3505
+ type AgentInvocationMode = 'sync' | 'async' | 'streaming'
3506
+
3507
+ type TaskLifecycleCapability =
3508
+ | 'status-polling'
3509
+ | 'status-subscription'
3510
+ | 'cancellation'
3511
+ | 'progress-streaming'
3512
+ | 'artifacts'
3513
+ | 'retry'
3514
+
3515
+ type AuthorizationStatus = 'authorized' | 'unauthorized' | 'unknown'
3516
+
3517
+ | 'discovered'
3518
+ | 'available'
3519
+ | 'unavailable'
3520
+ | 'invocable'
3521
+ | 'not-invocable'
3522
+ | 'authorized'
3523
+ | 'unauthorized'
3524
+
3525
+ interface RecoveryResult {
3526
+ requiresSelection: boolean
3527
+ unfinishedConversations?: Array<{
3528
+ conversationId: string
3529
+ objective: string
3530
+ currentWorkingPosition: string
3531
+ lastUpdated: string
3532
+ }>
3533
+ canonicalBrainIdentity?: string
3534
+ conversationId?: string
3535
+ currentObjective?: string
3536
+ currentWorkingPosition?: string
3537
+ establishedConclusions?: string[]
3538
+ relevantReasoningHistory?: Array<{ id: string; conclusion: string; epistemicStatus: string }>
3539
+ rejectedApproaches?: Array<{ approach: string; reason: string }>
3540
+ openQuestions?: string[]
3541
+ pendingDecisions?: string[]
3542
+ openLoops?: string[]
3543
+ applicableRules?: string[]
3544
+ relevantKnowledgeReferences?: Array<{ kind: string; identifier: string; relevance: number }>
3545
+ recommendedNextStep?: string
3546
+ provenanceAndCheckpointVersion?: {
3547
+ checkpointId?: string
3548
+ generatedAt: string
3549
+ }
3550
+ context?: ContextComposition
3551
+ }
3552
+
3553
+ interface DotMemSanitizer {
3554
+ sanitize: (value: unknown) => unknown
3555
+ redact: (value: unknown) => unknown
3556
+ }
3557
+
3558
+ type ClaimRef = { id: string; knowledge: unknown; epistemicType?: string }
3559
+
3560
+ interface LoadedStore {
3561
+ sourceId: string
3562
+ filePath: string
3563
+ state: KnowledgeState | null
3564
+ artifact: Awaited<ReturnType<typeof decodeMemArtifact>> | null
3565
+ error?: string
3566
+ }
3567
+
3568
+ interface DoctorFinding {
3569
+ type: 'duplicate-claim-id' | 'broken-revision-reference' | 'load-error'
3570
+ severity: 'error' | 'warning'
3571
+ message: string
3572
+ claimId?: string
3573
+ sourceId?: string
3574
+ filePath?: string
3575
+ sources?: Array<{ sourceId: string; filePath: string; acquiredAt?: string; scope?: string }>
3576
+ keptIndex?: number
3577
+ shadowedIndices?: number[]
3578
+ missingRefs?: string[]
3579
+ repairable?: boolean
3580
+ /** Content relation between duplicate records sharing the same id. */
3581
+ contentRelation?: 'byte-identical' | 'divergent-content'
3582
+ }
3583
+
3584
+ type PackageReport = {
3585
+ status: string
3586
+ representation: string
3587
+ packageVersion?: number
3588
+ memoryVersion?: number
3589
+ contentId?: string
3590
+ }
3591
+
3592
+ type DotMemContextToolResult = {
3593
+ [key: string]: unknown
3594
+ content: Array<{ type: 'text'; text: string }>
3595
+ structuredContent?: unknown
3596
+ isError?: boolean
3597
+ }
3598
+
3599
+ interface A2AAgentCard {
3600
+ name: string
3601
+ description?: string
3602
+ url: string
3603
+ provider?: { organization?: string; url?: string }
3604
+ version?: string
3605
+ capabilities?: {
3606
+ streaming?: boolean
3607
+ pushNotifications?: boolean
3608
+ stateTransitionHistory?: boolean
3609
+ extensions?: string[]
3610
+ }
3611
+ skills?: Array<{
3612
+ id?: string
3613
+ name: string
3614
+ description?: string
3615
+ tags?: string[]
3616
+ examples?: string[]
3617
+ inputModes?: string[]
3618
+ outputModes?: string[]
3619
+ }>
3620
+ security?: Array<{ scheme?: string; credentials?: Record<string, unknown> }>
3621
+ authenticatedExtensions?: string[]
3622
+ defaultInputModes?: string[]
3623
+ defaultOutputModes?: string[]
3624
+ }
3625
+
3626
+ interface A2ATask {
3627
+ id: string
3628
+ contextId?: string
3629
+ sessionId?: string
3630
+ status: { state: string; message?: unknown; timestamp?: string }
3631
+ artifacts?: Array<{
3632
+ artifactId: string
3633
+ name?: string
3634
+ description?: string
3635
+ parts?: Array<{ kind?: string; file?: { name?: string; mimeType?: string; bytes?: string } }>
3636
+ }>
3637
+ history?: unknown[]
3638
+ metadata?: Record<string, unknown>
3639
+ }
3640
+
3641
+ interface A2AError {
3642
+ code?: number
3643
+ message: string
3644
+ data?: unknown
3645
+ }
3646
+
3647
+ interface A2AJsonRpcResponse {
3648
+ jsonrpc: '2.0'
3649
+ id: string
3650
+ result?: unknown
3651
+ error?: A2AError
3652
+ }