@graphorin/core 0.6.0 → 0.7.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.
Files changed (112) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +14 -8
  3. package/dist/channels/channels.d.ts.map +1 -1
  4. package/dist/channels/index.d.ts +2 -2
  5. package/dist/channels/index.js +2 -2
  6. package/dist/channels/pause.d.ts +47 -2
  7. package/dist/channels/pause.d.ts.map +1 -1
  8. package/dist/channels/pause.js +62 -2
  9. package/dist/channels/pause.js.map +1 -1
  10. package/dist/contracts/checkpoint-store.d.ts +97 -1
  11. package/dist/contracts/checkpoint-store.d.ts.map +1 -1
  12. package/dist/contracts/checkpoint-store.js.map +1 -1
  13. package/dist/contracts/index.d.ts +5 -5
  14. package/dist/contracts/index.js +2 -1
  15. package/dist/contracts/memory-store.d.ts +59 -2
  16. package/dist/contracts/memory-store.d.ts.map +1 -1
  17. package/dist/contracts/provider.d.ts +20 -6
  18. package/dist/contracts/provider.d.ts.map +1 -1
  19. package/dist/contracts/session-store.d.ts +10 -2
  20. package/dist/contracts/session-store.d.ts.map +1 -1
  21. package/dist/contracts/tool.d.ts +75 -1
  22. package/dist/contracts/tool.d.ts.map +1 -1
  23. package/dist/contracts/tool.js +57 -0
  24. package/dist/contracts/tool.js.map +1 -0
  25. package/dist/contracts/tracer.d.ts +53 -5
  26. package/dist/contracts/tracer.d.ts.map +1 -1
  27. package/dist/contracts/tracer.js.map +1 -1
  28. package/dist/index.d.ts +14 -9
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +11 -7
  31. package/dist/index.js.map +1 -1
  32. package/dist/package.js +6 -0
  33. package/dist/package.js.map +1 -0
  34. package/dist/types/agent-event-wire.d.ts +74 -0
  35. package/dist/types/agent-event-wire.d.ts.map +1 -0
  36. package/dist/types/agent-event-wire.js +130 -0
  37. package/dist/types/agent-event-wire.js.map +1 -0
  38. package/dist/types/agent-event.d.ts +48 -6
  39. package/dist/types/agent-event.d.ts.map +1 -1
  40. package/dist/types/index.d.ts +3 -2
  41. package/dist/types/index.js +2 -1
  42. package/dist/types/memory.d.ts +11 -0
  43. package/dist/types/memory.d.ts.map +1 -1
  44. package/dist/types/run.d.ts +86 -4
  45. package/dist/types/run.d.ts.map +1 -1
  46. package/dist/types/run.js.map +1 -1
  47. package/dist/types/tool.d.ts +10 -0
  48. package/dist/types/tool.d.ts.map +1 -1
  49. package/dist/types/usage.d.ts +11 -1
  50. package/dist/types/usage.d.ts.map +1 -1
  51. package/dist/types/usage.js.map +1 -1
  52. package/dist/utils/binary-json.d.ts +165 -0
  53. package/dist/utils/binary-json.d.ts.map +1 -0
  54. package/dist/utils/binary-json.js +240 -0
  55. package/dist/utils/binary-json.js.map +1 -0
  56. package/dist/utils/index.d.ts +2 -1
  57. package/dist/utils/index.js +2 -1
  58. package/dist/utils/validation.d.ts +10 -1
  59. package/dist/utils/validation.d.ts.map +1 -1
  60. package/dist/utils/validation.js +1 -1
  61. package/dist/utils/validation.js.map +1 -1
  62. package/package.json +9 -7
  63. package/src/channels/channels.ts +206 -0
  64. package/src/channels/directive.ts +41 -0
  65. package/src/channels/dispatch.ts +37 -0
  66. package/src/channels/durable.ts +151 -0
  67. package/src/channels/index.ts +62 -0
  68. package/src/channels/pause.ts +216 -0
  69. package/src/contracts/auth-token-store.ts +42 -0
  70. package/src/contracts/checkpoint-store.ts +256 -0
  71. package/src/contracts/embedder.ts +42 -0
  72. package/src/contracts/eval-scorer.ts +44 -0
  73. package/src/contracts/index.ts +112 -0
  74. package/src/contracts/local-provider-trust.ts +33 -0
  75. package/src/contracts/logger.ts +61 -0
  76. package/src/contracts/memory-store.ts +187 -0
  77. package/src/contracts/oauth-server-store.ts +78 -0
  78. package/src/contracts/preferred-model.ts +56 -0
  79. package/src/contracts/provider.ts +316 -0
  80. package/src/contracts/reasoning-retention.ts +52 -0
  81. package/src/contracts/redaction-validator.ts +56 -0
  82. package/src/contracts/sandbox.ts +70 -0
  83. package/src/contracts/secret-ref.ts +22 -0
  84. package/src/contracts/secret-value.ts +117 -0
  85. package/src/contracts/secrets-store.ts +90 -0
  86. package/src/contracts/session-store.ts +163 -0
  87. package/src/contracts/token-counter.ts +23 -0
  88. package/src/contracts/tool.ts +397 -0
  89. package/src/contracts/tracer.ts +219 -0
  90. package/src/contracts/trigger-store.ts +40 -0
  91. package/src/index.ts +23 -0
  92. package/src/types/agent-event-wire.ts +193 -0
  93. package/src/types/agent-event.ts +579 -0
  94. package/src/types/handoff.ts +111 -0
  95. package/src/types/index.ts +148 -0
  96. package/src/types/memory.ts +427 -0
  97. package/src/types/message.ts +174 -0
  98. package/src/types/run.ts +312 -0
  99. package/src/types/sensitivity.ts +35 -0
  100. package/src/types/session-scope.ts +18 -0
  101. package/src/types/stop-condition.ts +108 -0
  102. package/src/types/tool-call.ts +24 -0
  103. package/src/types/tool.ts +324 -0
  104. package/src/types/usage.ts +120 -0
  105. package/src/types/workflow-event.ts +132 -0
  106. package/src/utils/assert-never.ts +24 -0
  107. package/src/utils/async-context.ts +55 -0
  108. package/src/utils/binary-json.ts +425 -0
  109. package/src/utils/hash.ts +122 -0
  110. package/src/utils/index.ts +57 -0
  111. package/src/utils/streams.ts +233 -0
  112. package/src/utils/validation.ts +82 -0
@@ -0,0 +1,148 @@
1
+ /**
2
+ * Plain TypeScript types for the Graphorin framework.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+
7
+ export type {
8
+ AgentCancellingEvent,
9
+ AgentEndEvent,
10
+ AgentErrorEvent,
11
+ AgentEvaluatorConvergedEvent,
12
+ AgentEvaluatorIterationEvent,
13
+ AgentEvent,
14
+ AgentFanOutMergedEvent,
15
+ AgentFanOutSpawnedEvent,
16
+ AgentFollowUpQueuedEvent,
17
+ AgentLateralLeakDetectedEvent,
18
+ AgentModelFellbackEvent,
19
+ AgentProgressReadEvent,
20
+ AgentProgressWrittenEvent,
21
+ AgentResult,
22
+ AgentStartEvent,
23
+ AgentSteeredEvent,
24
+ ContextCompactedEvent,
25
+ FanOutChildMetadata,
26
+ GuardrailTrippedEvent,
27
+ HandoffEvent,
28
+ LateralLeakVector,
29
+ ProgressArtifactRef,
30
+ ReasoningDeltaEvent,
31
+ StepEndEvent,
32
+ StepStartEvent,
33
+ TextCompleteEvent,
34
+ TextDeltaEvent,
35
+ ToolApprovalDeniedEvent,
36
+ ToolApprovalGrantedEvent,
37
+ ToolApprovalRequestedEvent,
38
+ ToolCallDeltaEvent,
39
+ ToolCallEndEvent,
40
+ ToolCallStartEvent,
41
+ ToolExecuteEndEvent,
42
+ ToolExecuteErrorEvent,
43
+ ToolExecutePartialEvent,
44
+ ToolExecuteProgressEvent,
45
+ ToolExecuteStartEvent,
46
+ VerifierResultEvent,
47
+ } from './agent-event.js';
48
+ export type {
49
+ WireAgentEndEvent,
50
+ WireAgentEvent,
51
+ WireContentChunk,
52
+ WireFileGeneratedEvent,
53
+ WireToolExecutePartialEvent,
54
+ } from './agent-event-wire.js';
55
+ export { fromWireAgentEvent, toWireAgentEvent } from './agent-event-wire.js';
56
+ export type {
57
+ Handoff,
58
+ HandoffFilter,
59
+ HandoffInputFilterDescriptor,
60
+ HandoffRecord,
61
+ HandoffSecretsInheritance,
62
+ } from './handoff.js';
63
+ export type {
64
+ Block,
65
+ EntityRole,
66
+ Episode,
67
+ Fact,
68
+ GraphEntity,
69
+ Insight,
70
+ MemoryHit,
71
+ MemoryKind,
72
+ MemoryMetadata,
73
+ MemoryOwner,
74
+ MemoryProvenance,
75
+ MemoryRecord,
76
+ MemorySearchOptions,
77
+ MemoryStatus,
78
+ Rule,
79
+ } from './memory.js';
80
+ export type {
81
+ AssistantMessage,
82
+ AudioContent,
83
+ FileContent,
84
+ ImageContent,
85
+ Message,
86
+ MessageContent,
87
+ MessageRole,
88
+ ReasoningContent,
89
+ ReasoningContentMeta,
90
+ SystemMessage,
91
+ TextContent,
92
+ ToolMessage,
93
+ UserMessage,
94
+ } from './message.js';
95
+ export {
96
+ flattenUsageByModel,
97
+ type ReadonlyRunState,
98
+ type RunContext,
99
+ type RunError,
100
+ type RunState,
101
+ type RunStateUsageByModel,
102
+ type RunStatus,
103
+ type RunStep,
104
+ type RunStepProviderResponse,
105
+ type RunTaintSummary,
106
+ type TodoItem,
107
+ } from './run.js';
108
+ export type { Sensitivity } from './sensitivity.js';
109
+ export { acceptsSensitivity, SENSITIVITY_ORDER } from './sensitivity.js';
110
+ export type { SessionScope } from './session-scope.js';
111
+ export type { StopCondition } from './stop-condition.js';
112
+ export { and, hasToolCall, isStepCount, isTerminal, not, or } from './stop-condition.js';
113
+ export type {
114
+ CompletedToolCall,
115
+ ContentChunk,
116
+ InboundSanitizationPolicy,
117
+ MemoryGuardTier,
118
+ RecoveryHint,
119
+ ResultHandle,
120
+ SandboxPolicy,
121
+ SideEffectClass,
122
+ ToolApproval,
123
+ ToolCall,
124
+ ToolError,
125
+ ToolErrorKind,
126
+ ToolOutcome,
127
+ ToolResult,
128
+ ToolSource,
129
+ ToolTrustClass,
130
+ TruncationStrategy,
131
+ } from './tool.js';
132
+ export type { Cost, ModelUsage, Usage, UsageAccumulator, UsageSnapshot } from './usage.js';
133
+ export { zeroUsage } from './usage.js';
134
+ export type {
135
+ WorkflowChannelUpdateEvent,
136
+ WorkflowCheckpointWrittenEvent,
137
+ WorkflowCustomEvent,
138
+ WorkflowEndEvent,
139
+ WorkflowErrorEvent,
140
+ WorkflowEvent,
141
+ WorkflowResumedEvent,
142
+ WorkflowStartEvent,
143
+ WorkflowStepEndEvent,
144
+ WorkflowStepStartEvent,
145
+ WorkflowSuspendedEvent,
146
+ WorkflowTaskEndEvent,
147
+ WorkflowTaskStartEvent,
148
+ } from './workflow-event.js';
@@ -0,0 +1,427 @@
1
+ import type { Sensitivity } from './sensitivity.js';
2
+
3
+ /**
4
+ * Kinds of memory record in the Graphorin model. The first six are the
5
+ * storage tiers the {@link MemoryStore} contract exposes as 1:1
6
+ * sub-namespaces; `insight` is the derived, reflection-synthesized
7
+ * record kind (P1-1) - it has no base-tier namespace and is persisted
8
+ * through the optional insight surface adapters expose. Used as the
9
+ * discriminator for span types and the `MemoryRecord` union.
10
+ *
11
+ * @stable
12
+ */
13
+ export type MemoryKind =
14
+ | 'working'
15
+ | 'session'
16
+ | 'episodic'
17
+ | 'semantic'
18
+ | 'procedural'
19
+ | 'shared'
20
+ | 'insight';
21
+
22
+ /**
23
+ * Where a memory came from - the trust-provenance tag carried by every
24
+ * fact / episode / induced procedure. `user` (the human said it) and
25
+ * `tool` (a tool the agent invoked returned it) are first-party;
26
+ * `extraction` (consolidator distilled it from a transcript),
27
+ * `reflection` (a synthesis pass inferred it), and `induction` (an
28
+ * AWM-style pass distilled a reusable workflow from a successful agent
29
+ * trajectory, P2-2) are *derived* and therefore land quarantined by
30
+ * default; `imported` is bulk-loaded from an external store. Used by
31
+ * P1-4 to gate action-driving recall against memory-poisoning (MINJA /
32
+ * MemoryGraft) - induced procedures drive *actions*, so the quarantine
33
+ * gate matters most for them.
34
+ *
35
+ * @stable
36
+ */
37
+ export type MemoryProvenance =
38
+ | 'user'
39
+ | 'tool'
40
+ | 'extraction'
41
+ | 'reflection'
42
+ | 'induction'
43
+ | 'imported';
44
+
45
+ /**
46
+ * Retrieval-trust state of a memory. `active` rows are eligible for
47
+ * default recall; `quarantined` rows are persisted and auditable but
48
+ * excluded from action-driving recall until explicitly validated (P1-4).
49
+ * Quarantine is a *retrieval gate*, never a delete.
50
+ *
51
+ * @stable
52
+ */
53
+ export type MemoryStatus = 'active' | 'quarantined';
54
+
55
+ /**
56
+ * Principal a memory belongs to (D3) - the *who-owns-this* dimension,
57
+ * orthogonal to {@link MemoryProvenance} (*where-it-came-from*):
58
+ * `user` for user-stated content, `agent` for the agent's own
59
+ * inferences (consolidator extraction / reflection / induction stamp
60
+ * this), `shared` for records deliberately published to a multi-agent
61
+ * shared tier. Absent (rows written before the feature, or writers
62
+ * that do not care) is treated as `user` at filter time; default
63
+ * reads apply **no owner filter**, so behaviour is unchanged until a
64
+ * caller opts into a retrieval-time scope filter.
65
+ *
66
+ * @stable
67
+ */
68
+ export type MemoryOwner = 'user' | 'agent' | 'shared';
69
+
70
+ /**
71
+ * Snapshot of memory-tier counters surfaced to the model via the
72
+ * memory-aware system prompt. Implementations live in `@graphorin/memory`;
73
+ * the type sits here so the agent runtime can include it in its
74
+ * `RunContext` without a memory dependency.
75
+ *
76
+ * @stable
77
+ */
78
+ export interface MemoryMetadata {
79
+ /** Total number of facts in the user's semantic memory. */
80
+ readonly factCount: number;
81
+ /** Number of episodes stored for the user. */
82
+ readonly episodeCount: number;
83
+ /** Number of past messages indexed for retrieval. */
84
+ readonly messageCount: number;
85
+ /** Active rules count (after context filtering). */
86
+ readonly activeRuleCount: number;
87
+ /** Number of declared working blocks. */
88
+ readonly workingBlockCount: number;
89
+ /** Last consolidator run, ISO-8601, if any. */
90
+ readonly lastConsolidatedAt?: string;
91
+ /** Optional, free-form metadata tags surfaced to the model. */
92
+ readonly tags?: ReadonlyArray<string>;
93
+ }
94
+
95
+ /**
96
+ * Marker shared by every memory record. Concrete records (`Block`,
97
+ * `Fact`, `Episode`, `Rule`, message rows) all extend it.
98
+ *
99
+ * @stable
100
+ */
101
+ export interface MemoryRecord {
102
+ readonly id: string;
103
+ readonly kind: MemoryKind;
104
+ readonly userId: string;
105
+ readonly agentId?: string;
106
+ readonly sessionId?: string;
107
+ readonly sensitivity: Sensitivity;
108
+ readonly createdAt: string;
109
+ readonly updatedAt?: string;
110
+ /**
111
+ * Soft-delete tombstone. Append-only stores set this instead of removing
112
+ * rows, so prior history is preserved per principle 8.
113
+ */
114
+ readonly deletedAt?: string;
115
+ readonly tags?: ReadonlyArray<string>;
116
+ }
117
+
118
+ /**
119
+ * Working-memory block - a labeled, char-bounded slot rendered into the
120
+ * system prompt every turn.
121
+ *
122
+ * @stable
123
+ */
124
+ export interface Block extends MemoryRecord {
125
+ readonly kind: 'working';
126
+ readonly label: string;
127
+ readonly description?: string;
128
+ readonly value: string;
129
+ readonly charLimit: number;
130
+ readonly readOnly?: boolean;
131
+ }
132
+
133
+ /**
134
+ * Single semantic-memory fact: an atomic statement about the user / world.
135
+ *
136
+ * @stable
137
+ */
138
+ export interface Fact extends MemoryRecord {
139
+ readonly kind: 'semantic';
140
+ readonly text: string;
141
+ /**
142
+ * Structured `(subject, predicate, object)` triple for the in-SQLite
143
+ * relation graph (P2-1). The consolidator's extraction prompt emits
144
+ * these; first-party `remember({ text })` writes usually omit them.
145
+ * `subject`/`object` are the graph *entities* (resolved to canonical
146
+ * ids in `fact_entities`); `predicate` is the relation label and is
147
+ * not itself an entity. Absent on rows written before the feature, and
148
+ * on plain free-text facts - they are a soft enrichment that powers
149
+ * one-hop expansion ({@link MemorySearchOptions} has no field; the
150
+ * memory tier's search opts in), never a recall gate.
151
+ */
152
+ readonly subject?: string;
153
+ /** Relation label of the {@link Fact.subject}→{@link Fact.object} triple (P2-1). */
154
+ readonly predicate?: string;
155
+ /** Object entity of the s/p/o triple (P2-1). See {@link Fact.subject}. */
156
+ readonly object?: string;
157
+ readonly confidence?: number;
158
+ /**
159
+ * Optional salience hint in `[0, 1]` for multi-signal forgetting
160
+ * (X-1). A *soft* signal - higher importance slows a fact's decay and
161
+ * delays capacity-bounded eviction, but never gates recall and never
162
+ * forces retention. Absent on rows written before the feature
163
+ * (treated as neutral, `0.5`).
164
+ */
165
+ readonly importance?: number;
166
+ /** Bi-temporal: when the fact became true, ISO-8601. */
167
+ readonly validFrom?: string;
168
+ /** Bi-temporal: when the fact stopped being true, ISO-8601. */
169
+ readonly validTo?: string;
170
+ /** ID of the fact this one supersedes, if any. */
171
+ readonly supersedes?: string;
172
+ /** ID of the fact that supersedes this one, if any. */
173
+ readonly supersededBy?: string;
174
+ /**
175
+ * Trust-provenance tag (P1-4). Absent on rows written before the
176
+ * feature; treated as first-party (`active`) when missing.
177
+ */
178
+ readonly provenance?: MemoryProvenance;
179
+ /**
180
+ * Retrieval-trust state (P1-4). Defaults to `active`; derived /
181
+ * injection-flagged writes land `quarantined` and are excluded from
182
+ * default recall.
183
+ */
184
+ readonly status?: MemoryStatus;
185
+ /**
186
+ * Principal dimension (D3). `'agent'` on consolidator-synthesized
187
+ * facts; absent ⇒ treated as `'user'` at filter time. Never gates
188
+ * default recall - only an explicit owner search filter reads it.
189
+ */
190
+ readonly owner?: MemoryOwner;
191
+ }
192
+
193
+ /**
194
+ * Episode - a summarized stretch of past activity.
195
+ *
196
+ * @stable
197
+ */
198
+ export interface Episode extends MemoryRecord {
199
+ readonly kind: 'episodic';
200
+ readonly summary: string;
201
+ /** ISO-8601 of the earliest event in the episode. */
202
+ readonly startedAt: string;
203
+ /** ISO-8601 of the latest event in the episode. */
204
+ readonly endedAt: string;
205
+ /** Optional importance score in `[0, 1]`. */
206
+ readonly importance?: number;
207
+ /** Trust-provenance tag (P1-4). See {@link MemoryProvenance}. */
208
+ readonly provenance?: MemoryProvenance;
209
+ /** Retrieval-trust state (P1-4). See {@link MemoryStatus}. */
210
+ readonly status?: MemoryStatus;
211
+ /** Principal dimension (D3). See {@link MemoryOwner}. */
212
+ readonly owner?: MemoryOwner;
213
+ }
214
+
215
+ /**
216
+ * Procedural rule - a standing order activated when its `condition` matches.
217
+ *
218
+ * @stable
219
+ */
220
+ export interface Rule extends MemoryRecord {
221
+ readonly kind: 'procedural';
222
+ readonly text: string;
223
+ readonly condition?: string;
224
+ readonly priority: number;
225
+ /**
226
+ * Ordered, value-abstracted step sequence of an *induced* workflow
227
+ * (P2-2) - e.g. `['search for {product}', 'add {quantity} to cart',
228
+ * 'check out']`. Present only on procedures distilled from successful
229
+ * agent trajectories; author-defined rules omit it.
230
+ */
231
+ readonly steps?: ReadonlyArray<string>;
232
+ /**
233
+ * Names of the variables abstracted from the trajectory's concrete
234
+ * values (P2-2) - the `{product}` / `{quantity}` placeholders that
235
+ * appear in {@link Rule.steps}. Lets a reused procedure be re-bound to
236
+ * fresh arguments instead of replaying one run's literals.
237
+ */
238
+ readonly variables?: ReadonlyArray<string>;
239
+ /**
240
+ * Voyager-style verifiable success criteria stored alongside an induced
241
+ * procedure (P2-2) so a reuse can *self-verify* its outcome instead of
242
+ * trusting the procedure blindly. Author-defined rules omit it.
243
+ */
244
+ readonly successCriteria?: ReadonlyArray<string>;
245
+ /**
246
+ * Trust-provenance tag (P1-4 / P2-2). Induced procedures are
247
+ * `'induction'`; author-defined rules omit it (treated first-party).
248
+ * See {@link MemoryProvenance}.
249
+ */
250
+ readonly provenance?: MemoryProvenance;
251
+ /**
252
+ * Retrieval-trust state (P1-4 / P2-2). Induced procedures land
253
+ * `'quarantined'` and are excluded from activation (they must not drive
254
+ * actions) until validated; author-defined rules omit it (treated
255
+ * `'active'`). See {@link MemoryStatus}.
256
+ */
257
+ readonly status?: MemoryStatus;
258
+ /**
259
+ * Demonstrated-success counter (MCON-2 part 4). Incremented by
260
+ * `ProceduralMemory.recordOutcome(...)` on each verified successful
261
+ * reuse; drives promotion-by-demonstrated-success for quarantined
262
+ * induced procedures once the configured threshold is reached.
263
+ * Absent ⇒ never counted (adapters without the column).
264
+ */
265
+ readonly successCount?: number;
266
+ /** Principal dimension (D3). `'agent'` on induced procedures. See {@link MemoryOwner}. */
267
+ readonly owner?: MemoryOwner;
268
+ }
269
+
270
+ /**
271
+ * Insight - a higher-order observation the consolidator's reflection
272
+ * pass (P1-1) synthesizes over recent memories ("the user has cancelled
273
+ * three evening plans this month - they may be overcommitted"). No
274
+ * single turn states it; it is *inferred*, so it is always
275
+ * `provenance: 'reflection'` and lands `status: 'quarantined'` (P1-4),
276
+ * excluded from action-driving recall until validated.
277
+ *
278
+ * Every insight carries **mandatory citations** (`cites`) - the ids of
279
+ * the supporting memories it was synthesized from - so a reader can
280
+ * trace it back to evidence; this is the "trustworthy reflection"
281
+ * mitigation against confirmation-bias loops. Insights are managed with
282
+ * an ExpeL-style salience counter (new insights start at `2`, pruned at
283
+ * `≤ 0`) and are retrieval-ranked **below** the primary facts they cite.
284
+ *
285
+ * Core defines only the record shape; the storage surface for insights
286
+ * is NOT part of the baseline {@link MemoryStore} contract - it lives in
287
+ * the optional `InsightMemoryStoreExt` exported from `@graphorin/memory`
288
+ * (W-048). Adapters without it simply have no insight tier.
289
+ *
290
+ * @stable
291
+ */
292
+ export interface Insight extends MemoryRecord {
293
+ readonly kind: 'insight';
294
+ /** The synthesized higher-order observation. */
295
+ readonly text: string;
296
+ /**
297
+ * IDs of the supporting memories (facts / episodes) this insight was
298
+ * synthesized from. Always ≥ 1 - citations are mandatory; an insight
299
+ * with no traceable evidence is never persisted.
300
+ */
301
+ readonly cites: ReadonlyArray<string>;
302
+ /**
303
+ * ExpeL-style salience counter. New insights start at `2`; a
304
+ * maintenance pass up-/down-votes on subsequent corroboration /
305
+ * contradiction and prunes (soft-deletes) insights at `≤ 0`.
306
+ */
307
+ readonly salience: number;
308
+ /**
309
+ * Trust-provenance tag (P1-4). Reflection-synthesized insights are
310
+ * `'reflection'`. See {@link MemoryProvenance}.
311
+ */
312
+ readonly provenance?: MemoryProvenance;
313
+ /**
314
+ * Retrieval-trust state (P1-4). Insights land `'quarantined'`. See
315
+ * {@link MemoryStatus}.
316
+ */
317
+ readonly status?: MemoryStatus;
318
+ /** Principal dimension (D3). Reflection-synthesized insights are `'agent'`. */
319
+ readonly owner?: MemoryOwner;
320
+ }
321
+
322
+ /**
323
+ * Role a {@link GraphEntity} plays in a {@link Fact}'s s/p/o triple
324
+ * (P2-1) - the `subject` or the `object`. The `predicate` is a relation
325
+ * label, not an entity, so it has no role here.
326
+ *
327
+ * @stable
328
+ */
329
+ export type EntityRole = 'subject' | 'object';
330
+
331
+ /**
332
+ * Canonical entity in the lightweight in-SQLite relation graph (P2-1).
333
+ * The entity resolver (`@graphorin/memory`) deduplicates the raw
334
+ * `subject`/`object` strings on facts into canonical entities - merging
335
+ * aliases ("Anna", "Anna S.", "my sister") via lexical + embedding
336
+ * similarity (with optional LLM adjudication) - so multi-hop recall can
337
+ * traverse relationships instead of fragmenting them.
338
+ *
339
+ * Merges are **append-only and reversible**: a merged entity is never
340
+ * deleted - its {@link GraphEntity.mergedInto} points at the surviving
341
+ * canonical entity, every merge / unmerge is recorded in an audit
342
+ * ledger, and `mergedInto` is single-level (it always points directly at
343
+ * a root), so `mergedInto ?? id` is the canonical id.
344
+ *
345
+ * Core defines only the record shape; the storage surface for the graph
346
+ * (upsert / link / merge / one-hop expansion) is NOT part of the
347
+ * baseline {@link MemoryStore} contract - it lives in the optional
348
+ * `GraphMemoryStoreExt` exported from `@graphorin/memory` (W-048).
349
+ * Adapters without it simply have no relation graph.
350
+ *
351
+ * @stable
352
+ */
353
+ export interface GraphEntity {
354
+ readonly id: string;
355
+ readonly userId: string;
356
+ /** Display name as first observed (the surface form that minted it). */
357
+ readonly name: string;
358
+ /** Case/space-folded key used for lexical dedup + the canonical unique index. */
359
+ readonly normalizedName: string;
360
+ /**
361
+ * Canonical pointer. `undefined` ⇒ this entity is itself a root.
362
+ * Otherwise it is the id of the surviving entity this one was merged
363
+ * into; single-level by construction, so `mergedInto ?? id` resolves
364
+ * the canonical id without a recursive walk.
365
+ */
366
+ readonly mergedInto?: string;
367
+ readonly createdAt: string;
368
+ readonly updatedAt?: string;
369
+ }
370
+
371
+ /**
372
+ * Search options shared across memory tiers.
373
+ *
374
+ * @stable
375
+ */
376
+ export interface MemorySearchOptions {
377
+ readonly query: string;
378
+ readonly topK?: number;
379
+ readonly tags?: ReadonlyArray<string>;
380
+ readonly dateRange?: { readonly from?: string; readonly to?: string };
381
+ readonly includeArchived?: boolean;
382
+ /**
383
+ * Include quarantined memories in the result set (P1-4). Defaults to
384
+ * `false`: action-driving recall never returns quarantined rows. Set
385
+ * `true` only for the validation / inspector path - never for
386
+ * auto-recall fed back into the model.
387
+ */
388
+ readonly includeQuarantined?: boolean;
389
+ readonly signal?: AbortSignal;
390
+ /**
391
+ * Point-in-time ("as of") read. When set, only records whose
392
+ * validity interval contains this instant are returned. For facts:
393
+ * `(valid_from IS NULL OR valid_from <= asOf) AND (valid_to IS NULL OR valid_to > asOf)`;
394
+ * for episodes: `started_at <= asOf`. ISO-8601. Absent ⇒ fact reads
395
+ * evaluate validity at NOW (see {@link includeSuperseded}).
396
+ */
397
+ readonly asOf?: string;
398
+ /**
399
+ * Include superseded / validity-expired facts in the result set
400
+ * (memory-retrieval-01). Defaults to `false`: a default read behaves
401
+ * as `asOf = now`, so a fact whose `validTo` was closed (e.g. by
402
+ * `supersede`) never surfaces as current - exactly what the
403
+ * `fact_supersede` tool promises. Set `true` only for inspector /
404
+ * audit paths that need the full history. Ignored when an explicit
405
+ * {@link asOf} is supplied.
406
+ */
407
+ readonly includeSuperseded?: boolean;
408
+ /**
409
+ * Retrieval-time principal filter (D3). When set, only records whose
410
+ * owner is in the requested set match; rows written before the
411
+ * feature (owner absent) are treated as `'user'`. Absent ⇒ no owner
412
+ * filter - behaviour is unchanged.
413
+ */
414
+ readonly owner?: MemoryOwner | ReadonlyArray<MemoryOwner>;
415
+ }
416
+
417
+ /**
418
+ * A single retrieval hit with similarity / relevance metadata.
419
+ *
420
+ * @stable
421
+ */
422
+ export interface MemoryHit<TRecord extends MemoryRecord = MemoryRecord> {
423
+ readonly record: TRecord;
424
+ readonly score: number;
425
+ /** Optional source signals contributing to `score` (BM25, vec, RRF, …). */
426
+ readonly signals?: Readonly<Record<string, number>>;
427
+ }